Solved

14-Bit Raw Data Displayed on a TImage??

Posted on 2003-10-27
9
279 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

12 Experts available now in Live!

Get 1:1 Help Now