Hi!
Which is the right way of reading pixel data from a dicom image. If one looks at the ImageProcessor <a href="http://[http://rsb.info.nih.gov/ij/developer/api/ij/process/ImageProcessor.html ]">ImageProcessor float getPixelValue(int x, int y) Object getPixels() int getPixel(int x, int y) Thanks |
Hi Muqueet,
here is a short description: > float getPixelValue(int x, int y) for FloatProcessors: pixel value for ColorProcessors: brightness (0-255) for 8&16 bit: calibrated value if calibration, uncalibrated value (0-255, 0-65535) otherwise. > int getPixel(int x, int y) for 8&16-bit: uncalibrated pixel value for ColorProcessors: an int holding the r, g, b values in the three lowest bytes for FloatProcessors: you have to convert this into a float number by Float.intBitsToFloat() > Object getPixels() an array of all pixels. byte[], short[], int[] and float[] for Byte, Short, Color and Floatprocessors, respectively. So, if you want to read pixel values and have your plugin work for all types of ImageProcessor, use float getPixelValue(int x, int y). If you are writing a PlugInFilter, the easiest is to specify the CONVERT_TO_FLOAT flag. Then your filter will be always called with a FloatProcessor (uncalibrated), and after filtering, the data will be converted back. For ColorProcessors, this is done three times (once for each color). In this case, one would usually access the pixels array: float[] pixels = (float[])ip.getPixels(); float value = pixels(x+y*width); Michael ________________________________________________________________ On 5 Jan 2010, at 11:15, Muqeet Khan wrote: > Hi! > > Which is the right way of reading pixel data from a dicom image. If > one > looks at the ImageProcessor > http://[http://rsb.info.nih.gov/ij/developer/api/ij/process/ > ImageProcessor.html > ] ImageProcessor > > float getPixelValue(int x, int y) > Object getPixels() > int getPixel(int x, int y) > > Thanks > |
So basically if i would use getPixels() then what i get is uncalibrated value (0-65535), so if i care about the real values then i need to apply the calibration. Calibration#getCValue(double value). Is it?
Thanks!
|
Hi Muqueet,
when using getPixels for a ByteProcessor or ShortProcessor, make sure that you care about the data being unsigned. As Java has no unsigned data type, you have to do this by a bitwise 'and' operation: ShortProcessor ip = ... short[] pixels = (short[])ip.getPixels(); int iValue = pixels[x+y*width]&0xffff; //use &0xff for byte Then you can use iValue to look up the calibrated value in the calibration table. If you have only an ImageProcessor, not an ImagePlus, use float[] cTable = ip.getCalibrationTable(); float fValue = cTable==null ? iValue : cTable[iValue]; Of course, if you want calibrated values, ip.getPixelValue(x, y) would be much easier, and it will also work for other image types: float fValue = ip.getPixelValue(x, y); Michael ________________________________________________________________ On 5 Jan 2010, at 21:05, Muqeet Khan wrote: > So basically if i would use getPixels() then what i get is > uncalibrated value > (0-65535), so if i care about the real values then i need to apply the > calibration. Calibration#getCValue(double value). Is it? > > Thanks! > > > Michael Schmid-3 wrote: >> >> Hi Muqueet, >> >> here is a short description: >> >>> float getPixelValue(int x, int y) >> >> for FloatProcessors: pixel value >> for ColorProcessors: brightness (0-255) >> for 8&16 bit: calibrated value if calibration, uncalibrated value >> (0-255, 0-65535) otherwise. >> >>> int getPixel(int x, int y) >> >> for 8&16-bit: uncalibrated pixel value >> for ColorProcessors: an int holding the r, g, b values in the >> three lowest bytes >> for FloatProcessors: you have to convert this into a float number >> by Float.intBitsToFloat() >> >>> Object getPixels() >> an array of all pixels. byte[], short[], int[] and float[] for >> Byte, Short, Color and Floatprocessors, respectively. >> >> So, if you want to read pixel values and have your plugin work for >> all types of ImageProcessor, use float getPixelValue(int x, int y). >> >> If you are writing a PlugInFilter, the easiest is to specify the >> CONVERT_TO_FLOAT flag. Then your filter will be always called with a >> FloatProcessor (uncalibrated), and after filtering, the data will be >> converted back. For ColorProcessors, this is done three times (once >> for each color). In this case, one would usually access the pixels >> array: >> float[] pixels = (float[])ip.getPixels(); >> float value = pixels(x+y*width); >> >> Michael >> ________________________________________________________________ >> >> On 5 Jan 2010, at 11:15, Muqeet Khan wrote: >> >>> Hi! >>> >>> Which is the right way of reading pixel data from a dicom image. If >>> one >>> looks at the ImageProcessor >>> http://[http://rsb.info.nih.gov/ij/developer/api/ij/process/ >>> ImageProcessor.html >>> ] ImageProcessor >>> >>> float getPixelValue(int x, int y) >>> Object getPixels() >>> int getPixel(int x, int y) >>> >>> Thanks >>> >> >> > > -- > View this message in context: http://n2.nabble.com/Reading-pixel- > value-tp4254405p4257095.html > Sent from the ImageJ mailing list archive at Nabble.com. |
float fValue = ip.getPixelValue(x, y); for this do i still further need to look-up the calibrated value in the calibration table.
Thanks!
|
On Wednesday 06 January 2010 17:32:53 you wrote:
> float fValue = ip.getPixelValue(x, y); for this do i still further need to > look-up the calibrated value in the calibration table. Hi, Have a look at the api here: http://rsb.info.nih.gov/ij/developer/api/ This is the one you want: http://rsb.info.nih.gov/ij/developer/api/ij/process/ImageProcessor.html#getPixelValue(int, int) (sorry if the link gets truncated) public abstract float getPixelValue(int x, int y) Returns the value of the pixel at (x,y). For byte and short images, returns a calibrated value if a calibration table has been set using setCalibraionTable(). For RGB images, returns the luminance value. Cheers G. |
Hi!
Instead of setting the calibration table can i subtract 32768 float iValue = getPixelValue(int x, int y) - 32768 Thanks!
|
Free forum by Nabble | Edit this page |