![]() |
8 Bit Grauwert Bild speichern
Hallo zusammen,
ich verzweifele gerade daran ein 8 bit Bild mit Grauwerten abzuspeichern. Ich greife mir aus einem Bild mit 3 Kanälen einen heraus und speichere die Werte in einem neuen TBitmap mit PixelFormat pf8bit.
Delphi-Quellcode:
Wenn ich das nun abspeichere erhalte ich zwar ein Bild mit 8 Bit pro Kanal und einem Kanal aber leider ist das Bild in Farbe und nicht grau.
var
rowGrey: PByte; rowRGB: ^TRGBTriple; ... image := TBitmap.Create; image.PixelFormat := pf8bit; image.Width := image1.Picture.Width; image.Height := image1.Picture.Height; for j := 0 to image1.Picture.Height-1 do begin rowGrey := image.ScanLine[j]; rowRGB := image1.Picture.Bitmap.Scanline[j]; for i := 0 to image1.Picture.Width-1 do begin rowGrey^ := min(round(rowRGB^.rgbtRed), 255); inc (rowGrey); inc (rowRGB); end; end; Ich hab gelesen, dass man bei einem Bild mit PixelFormat pf8bit eine Farb-Palette setzten muss, da sonst die Standard Palette genommen wird die diese dann zu der Farbdarstellung führt. Gut hab ich also eine Farbpalette gebastelt.
Delphi-Quellcode:
Wenn ich das Bild allerdings mit der Palette speichere, werden die Farbwerte die sich zwischen den Helligkeitswerten 30 - 50 liegen auf 0 - 255 skaliert angezeigt.
GrayPal.palVersion := $0300;
GrayPal.palNumEntries := 256; for i := 0 to 255 do begin GrayPal.palPalEntry[i].peRed := i; GrayPal.palPalEntry[i].peGreen := i; GrayPal.palPalEntry[i].peBlue := i; GrayPal.palPalEntry[i].peFlags := PC_NOCOLLAPSE; end; image.Palette := CreatePalette(PLogPalette(@Graypal)^); Habt ihr eine Idee woran das liegt? Brauche ich hier eine andere Palette? Gibt es eine andere Möglichkeit die Grauwerte direkt als Werte und nicht als Index für eine LookUpTable abzuspeichern so wie bei pf24bit? |
AW: 8 Bit Grauwert Bild speichern
|
AW: 8 Bit Grauwert Bild speichern
So wie du es beschreibst bekomme ich zwar auch ein Graubild aber in 3 Kanälen und nicht so wie ich es beschrieben habe mit einem PixelFormat pf8bit also nur einem Kanal.
Ich möchte ja gerade nicht die selben Informationen drei mal abspeichern. Außerdem stehen in meinem TBitmap schon die richtigen Grauwerte drin es geht nur ums Abspeichern wonach das resultierende bmp dann als 8Bit color und nicht 8 bit grey erkannt wird. |
AW: 8 Bit Grauwert Bild speichern
[edit] mist
|
AW: 8 Bit Grauwert Bild speichern
*grummel*
hab Geister gesucht. Wenn ich die Zuweisung der Palette nach oben verschiebe über die Zuweisung der Werte funktioniert alles
Delphi-Quellcode:
ImageJ zeigt mir nun auch grayscale LUT und nicht mehr color LUT. Warum eine spätere Zuweisung einer LookUpTable die eigentlichen Werte im TBitmap verändert ist mir noch nicht so ganz klar und warum es dafür keine Funktion zu geben scheint auch nich aber nun ja tut nun :)
var
rowGrey: PByte; rowRGB: ^TRGBTriple; GrayPal:TMaxLogPalette; PaletteSize: integer; ... image := TBitmap.Create; image.PixelFormat := pf8bit; image.Width := image1.Picture.Width; image.Height := image1.Picture.Height; GrayPal.palVersion := $0300; GrayPal.palNumEntries := 256; for i := 0 to 255 do begin GrayPal.palPalEntry[i].peRed := i; GrayPal.palPalEntry[i].peGreen := i; GrayPal.palPalEntry[i].peBlue := i; GrayPal.palPalEntry[i].peFlags := PC_NOCOLLAPSE; end; image.Palette := CreatePalette(PLogPalette(@Graypal)^); for j := 0 to image1.Picture.Height-1 do begin rowGrey := image.ScanLine[j]; rowRGB := image1.Picture.Bitmap.Scanline[j]; for i := 0 to image1.Picture.Width-1 do begin rowGrey^ := min(round(rowRGB^.rgbtRed), 255); inc (rowGrey); inc (rowRGB); end; end; danke an alle |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:13 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