Link to home
Start Free TrialLog in
Avatar of engdmorr
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.DrawImageButtonClick(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,Grayshade);
         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
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of engdmorr
engdmorr

ASKER

The last two bits arent used for anything.  The program gets its data from a raw image file and I disgard the two LSB's by doing a 'div 4' on the value.  I thought the above should work as well, thats why I coded it :)  But it doesnt.  I was thinking, would creating my own 14-bit pallette in Delphi be an option?  Has anyone attempted creating their own pallette before?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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,Grayshade);

or just eliminate the high bits

Grayshade  := (ImArray[i][j] and not $C000) div 64;
Image1.Canvas.Pixels[i,j] := RGB(Grayshade,Grayshade,Grayshade);
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,Grayshade);