first stack slice isn't updated

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

first stack slice isn't updated

Ilan
I have a routine which masks an image to produce either zero or the original image value.
It works on all but the first slice. The first slice remains unchanged. It seems like setPixels doesn't want to set the first slice in the stack. I made a simplified test to show the problem. I have a mask which each pixel is either 0 or 255 (Convert to Mask function does this for me.) I convert the image to 16 bit mode.

The code is as follows
        void doTest() {
                int i, j, stkSz, sliceSz;
                short curVal;
                ImageStack maskStack;
                Object pix2;
                short[] maskIn, maskOut;
                stkSz = imgMask.getImageStackSize();
                maskStack = imgMask.getImageStack();
                for( i=1; i<=stkSz; i++) {
                        pix2 = maskStack.getPixels(i);
                        if(!(pix2 instanceof short [])) {
                                JOptionPane.showMessageDialog(this,"Must have 16 bit data on both series");
                                return;
                        }
                        maskIn = (short[]) pix2;
                        sliceSz = maskIn.length;
                        maskOut = new short[sliceSz];
                        for( j=0; j<sliceSz; j++) {
                                curVal = maskIn[j];
                                if( curVal != 0) curVal = 300;
                                maskOut[j] = curVal;
                        }
                        maskStack.setPixels(maskOut, i);
                }
                imgMask.repaintWindow();
                dispose();
        }

When I look at the results the first slice in the stack stays at 0 or 255. All the following slices have pixels of either 0 or 300, which is what I expect to get. It is as if the variable i should run from zero instead of 1, but I tried this and zero fails (as I expect it to fail).

This looks like a bug in the setPixels, or I am doing something stupid. Can anyone help me?

Thanks,
Ilan
Reply | Threaded
Open this post in threaded view
|

Re: first stack slice isn't updated

Ilan
Sorry, I was using an ancient version of ImageJ. In that version there was a problem. I just tried it in the most recent version and all is well.
I wouldn't have posted had I thought it could have mattered. So apparently I found some old bug.

Ilan