14-Bit Raw Data Displayed on a TImage??


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);
   i, j: integer;
   Grayshade, Red, Green, Blue: Byte;
  for j := 0 to 576 do
       for i:= 0 to 771 do

             // 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);

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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wim ten BrinkSelf-employed developerCommented:
14-bit greyscale? Then what are the last two bits used for? Or are the last two bits used as the first two bits of the next pixel? If this is a stream of bits then you have to do a bit more calculations to find the position of a pixel. If it's just 14 bits padded to 16 bits then your code should work.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
engdmorrAuthor Commented:
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?
hello engdmorr, I can not find what you are trying to do with your code? What is this code

Red := ImArray[i][j];
 Green := ImArray[i][j] shr 8;
 Blue  := ImArray[i][j] shr 16;

suppose to do?
as near as I can figure, There are no Red, Green and Blue values in a 14 bit grayscale. . . It might have 16383 intensity values of GREY, no red green and blue, much like the 8 bit greyscale, which has 256 grey values, but no Red, green or blue values. I have not tried to do a 14 bit read, but I do notknow if there would be any padding, but maybe there would be, since reading 14 bit boundries, wound seem to be difficult be difficult, but you might try to read an intensity of grey fron the ImArray[i][j] instead of the Red, green and blue values, and then divide by 64 to get a value between 0 and 255. . . what is the ImArray an Array of? what is it, an array of word (16-bit)
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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);
engdmorrAuthor Commented:
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);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.