AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi [gelöst] Problem mit RGB und ScanLine
Thema durchsuchen
Ansicht
Themen-Optionen

[gelöst] Problem mit RGB und ScanLine

Ein Thema von Thanatos81 · begonnen am 26. Feb 2007 · letzter Beitrag vom 26. Feb 2007
Antwort Antwort
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
Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#2

Re: Problem mit RGB und ScanLine

  Alt 26. Feb 2007, 10:10
Zwischenfrage:

Was ist denn RGB2TColor und TColor2RGB ?

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


Was möchtest du denn genau machen ?
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat
matashen

Registriert seit: 29. Jan 2007
Ort: daheim
463 Beiträge
 
Delphi XE2 Enterprise
 
#3

Re: Problem mit RGB und ScanLine

  Alt 26. Feb 2007, 10:14
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?
Matthias
  Mit Zitat antworten Zitat
Thanatos81
(Gast)

n/a Beiträge
 
#4

Re: Problem mit RGB und ScanLine

  Alt 26. Feb 2007, 10:19
@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
  Mit Zitat antworten Zitat
Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#5

Re: [gelöst] Problem mit RGB und ScanLine

  Alt 26. Feb 2007, 10:27
Aha, RGB2TColor gibts als Windowsfunction Namens RGB();.
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat
Thanatos81
(Gast)

n/a Beiträge
 
#6

Re: [gelöst] Problem mit RGB und ScanLine

  Alt 26. Feb 2007, 10:30
Jupp, hab ich auch schon gesehen; wenn erstmal alles auf ScanLine umgestellt ist, werden TColor2RGB und RGB2TColor auch rausgeschmissen. Also in ca. 15 Minuten^^
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:22 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