Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi [gelöst] Problem mit RGB und ScanLine (https://www.delphipraxis.net/87270-%5Bgeloest%5D-problem-mit-rgb-und-scanline.html)

Thanatos81 26. Feb 2007 10:04


[gelöst] Problem mit RGB und ScanLine
 
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.

turboPASCAL 26. Feb 2007 10:10

Re: Problem mit RGB und ScanLine
 
Zwischenfrage: :mrgreen:

Was ist denn RGB2TColor und TColor2RGB ?

Ausserdem, du arbeitest mit Scanline und Canvas.Pixel[y,x] ? :gruebel:


Was möchtest du denn genau machen ?

matashen 26. Feb 2007 10:14

Re: Problem mit RGB und ScanLine
 
Hallo erstmal,

ich sehe das in deinem Code nirgends die Farbtiefe ermittelt wird oder auf eine gut zu verarbeitende umgeschaltet wird.

Du solltest erstmal das Bitmap auf 24 Bit Farbtiefe umstellen um sicherzustellen das ein Farbwert genau 8Bit als 1 Byte benötigt.

Welche Farbtiefe hat dein testbild?

Thanatos81 26. Feb 2007 10:19

Re: Problem mit RGB und ScanLine
 
@turboPASCAL
Das ist das hier: http://www.delphipraxis.net/internal...=600828#600828 ;-) Die Variante mit himitsus Ergänzung.

@matashen
Das Bild stammt von einer FireWire-Kamera mittels DSPack. Und das Eingangsformat hab ich eigentlich auf 24 Bit stehen. Aber nachdem ich jetzt an den Anfang beider Prozeduren "bmp.PixelFormat := pf24Bit;" eingefügt habe, funktioniert es. Danke! Anscheinend wurde das durch die Assigns unterschlagen :wall:

turboPASCAL 26. Feb 2007 10:27

Re: [gelöst] Problem mit RGB und ScanLine
 
Aha, RGB2TColor gibts als Windowsfunction Namens RGB();. ;)

Thanatos81 26. Feb 2007 10:30

Re: [gelöst] Problem mit RGB und ScanLine
 
Jupp, hab ich auch schon gesehen; wenn erstmal alles auf ScanLine umgestellt ist, werden TColor2RGB und RGB2TColor auch rausgeschmissen. Also in ca. 15 Minuten^^


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:15 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz