![]() |
Bild: Umwandlung in Blaustufen (nicht Graustufen)
Hallo,
wie kann ich ein Bild in Blaustufen umwandeln? D.h. das Bild soll so wie ein Graustufenbild aussehen nur eben nicht in grau sondern in blau. Hat da jemand einen Tipp? Ganz gut wäre es auch, wenn die Lösung so allgemein wäre, dass die die Farbe, in die gewandelt werden soll, angeben könnte. Danke! Graustufen mache ich so:
Delphi-Quellcode:
for X := 0 to Image.Width - 1 do
for Y := 0 to Image.Height - 1 do begin PxlColor := ColorToRGB((Image as TBitmap).Canvas.Pixels[X, Y]); C := Round((((PxlColor shr 16) + ((PxlColor shr 8) and $00FF) + (PxlColor and $0000FF)) div 3)) div 2 + 96; (Image as TBitmap).Canvas.Pixels[X, Y] := RGB(C, C, C); end; |
Re: Bild: Umwandlung in Blaustufen (nicht Graustufen)
Hallo, das ist ganz einfach:
Delphi-Quellcode:
Ich würd das ganze aber mit Scanline machen:
for X := 0 to Image.Width - 1 do
for Y := 0 to Image.Height - 1 do begin PxlColor := ColorToRGB((Image as TBitmap).Canvas.Pixels[X, Y]); C := Round((((PxlColor shr 16) + ((PxlColor shr 8) and $00FF) + (PxlColor and $0000FF)) div 3)) div 2 + 96; (Image as TBitmap).Canvas.Pixels[X, Y] := RGB(0, 0, C); //da spielt die musik end;
Delphi-Quellcode:
Ich hoffe das funktioniert so, hab das ausm Gedächtnics getippt, eventuell muss man da noch ein bisschen rumcasten.
var
lineptr: PColor; lineptr := (Image as TBitmap).ScanLine[0]; //erstes bildpixel for Y := 0 to Image.Height - 1 do begin for X := 0 to Image.Width - 1 do begin PxlColor := ColorToRGB(TColor(lineptr^)); C := Round((((PxlColor shr 16) + ((PxlColor shr 8) and $00FF) + (PxlColor and $0000FF)) div 3)) div 2 + 96; lineptr^ := RGB(0, 0, C); //da spielt die musik Inc(lineptr); //nächstes bildpixel end; end; |
Re: Bild: Umwandlung in Blaustufen (nicht Graustufen)
Die Helligkeitsberechnung kann ich zwar nicht ganz nachvollziehen (das ist weder der Mittelwert aller Kanäle noch der bekannte Grauwert = 0,299·Rot + 0,587·Grün + 0,114·Blau. Und überhaupt, Round bei int-Werten? div 3 div 2? Klammernwald *g* ?), aber sobald man den Helligkeitsanteil (0 <= x <= 1) in der Hand hat, muss man ihn nur noch mit der gewünschten Farbe multiplizieren.
|
Re: Bild: Umwandlung in Blaustufen (nicht Graustufen)
Hab's mal eben so versucht (Nur für 32bit Bilder):
Delphi-Quellcode:
NewCol bestimmt den Farbton, den das umgewandelte Bild haben soll. Für ein reines Graustufenbild muß also $00FFFFFF verwendet werden, für ein Blaustufenbild $00FF0000.
procedure ConvertBitmap32(BM: TBitmap; NewCol: TColor);
var x, y : Integer; p : pintegerarray; Gray : Integer; r,g,b: integer; begin if BM.PixelFormat <> pf32bit then Exit; // Separate desired color into RGB b := (NewCol and $FF0000) shr 16; g := (NewCol and $FF00 ) shr 8; r := (NewCol and $FF ); // Change color for each pixel for y := BM.Height-1 downto 0 do begin p := BM.ScanLine[y]; for x := 0 TO BM.Width-1 do begin // Determine gray value (Gray = 0.11*B + 0.50*G + 0.30*R) Gray := (((p^[x] and $FF) ) * 28 + // about 11% blue ((p^[x] and $FF00) shr 8) * 128 + // about 50% green ((p^[x] and $FF0000) shr 16) * 100) shr 8; // about 39% red // Gray now is between 0 and 255 // Adjust color p^[x] := (((r * Gray) shr 8) shl 16 ) or (((g * Gray) shr 8) shl 8 ) or (((b * Gray) shr 8)); end; end; END; Die Bestimmung des Grauwertes folgt nur grob der von Khabarakh angesprochenen Umwandlung, aber solche Feinheiten sehen wir auf unseren unkalibrierten Monitoren eh nicht ;) Allerdings ergibt sich durch diese Verwendung folgender Effekt: Ein helles blau wirkt im Blaustufenbild dunkler als im Original. Gruß Michael |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:48 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz