Login  Register

Re: Create an Tiff image reading pixel values of 16 bit signed image

Posted by Muqeet Khan on Nov 21, 2009; 1:40pm
URL: http://imagej.273.s1.nabble.com/Create-an-Tiff-image-reading-pixel-values-of-16-bit-signed-image-tp3690357p3690359.html

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???