Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

14-Bit Raw Data Displayed on a TImage??

Posted on 2003-10-27
Last Modified: 2010-04-05

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.
Question by:engdmorr
  • 4
  • 2
LVL 17

Accepted Solution

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.

Author Comment

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?
LVL 34

Assisted Solution

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)
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 34

Expert Comment

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

LVL 34

Expert Comment

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

Author Comment

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.
LVL 34

Expert Comment

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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