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.