Posted by
Michael Schmid on
URL: http://imagej.273.s1.nabble.com/Create-an-Tiff-image-reading-pixel-values-of-16-bit-signed-image-tp3690357p3690360.html
Hi Muqeet,
if you input data are signed, and you want to convert them to float,
simply use
short[] inPixels = (short[])inImageProcessor.getPixels();
float[] outPixels = new float[inPixels.length];
for (int i=0; i<inPixels.length; i++)
outPixels[i] = inPixels[i]; //conversion keeps sign
for unsigned data, you would need to disable the sign explicitly:
outPixels[i] = (float)(inPixels[i]&0xffff);
If you want to keep a shortProcessor, simply do an exclusive or with
0x8000 on all pixels, i.e., flip the highest bit. You can then set the
value calibration of the ImagePlus if you care about the numeric values:
Calibration cal = imp.getCalibration();
double[] coeff = new double[2];
coeff[0] = -32768.0;
coeff[1] = 1.0;
cal.setFunction(Calibration.STRAIGHT_LINE, coeff, "gray value");
Michael
________________________________________________________________________
On Sat, November 21, 2009 14:40, Muqeet Khan wrote:
> I know use FloatProcessor, i get the image but it does not look ok. Any
> idea
> what is going wrong here?
>
> Muqeet Khan wrote:
>>
>> Is it due to the reason that you use short and values greater than
>> 32,767
>> turns out to be negative. How do i retain the original pixel value. Well
>> i
>> could use putPixelValue.... but my actual intention later is to take
>> mean
>> of couple of image pixels and generate an image. So i have to use
>> setPixels(...) which expects me to use only short data type. Any idea
>> how
>> to retain the original pixel value in this scenario???
>>
>> Muqeet Khan wrote:
>>>
>>> I have a 16-bit signed image, i want to create a tiff image by reading
>>> the pixel values of the 16-bit signed image. For some reason i don't
>>> get
>>> a proper tiff image when doing it. Here are the steps.
>>>
>>> ImagePlus createImage(ImagePlus imagePlus, ImageProcessor targetImage)
>>> {
>>>
>>> int pixelCount = imagePlus.getWidth() * imagePlus.getHeight();
>>> Short pixels[] = new Short[pixelCount]
>>> ImageProcessor iP = imagePlus.getProcessor();
>>> int count = 0;
>>>
>>> for (int x = 0;x < imagePlus.getWidth(); x++) {
>>>
>>> for (int y = 0; y < imagePlus.getHeight; y++) {
>>> double pixelValue = iP.getPixelValue(x, y);
>>> pixels[count] = pixelValue;
>>> count ++;
>>> }
>>> }
>>>
>>> targetImage.setPixels(pixels);
>>> targetImage .resetMinAndMax();
>>> return new ImagePlus("Image-RXZ", targetImage);
>>> }
>>>
>>> Is this correct way of doing???
>>>
>>
>>
>
> --
> View this message in context:
>
http://n2.nabble.com/Create-an-Tiff-image-reading-pixel-values-of-16-bit-signed-image-tp4038039p4042633.html> Sent from the ImageJ mailing list archive at Nabble.com.
>