Welcome to LEAD Support Forum Login | Register | Faq  

    LEAD Support Forum
  Resource to find answers and post technical questions about LEAD products.
Search    
   

Re: Get Grayscale values
Started by Andi at 07-01-2008 8:36. Topic has 4 replies.

Print Search « Previous Thread Next Thread »
  07-01-2008, 8:36
Andi is not online. Last active: 7/1/2008 1:21:01 PM Andi

Not Ranked
Joined on 07-01-2008
Posts 3
Get Grayscale values
Reply Quote
Hey everyone,

i have a couple of grayscale CT Images and i need the pixelvalues. i know there is the method GetPixelData() and it returns a char-array. For 8bit, 16bit... grayscale images it works fine and i can convert the the resultarray into short and integer. But i have problems with 12bit, 13bit grayscale imges. The values are still in two char (16 bit) and i dont know how get the right value out of it.

Is there another methode to get grayscalevalues or does anybody know how to convert such a char-array into a short or a integer in C++?

Thanks in advance
Andi

   Report 
  07-01-2008, 11:00
Adam Boulad is not online. Last active: 11/20/2008 3:23:08 PM Adam Boulad



Top 10 Posts
Joined on 09-16-2007
Posts 513
Re: Get Grayscale values
Reply Quote
Andi,
If the allocated bits are 16 and the stored bits are less than that, such as 12 or 13, you can get the actual value by shifting the 16-bit integer value to the right a number of bits equal to the low bit of the value. This means if the high bit is 15 and the Low Bit is 3, the actual value is (StoredValue >> 3).


Adam Boulad
LEADTOOLS Technical Support

   Report 
  07-02-2008, 2:43
Andi is not online. Last active: 7/1/2008 1:21:01 PM Andi

Not Ranked
Joined on 07-01-2008
Posts 3
Re: Get Grayscale values
Reply Quote
Hello,
thanks for your answer. i also thought to solve the problem by shifting, but i got wrong results with negative values. An example:
My data: 00011100 00000000 which is signed and the Highbit in 12. The result must be 1024 but i got 7168.  I solved that by the follwoing lines:

char *pixeldata = leadbitmap.GetPixelData(...);
short value = 0xe000;
value |= (pixeldata[1] << 8 | pixeldata[0]);

In this way a get the right values just for negative data and only for data where the HighBit is 12. If the HighBit is another one i need of course another Bitmask. I don´t think that this is the best choice to solve my problem and thats why I am asking if there is a better solution to get the pixelvalues out of grayscaleimages.

Greetings
Andi

   Report 
  07-02-2008, 10:36
Adam Boulad is not online. Last active: 11/20/2008 3:23:08 PM Adam Boulad



Top 10 Posts
Joined on 09-16-2007
Posts 513
Re: Get Grayscale values
Reply Quote
Andi,
It seems your data is already in the correct bit positions (13 bits from 0 to 12), but your problem is with the sign bit. If that's the case, one easy solution that will solve it for both positive and negative pixel values is the following:
1. Put the bits in a signed 16-bit integer.
2. Shift it left by 3 bits.
3. Perform integer division by 8. This will shift right by 3 bits, and also perform sign extension so the high 3 bits will be all 1 for negative numbers, and all 0 for non-negative numbers.

To make it general, the same steps become:
1. Calculate N1 = (15 - High Bit location), and N2 = (Low Bit)
2. Put the bits in a signed 16-bit integer.
3. Shift left by N1 bits.
4. Divide by (2 to the power (N1+N2))
Adam Boulad
LEADTOOLS Technical Support

   Report 
  07-02-2008, 11:25
Andi is not online. Last active: 7/1/2008 1:21:01 PM Andi

Not Ranked
Joined on 07-01-2008
Posts 3
Re: Get Grayscale values
Reply Quote
Thank you very much for this solution. The general way is exactly what i need.

Greetings
Andi

   Report 
Post
LEAD Support Fo... » Developer » Image Processin... » Re: Get Grayscale values

Powered by Community Server, by Telligent Systems