why pixels are shown in strange values??

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

why pixels are shown in strange values??

周鑫
Hi all,

I found some strange result when I program with ImageJ.
The version I use is still 1.46.

What happened is that I simply applied a crop operation in ImageProcessor.
Here is the code:

public static ImageStack getCroppedStack(ImageStack ip_stack, int x, int y, int crop_width, int crop_height)
    {
        ImageStack stack     = ip_stack;
        int    size             = stack.getSize();
       
        ImageStack cropped_stack = new ImageStack(crop_width, crop_height);
       
        for (int i=1; i<=size; i++)
        {
            ImageProcessor iproc = stack.getProcessor(i);
            iproc.setRoi(x,y,crop_width, crop_height);
            ImageProcessor croppedIp = iproc.crop();
            cropped_stack.addSlice(croppedIp);
        }
       
        return cropped_stack;
    }

The strange problem I had is that the value on each pixels in new stack is represented in a strange way.
For example, in ImageJ, when I looked at the two stack with the mouse pointed to one pixel, the original stack shows:
x=137.80, y= 72.48, z=0, value = 46
But in cropped stack, it shows
x=37.80, y= 22.48, z=0, value = -32722.00 (46)
why the correct value is in () but a negative value is used instead??

Yes, I forgot to say that imagej.plugins.nifti_io.Nifti_Writer is used to save the cropped stack in niifti format.
Anyone has an idea of what happened??

It is important because many operation refuse the negative values and I had a series of errors generated.

Best regards, Xin




--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: why pixels are shown in strange values??

Michael Schmid
Hi Xin,

your problem is not caused by 'crop' but by writing and reading the image.
For some reason, somewhere the image is interpreted as signed 16 bits, but
it should be unsigned.

I would recommend to
(1) Upgrade to the latest ImageJ version, and
(2) Make sure you have the latest nifty_io plugin (according to the update
history, a bug concerning signed 16-bit images was fixed in Nov 2012).

If the problem persists, it is probably a bug in nifty_io.

Michael

____________________________________________________________________

> Hi all,
>
> I found some strange result when I program with ImageJ.
> The version I use is still 1.46.
>
> What happened is that I simply applied a crop operation in ImageProcessor.
> Here is the code:
>
> public static ImageStack getCroppedStack(ImageStack ip_stack, int x, int
> y, int crop_width, int crop_height)
>     {
>         ImageStack stack     = ip_stack;
>         int    size             = stack.getSize();
>
>         ImageStack cropped_stack = new ImageStack(crop_width,
> crop_height);
>
>         for (int i=1; i<=size; i++)
>         {
>             ImageProcessor iproc = stack.getProcessor(i);
>             iproc.setRoi(x,y,crop_width, crop_height);
>             ImageProcessor croppedIp = iproc.crop();
>             cropped_stack.addSlice(croppedIp);
>         }
>
>         return cropped_stack;
>     }
>
> The strange problem I had is that the value on each pixels in new stack is
> represented in a strange way.
> For example, in ImageJ, when I looked at the two stack with the mouse
> pointed to one pixel, the original stack shows:
> x=137.80, y= 72.48, z=0, value = 46
> But in cropped stack, it shows
> x=37.80, y= 22.48, z=0, value = -32722.00 (46)
> why the correct value is in () but a negative value is used instead??
>
> Yes, I forgot to say that imagej.plugins.nifti_io.Nifti_Writer is used to
> save the cropped stack in niifti format.
> Anyone has an idea of what happened??
>
> It is important because many operation refuse the negative values and I
> had a series of errors generated.
>
> Best regards, Xin
>
>
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html