Solved

14-Bit Raw Data Displayed on a TImage??

Posted on 2003-10-27
9
282 Views
Last Modified: 2010-04-05
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.
0
Comment
Question by:engdmorr
  • 4
  • 2
9 Comments
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 63 total points
ID: 9634141
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.
0
 

Author Comment

by:engdmorr
ID: 9635655
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?
0
 
LVL 33

Assisted Solution

by:Slick812
Slick812 earned 62 total points
ID: 9639377
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)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Expert Comment

by:Slick812
ID: 9639450
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);

0
 
LVL 33

Expert Comment

by:Slick812
ID: 9639517
or just eliminate the high bits

Grayshade  := (ImArray[i][j] and not $C000) div 64;
Image1.Canvas.Pixels[i,j] := RGB(Grayshade,Grayshade,Grayshade);
0
 

Author Comment

by:engdmorr
ID: 9650824
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.
0
 
LVL 33

Expert Comment

by:Slick812
ID: 9652929
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);
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now