Login  Register

setMinAndMax() fails on currently selected channel of a CompositeImage

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

setMinAndMax() fails on currently selected channel of a CompositeImage

Michael Ellis
43 posts
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();
                        }
                }
        }
}
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: setMinAndMax() fails on currently selected channel of a CompositeImage

Rasband, Wayne (NIH/NIMH) [E]
1064 posts
On May 21, 2010, at 1:07 PM, Michael Ellis wrote:

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

Try using

    imp.setPosition(channel, imp.getSlice(), imp.getFrame());
    imp.setDisplayRange(min, max);

which is what the "Image>Adjust>Color Balance widget (ij.plugin.frame.ContrastAdjuster.java) uses.

-wayne


>
> /
> *------------------------------------------------------------------------------------------------------------*/
> 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();
> }
> }
> }
> }
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: setMinAndMax() fails on currently selected channel of a CompositeImage

Michael Ellis
43 posts
Wayne, thanks. That does the trick.

I don't understand the difference between the two approaches, the code  
for CompositeImage and associated goodies is pretty hairy, but at  
least it is working so I'm a happy bunny!

Many thanks.


On 21 May 2010, at 18:59, Rasband, Wayne (NIH/NIMH) [E] wrote:

> On May 21, 2010, at 1:07 PM, Michael Ellis wrote:
>
>> 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!
>
> Try using
>
>    imp.setPosition(channel, imp.getSlice(), imp.getFrame());
>    imp.setDisplayRange(min, max);
>
> which is what the "Image>Adjust>Color Balance widget  
> (ij.plugin.frame.ContrastAdjuster.java) uses.
>
> -wayne
>
<snip>

Michael Ellis
Managing Director
Digital Scientific UK Ltd.
http://www.digitalscientific.co.uk
[hidden email]
tel: +44(0)1223 329993
fax: +44(0)1223 370040

Sheraton House
Castle Park
Cambridge
CB3 0AX


The contents of this e-mail may be privileged and are confidential.  
It may not be disclosed to or used by anyone other than the  
addressee(s), nor copied in any way.  If received in error, please  
advise the sender and delete it from your system.