engdmorr
asked on
14-Bit Raw Data Displayed on a TImage??
Hi,
I am writing a program that reads in raw image data from a file and prints it to a TImage box in Delphi. The Image format is 14-bit grayscale (i.e. 16383 intensity values). I have tried to code this up using the following procedure image just isnt representative of what it should be like.
procedure TForm1.DrawImageButtonClic k(Sender: TObject);
var
i, j: integer;
Grayshade, Red, Green, Blue: Byte;
begin
for j := 0 to 576 do
begin
for i:= 0 to 771 do
begin
// This routine gets the Red, Green and Blue components and converts them into gray
Red := ImArray[i][j];
Green := ImArray[i][j] shr 8;
Blue := ImArray[i][j] shr 16;
Grayshade := Round(0.3 * Red + 0.6 * Green + 0.1 * Blue);
Image1.Canvas.Pixels[i,j] := RGB(Grayshade,Grayshade,Gr ayshade);
end;
end;
end;
If you could point me in the right direction that would be great. I am relatively new to Delphi so if I am using totally the wrong technique then I am open to other suggestions.
Just to re-iterate, the image format is 14-bit grayscale, dont ask me why, probably something to do with the hardware where the data comes from.
Your help is much appreciated.
I am writing a program that reads in raw image data from a file and prints it to a TImage box in Delphi. The Image format is 14-bit grayscale (i.e. 16383 intensity values). I have tried to code this up using the following procedure image just isnt representative of what it should be like.
procedure TForm1.DrawImageButtonClic
var
i, j: integer;
Grayshade, Red, Green, Blue: Byte;
begin
for j := 0 to 576 do
begin
for i:= 0 to 771 do
begin
// This routine gets the Red, Green and Blue components and converts them into gray
Red := ImArray[i][j];
Green := ImArray[i][j] shr 8;
Blue := ImArray[i][j] shr 16;
Grayshade := Round(0.3 * Red + 0.6 * Green + 0.1 * Blue);
Image1.Canvas.Pixels[i,j] := RGB(Grayshade,Grayshade,Gr
end;
end;
end;
If you could point me in the right direction that would be great. I am relatively new to Delphi so if I am using totally the wrong technique then I am open to other suggestions.
Just to re-iterate, the image format is 14-bit grayscale, dont ask me why, probably something to do with the hardware where the data comes from.
Your help is much appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if ImArray[i][j] is a "WORD" (16-Bit), and the Unused bits are Not Set, then you might try
Grayshade := ImArray[i][j] div 64;
Image1.Canvas.Pixels[i,j] := RGB(Grayshade,Grayshade,Gr ayshade);
Grayshade := ImArray[i][j] div 64;
Image1.Canvas.Pixels[i,j] := RGB(Grayshade,Grayshade,Gr
or just eliminate the high bits
Grayshade := (ImArray[i][j] and not $C000) div 64;
Image1.Canvas.Pixels[i,j] := RGB(Grayshade,Grayshade,Gr ayshade);
Grayshade := (ImArray[i][j] and not $C000) div 64;
Image1.Canvas.Pixels[i,j] := RGB(Grayshade,Grayshade,Gr
ASKER
Still nothing seems to work. Will probably just give up now, have spent far too much time on this one. Thanks for all the comments though.
if the bits are in the upper segment of the of the word value, you might try a shr 8
Grayshade := ImArray[i][j] shr 8;
Image1.Canvas.Pixels[i,j] := RGB(Grayshade,Grayshade,Gr ayshade);
Grayshade := ImArray[i][j] shr 8;
Image1.Canvas.Pixels[i,j] := RGB(Grayshade,Grayshade,Gr
ASKER