setMinAndMax() fails on currently selected channel of a CompositeImage
Posted by Michael Ellis on May 21, 2010; 5:07pm
URL: http://imagej.273.s1.nabble.com/setMinAndMax-fails-on-currently-selected-channel-of-a-CompositeImage-tp3688229.html
I'm trying to write a plugin that will let me interactively manipulate
a CompositeImage.
I find setMinAndMax() fails to work on the image processor returned by
getProcessor(channelIndex)
for the currently selected channel of the CompositeImage.
The plugin below is a minimal piece of code that illustrates my problem.
It creates an 8 bit 256x256 3 channel CompositeImage filling each
channel with a ramp.
By default the LUTS for each channel are:
channel 1 = red
channel 2 = green
channel 3 = blue
I set the min and max values using setMinAndMax(175,200) for each
channel.
I repeat this three times, selecting channel 1, then 2, then 3. In
each case the
setMinAndMax(175,200) appears to fail for the currently selected
channel.
My goal is to create a plugin where I can interactively adjust the
enabled,
min and max values for every plane in a composite image.
Using setPosition() to select a channel other than the one I want to
adjust
seems to work around the problem (try setting workAround to true) but
this
seem inelegant and probably indicative that I am doing something wrong!
Help!
/
*------------------------------------------------------------------------------------------------------------*/
import ij.CompositeImage;
import ij.IJ;
import ij.ImagePlus;
import ij.plugin.PlugIn;
import ij.process.ImageProcessor;
public class My_Plugin implements PlugIn {
public My_Plugin() {
}
public void run(String arg) {
for (int channelSelect = 1; channelSelect <= 3; ++channelSelect) {
ImagePlus imp = IJ.createImage("Chan select=" + channelSelect, "8-
bit Ramp", 256, 256, 3);
CompositeImage ci = new CompositeImage(imp,
CompositeImage.COMPOSITE);
ci.show();
ci.setPosition(channelSelect);
for (int channelIndex = 1; channelIndex <= 3; ++channelIndex) {
boolean workAround = false;
if (workAround) {
// Select any channel other than the one we are changing.
ci.setPosition(channelIndex < 3 ? channelIndex + 1 : 1);
}
final int min = 175, max = 200;
ImageProcessor cip = ci.getProcessor(channelIndex);
cip.setMinAndMax(min, max);
ci.updateAndDraw();
}
}
}
}