Einzelnen Beitrag anzeigen

Thanatos81
(Gast)

n/a Beiträge
 
#1

[gelöst] Problem mit RGB und ScanLine

  Alt 26. Feb 2007, 10:04
So, erst mal etwas Code vorweg und dann die Erklärung meines Problems anhand des Codes.

Einlesen des Bildes und Zerlegung in RGB-Werte
Delphi-Quellcode:
  
  imgOri.Picture.Bitmap.Assign(bmp);

  imgRed.Picture.Bitmap.Height := bmp.Height;
  imgRed.Picture.Bitmap.Width := bmp.Width;

  // imgBlue.Picture.Bitmap.Height := bmp.Height;
  // imgBlue.Picture.Bitmap.Width := bmp.Width;

  // imgGreen.Picture.Bitmap.Height := bmp.Height;
  // imgGreen.Picture.Bitmap.Width := bmp.Width;

    //ToDo: Für Release komplett betrachten
  for y := 0 to 170 do //bmp.Height - 1 do
  begin
    line := bmp.ScanLine[y];
    for x := 0 to bmp.Width do
    begin
      if (line^.rgbtBlue < 200) and (line^.rgbtGreen < 200) then
      begin
        temp := line^.rgbtRed;
        imgRed.Picture.Bitmap.Canvas.Pixels[x, y] := RGB2TColor(temp, 0, 0);

        // temp := line^.rgbtGreen;
        // imgGreen.Picture.Bitmap.Canvas.Pixels[x, y] := RGB2TColor(0, temp, 0);

        // temp := line^.rgbtBlue;
        // imgBlue.Picture.Bitmap.Canvas.Pixels[x, y] := RGB2TColor(0, 0, temp);
      end;
      inc(line);
    end;
  end;
  deleteBrightPixel(imgRed.Picture.Bitmap);
  // deleteBrightPixel(imgGreen.Picture.Bitmap);
  // deleteBrightPixel(imgBlue.Picture.Bitmap);
Prozedur deleteBrightPixel
Delphi-Quellcode:
procedure deleteBrightPixel(bmp: TBitmap);
var
  tut: Cardinal;
  count: Cardinal;
  x, y: Integer;
  hue, lumi, sat: Word;
  c: TColor;
  r, g, b: Byte;
  line: PRGBTriple;
begin
  tut := 0;
  count := 0;

  for y := 0 to bmp.Height - 1 do
  begin
    line := bmp.ScanLine[y];
    for x := 0 to bmp.Width - 1 do
    begin
      c := bmp.Canvas.Pixels[x, y];

      if c <> clWhite then
      begin
        TColor2RGB(c, r, g, b);
        if (x = 139) and (y = 112) then
          showMessage(format('%d, %d, %d', [line^.rgbtRed, line^.rgbtGreen
            , line^.rgbtBlue]));

        ColorRGBToHLS(ColorToRGB(c), hue, lumi, sat);

        inc(tut, lumi);
        inc(count);
      end;
      inc(line);
    end;
  end;

  tut := tut div count;

  for y := 0 to bmp.Height - 1 do
  begin
    for x := 0 to bmp.Width - 1 do
    begin
      c := bmp.Canvas.Pixels[x, y];
      if c <> clWhite then
      begin
        TColor2RGB(c, r, g, b);
        ColorRGBToHLS(ColorToRGB(c), hue, lumi, sat);

        if (lumi > tut) then
          bmp.Canvas.Pixels[x, y] := clWhite;
      end;
    end;
  end;
end;
So, das ganze funktioniert soweit auch so, wie ich es mir vorstelle. Nur wollte ich jetzt auch das Löschen heller Pixel mittels ScanLine beschleunigen. Komischerweise gibt mir ScanLine aber bei Aufruf der Prozedur mit imgRed.Picture.Bitmap bei der if-Bedingung nur einen Wert für Grün an, obwohl das Bild nur noch aus Weiß/Rot besteht, und weiß wird ja mittels "if c <> clWhite" abgewiesen. Die gewählten X/Y-Koordinaten beinhalten einen dunkelroten Punkt.

Und ich frage mich jetzt, ob ich was Grundlegendes mit ScanLine verkehrt mache, oder warum angeblich nur ein Grünanteil vorhanden ist.
  Mit Zitat antworten Zitat