0
votes

The objective of the plugin is to take a slice from a stack and then create a new stack with multiple images of the same slice but with different contrasts.

I wrote a for loop, but the results are not what I intended. The new stack is created but it's always the same image in every slice. What am I missing here?

public void run(ImageProcessor ip) {
    ImageProcessor ip2 = ip.duplicate();
    ImageStack nstack = new ImageStack(stack.getWidth(),stack.getHeight());
    ip2.snapshot();
        for(int i=0; i<256; i=i+10){
        ip2.setMinAndMax(0,i);
        nstack.addSlice("Contrast "+i, ip2);
        ip2.reset();
        }

    ImagePlus imp2= new ImagePlus("teste", nstack);
    imp2.show();
    }}
1
The addSlice method only updates the min and max the first time it's called (if there are no other slices) so your settings aren't being preserved. I'm not sure how to do what you want though... you may have better luck on the ImageJ Mailing list. - hinerm
Thank you very much for your input. I will try there :) - JessicaJones

1 Answers

0
votes

As pointed out by Michael Schmid on the ImageJ mailing list,

the Brightness & Contrast settings determine how the data are displayed, they do not affect the actual data

In case of 8-bit images, you can use the applyLut() method of the ByteProcessor class after setting the contrast:

ip2.setMinAndMax(0,i);
ip2.applyLut();