0

I am developing a dicom viewer in c#.net . I need a little help on calculating the HU Value of Pixel . I know the formula for calculating the HU is ,

  HU = Pixel Value * Rescale Slope + Rescale Intercept 

I made some calculations and retrieved from my original dicom pixel value but thats not giving me the right HU value . My question is what is exactly the pixel value . Anyone Help Me On this .

This is my code

 public void calculateHU(string x,string y)
        {
            Int32 intercept, slope,pix;
            intercept = -1024;
            slope = 1;
            int xx, yy;
            xx = Convert.ToInt32(x);
            yy = Convert.ToInt32(y);
            xx = xx +Convert.ToInt32( imagerect.X);
            yy = yy + Convert.ToInt32( imagerect.Y);
            pix =  getpixelvalue(xx,yy);
            double hu = pix * slope + intercept;

        }

        public Int32 getpixelvalue(int x, int y)
        {
            string c;
            c = pix16[imgno][y * bmd.width + x].ToString();
            return Convert.ToInt32(c);
        }
DjMalaikallan
  • 389
  • 1
  • 4
  • 13
  • Please show some code on how you are retrieving the value and performing the math. If that is the formula, then then the formula is correct. We need to see what you have done to figure out what has gone wrong. – Scott Chamberlain May 21 '12 at 13:48
  • Could you please give an example of what you get and what you expect to get? Please also explain what the _pix16_ array actually contains: are these raw values? Big/little-endian accounted for? Signed/unsigned? – Anders Gustafsson May 21 '12 at 14:28
  • I am getting the Hu Value 32968 instead of 67 . pix16 is a two dimensional dicom raw data storage. And Little Endian . Unsigned . – DjMalaikallan May 21 '12 at 14:33
  • What value type are the _pix16_ elements? What are you trying to achieve by applying `.ToString()`? If _pix16_ contains _unsigned short_:s or _char_:s, I think you should simply return `Convert.ToInt32(pix16[imgno][y * bmd.width + x])`. – Anders Gustafsson May 21 '12 at 15:44
  • If I were you, I would: double-check the endianness (little vs. big) and value representation used (OB vs. OW); confirm whether the data is signed or unsigned; look at Bits Allocated, Bits Stored, and High Bit to determine if there are unused bits that should be masked; check the photometric interpretation to be sure that you are really dealing with monochrome data. – Matt May 21 '12 at 22:40
  • Also, as shown, your code is using constant values for the rescale slope and intercept. These values should be determined by reading those attributes directly from the header for each image. Maybe you already did that and are just displaying them as fixed values to simplify the presentation of your code here. However, if that is not the case, the use of those constants could be the problem. – Matt May 21 '12 at 23:36
  • I am getting the pixel values as 0 to 255 ... Is that right ? ... – DjMalaikallan May 22 '12 at 10:58
  • Do you mean that you are getting values 0 to 255 for a _short_ or _ushort_ array? In that case you need to check how the pixel data is read, because the normal range would be 0 to 4095 (12 bits unsigned). As Matt points out, you should also check that the complementary parameters are properly set. – Anders Gustafsson May 22 '12 at 12:14
  • Thanks for that i have cross checked everything i realized what my problem is , my values 0-255 are grayscale 8 bit values . and then i searched for the actual stored pixel values and found those as something like 32768,30768,... But not the range between 0 to 4095 ... – DjMalaikallan May 23 '12 at 05:32
  • So far i found the answer by again a full check ... Now i got my Hounsfield Values exactly right for positive values . But No negative values are coming ... example for the -1028 Hu i got 252 HU. Any help – DjMalaikallan May 23 '12 at 10:26

1 Answers1

2

If Pixel Representation (0028,0103) is set to 0 (unsigned), the Pixel Data values should be non-negative. According to your example where the intercept and slope are -1024 and 1, respectively, the raw pixel value would have to be -4 to yield HU value -1028.

If you are expecting to obtain resulting HU values as low as -1028, this is most probably managed through a negative enough Rescale Intercept value (and potentially Rescale Slope) value instead.

Rather than hard coding Rescale Intercept and Slope, grab these values from the image, tags (0028,1052) and (0028,1053) respectively, and apply in the HU calculation.

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
  • Thank you Anders , i found the solution ... I am just changed everything including stored pixel value type from unsigned to signed . Now i got the exact HU .... Thank you .... – DjMalaikallan May 23 '12 at 13:09
  • Any idea on how to convert the signed pixel value to unsigned pixel value using the dicom attributes? – Shankar S Oct 29 '19 at 08:10