ZProjector - can't process RGB stack?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ZProjector - can't process RGB stack?

Kenneth Sloan-3
Context: Java plugin

I’m currently building a stack containing two RGB images, like so:

    ImageStack RGStack = greenIPlus.createEmptyStack();
    RGStack.addSlice("Red",redIPlus.getProcessor());
    RGStack.addSlice("Green",greenIPlus.getProcessor());
    ImagePlus RGIPlus = new ImagePlus("Stack",RGStack);

Here, “red” and “green” refer to the dominant color in each image, but both are RGB images.  I suppose I *could* make them single channel and
color them, but I’d prefer “simple”.

If it matters, once this RGStack is built, I’m applying a fairly complicated overlay, which should appear no matter what slice is viewed.  That
all works now.  I’m just trying to enhance the stack by adding the Projection.

I want to also include a z-projected version, combining the two images.  I tried this:

    ZProjector zp = new ZProjector(RGIPlus);
    zp.setStartSlice(1);
    zp.setStopSlice(2);
    zp.setMethod(zp.SUM_METHOD);
    zp.doProjection();
    ImagePlus projectionIPlus = zp.getProjection();;
    RGStack.addSlice("Red+Green",projectionIPlus.getProcessor());


But, zp.doProjection() complains that it can only handle non-RGB stacks.

But…when I use the gui - I can select the stack and ask for Image->Stacks->Z Project and it works just fine.  It generates
an RGB Color image called “SUM_Stack”.

Recording this gives:


run("Z Project...", "projection=[Sum Slices]”);
selectWindow("Stack”);

I suppose I could use IJ.run("Z Project...", "projection=[Sum Slices]”);

But…I’m unsure how to (in java) refer to the “SUM_Stack” image (so that I can add it to the RGStack - with title “Red+Green”.

So - two part question:

a) is there a way to directly perform the Z Projection (in java)  to replicate the SUM_Stack I can generate in the interface?
b) failing that, if I use  IJ.run("Z Project...", "projection=[Sum Slices]”);   how do I get a handle on the resulting RGB image, so that I can add it
   to my 2-element stack (making it a 3-element stack: “red” image, “green” image, Summed image).

Either method will work for me.

[note that the ideal answer would edit my second code fragment above, so it gets the intended (is it obvious?) result.]

Thank you for your time.

As a last resort, I can write a routine to take my two RGB images and create a third projected image.  I’ve written that program about 20 times over the past 40 years - but I’m trying real hard to resist the urge to “just do it myself” and learn how to use the standard ImageJ tools.  My customer is taking the weekend to write a macro to do the projection (and possibly the insertion into the stack).  I’d like to get a fully automated version working first...

--
Kenneth Sloan
[hidden email] <mailto:[hidden email]>
Vision is the art of seeing what is invisible to others.





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

Re: ZProjector - can't process RGB stack?

Wayne Rasband-2
> On Jun 23, 2017, at 9:59 PM, Kenneth Sloan <[hidden email]> wrote:
>
> Context: Java plugin
>
> I’m currently building a stack containing two RGB images, like so:
>
>    ImageStack RGStack = greenIPlus.createEmptyStack();
>    RGStack.addSlice("Red",redIPlus.getProcessor());
>    RGStack.addSlice("Green",greenIPlus.getProcessor());
>    ImagePlus RGIPlus = new ImagePlus("Stack",RGStack);
>
> Here, “red” and “green” refer to the dominant color in each image, but both are RGB images.  I suppose I *could* make them single channel and
> color them, but I’d prefer “simple”.
>
> If it matters, once this RGStack is built, I’m applying a fairly complicated overlay, which should appear no matter what slice is viewed.  That
> all works now.  I’m just trying to enhance the stack by adding the Projection.
>
> I want to also include a z-projected version, combining the two images.  I tried this:
>
>    ZProjector zp = new ZProjector(RGIPlus);
>    zp.setStartSlice(1);
>    zp.setStopSlice(2);
>    zp.setMethod(zp.SUM_METHOD);
>    zp.doProjection();
>    ImagePlus projectionIPlus = zp.getProjection();;
>    RGStack.addSlice("Red+Green",projectionIPlus.getProcessor());
>
> But, zp.doProjection() complains that it can only handle non-RGB stacks.

The zp.doProjection(boolean) method in the latest daily build (1.51q1) works with RGB stacks, for example:

    img = IJ.openImage("http://wsr.imagej.net/images/flybrain.zip");
    zp = new ZProjector(img);
    zp.setMethod(ZProjector.AVG_METHOD);
    zp.doProjection(true);
    projection = zp.getProjection();
    projection.show();

-wayne


> But…when I use the gui - I can select the stack and ask for Image->Stacks->Z Project and it works just fine.  It generates
> an RGB Color image called “SUM_Stack”.
>
> Recording this gives:
>
>
> run("Z Project...", "projection=[Sum Slices]”);
> selectWindow("Stack”);
>
> I suppose I could use IJ.run("Z Project...", "projection=[Sum Slices]”);
>
> But…I’m unsure how to (in java) refer to the “SUM_Stack” image (so that I can add it to the RGStack - with title “Red+Green”.
>
> So - two part question:
>
> a) is there a way to directly perform the Z Projection (in java)  to replicate the SUM_Stack I can generate in the interface?
> b) failing that, if I use  IJ.run("Z Project...", "projection=[Sum Slices]”);   how do I get a handle on the resulting RGB image, so that I can add it
>   to my 2-element stack (making it a 3-element stack: “red” image, “green” image, Summed image).
>
> Either method will work for me.
>
> [note that the ideal answer would edit my second code fragment above, so it gets the intended (is it obvious?) result.]
>
> Thank you for your time.
>
> As a last resort, I can write a routine to take my two RGB images and create a third projected image.  I’ve written that program about 20 times over the past 40 years - but I’m trying real hard to resist the urge to “just do it myself” and learn how to use the standard ImageJ tools.  My customer is taking the weekend to write a macro to do the projection (and possibly the insertion into the stack).  I’d like to get a fully automated version working first...

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

Re: ZProjector - can't process RGB stack?

Kenneth Sloan-3
Thank you for the instant response!

Alas, no joy.

I downloaded the daily build (ImageJ 1.51q1), but doProjection still fails.

Briefly, I create a stack containing two RGB images.  I then attempt a ZProjection
to produce a composite image.  The ZProjection complains “Non-RGB Stack required”.

Here’s the current code (and a bit more, to create context):
 // read in the two .tif images                                                                      
    OpenDialog od;
    IJ.showStatus("Please select a GREEN .tif file”);
    od = new OpenDialog("Choose a GREEN .tif file:");
    greenTIF = od.getFileName();
    greenDir = od.getDirectory();

    greenIPlus = IJ.openImage(greenDir + greenTIF);
    greenIPlus.show();


    IJ.showStatus("Please select a RED .tif file");
    od = new OpenDialog("Choose a RED .tif file:");
    redTIF = od.getFileName();
    redDir = od.getDirectory();

    redIPlus = IJ.openImage(redDir + redTIF);
    redIPlus.show();

    ImageStack RGStack = greenIPlus.createEmptyStack();
    RGStack.addSlice("Red",redIPlus.getProcessor());
    RGStack.addSlice("Green",greenIPlus.getProcessor());
    ImagePlus RGIPlus = new ImagePlus("Stack",RGStack);
    RGIPlus.show();
    redIPlus.hide();
    greenIPlus.hide();

    ImageWindow iw =  RGIPlus.getWindow();
    IJ.log("iw = "+iw);
    iw.setLocationAndSize(0,200,900,700); // 225                                                        


    // produce SUM of Red + Green images                                                                
    ZProjector zp = new ZProjector(RGIPlus);
    zp.setStartSlice(1);
    zp.setStopSlice(2);
    zp.setMethod(zp.SUM_METHOD);
    IJ.log("calling doProjection");
    zp.doProjection();
    IJ.log("doProjection returns");

About ImageJ says I’m running ImageJ 1.51q1

The IJ LOG shows “calling doProjection”

A pop-up message says “Non-RGB Stack required [OK]”

here’s a screenshot (I’m not confident this works…)



--
Kenneth Sloan
[hidden email] <mailto:[hidden email]>
Vision is the art of seeing what is invisible to others.




> On Jun 24, 2017, at 00:18 , Wayne Rasband <[hidden email]> wrote:
>
>> On Jun 23, 2017, at 9:59 PM, Kenneth Sloan <[hidden email]> wrote:
>>
>> Context: Java plugin
>>
>> I’m currently building a stack containing two RGB images, like so:
>>
>>   ImageStack RGStack = greenIPlus.createEmptyStack();
>>   RGStack.addSlice("Red",redIPlus.getProcessor());
>>   RGStack.addSlice("Green",greenIPlus.getProcessor());
>>   ImagePlus RGIPlus = new ImagePlus("Stack",RGStack);
>>
>> Here, “red” and “green” refer to the dominant color in each image, but both are RGB images.  I suppose I *could* make them single channel and
>> color them, but I’d prefer “simple”.
>>
>> If it matters, once this RGStack is built, I’m applying a fairly complicated overlay, which should appear no matter what slice is viewed.  That
>> all works now.  I’m just trying to enhance the stack by adding the Projection.
>>
>> I want to also include a z-projected version, combining the two images.  I tried this:
>>
>>   ZProjector zp = new ZProjector(RGIPlus);
>>   zp.setStartSlice(1);
>>   zp.setStopSlice(2);
>>   zp.setMethod(zp.SUM_METHOD);
>>   zp.doProjection();
>>   ImagePlus projectionIPlus = zp.getProjection();;
>>   RGStack.addSlice("Red+Green",projectionIPlus.getProcessor());
>>
>> But, zp.doProjection() complains that it can only handle non-RGB stacks.
>
> The zp.doProjection(boolean) method in the latest daily build (1.51q1) works with RGB stacks, for example:
>
>    img = IJ.openImage("http://wsr.imagej.net/images/flybrain.zip <http://wsr.imagej.net/images/flybrain.zip>");
>    zp = new ZProjector(img);
>    zp.setMethod(ZProjector.AVG_METHOD);
>    zp.doProjection(true);
>    projection = zp.getProjection();
>    projection.show();
>
> -wayne
>
>
>> But…when I use the gui - I can select the stack and ask for Image->Stacks->Z Project and it works just fine.  It generates
>> an RGB Color image called “SUM_Stack”.
>>
>> Recording this gives:
>>
>>
>> run("Z Project...", "projection=[Sum Slices]”);
>> selectWindow("Stack”);
>>
>> I suppose I could use IJ.run("Z Project...", "projection=[Sum Slices]”);
>>
>> But…I’m unsure how to (in java) refer to the “SUM_Stack” image (so that I can add it to the RGStack - with title “Red+Green”.
>>
>> So - two part question:
>>
>> a) is there a way to directly perform the Z Projection (in java)  to replicate the SUM_Stack I can generate in the interface?
>> b) failing that, if I use  IJ.run("Z Project...", "projection=[Sum Slices]”);   how do I get a handle on the resulting RGB image, so that I can add it
>>  to my 2-element stack (making it a 3-element stack: “red” image, “green” image, Summed image).
>>
>> Either method will work for me.
>>
>> [note that the ideal answer would edit my second code fragment above, so it gets the intended (is it obvious?) result.]
>>
>> Thank you for your time.
>>
>> As a last resort, I can write a routine to take my two RGB images and create a third projected image. I’ve written that program about 20 times over the past 40 years - but I’m trying real hard to resist the urge to “just do it myself” and learn how to use the standard ImageJ tools.  My customer is taking the weekend to write a macro to do the projection (and possibly the insertion into the stack).  I’d like to get a fully automated version working first...
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html <http://imagej.nih.gov/ij/list.html>

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

Screen Shot 2017-06-24 at 6.57.07 .png (693K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ZProjector - can't process RGB stack?

Wayne Rasband-2
In reply to this post by Kenneth Sloan-3
> On Jun 23, 2017, Kenneth Sloan wrote:
>
> Context: Java plugin
>
> I’m currently building a stack containing two RGB images, like so:
>
>    ImageStack RGStack = greenIPlus.createEmptyStack();
>    RGStack.addSlice("Red",redIPlus.getProcessor());
>    RGStack.addSlice("Green",greenIPlus.getProcessor());
>    ImagePlus RGIPlus = new ImagePlus("Stack",RGStack);
>
> Here, “red” and “green” refer to the dominant color in each image, but both are RGB images.  I suppose I *could* make them single channel and
> color them, but I’d prefer “simple”.
>
> If it matters, once this RGStack is built, I’m applying a fairly complicated overlay, which should appear no matter what slice is viewed.  That
> all works now.  I’m just trying to enhance the stack by adding the Projection.
>
> I want to also include a z-projected version, combining the two images.  I tried this:
>
>    ZProjector zp = new ZProjector(RGIPlus);
>    zp.setStartSlice(1);
>    zp.setStopSlice(2);
>    zp.setMethod(zp.SUM_METHOD);
>    zp.doProjection();
>    ImagePlus projectionIPlus = zp.getProjection();;
>    RGStack.addSlice("Red+Green",projectionIPlus.getProcessor());
>
> But, zp.doProjection() complains that it can only handle non-RGB stacks.

The latest ImageJ daily build (1.51q3) adds a recordable ZProjector.run() method that works with RGB stacks and hyperstacks. The following JavaScript code demonstrates how to use it.

-wayne


  // T1 Head MRI dataset (16-bit)
  imp = IJ.openImage("http://wsr.imagej.net/images/t1-head.zip");
  imp2 = ZProjector.run(imp,"avg");
  imp2.show();
  imp3 = ZProjector.run(imp,"max",50,60);
  imp3.show();

  // Drosophila Brain (RGB)
  imp = IJ.openImage("http://wsr.imagej.net/images/flybrain.zip");
  imp = ZProjector.run(imp,"sd",10,40);
  imp.show();

  // Confocal Series (4D hyperstack)
  imp = IJ.openImage("http://wsr.imagej.net/images/confocal-series.zip");
  imp = ZProjector.run(imp,"sd");
  imp.show();

  // Mitosis (5D hyperstack)
  imp = IJ.openImage("http://wsr.imagej.net/images/Spindly-GFP.zip");
  imp2 = ZProjector.run(imp,"max all"); // all time frames
  imp2.show();
  imp.setPosition(1,1,33);
  imp2 = ZProjector.run(imp,"max"); // t=33
  imp2.show();


> But…when I use the gui - I can select the stack and ask for Image->Stacks->Z Project and it works just fine.  It generates
> an RGB Color image called “SUM_Stack”.
>
> Recording this gives:
>
>
> run("Z Project...", "projection=[Sum Slices]”);
> selectWindow("Stack”);
>
> I suppose I could use IJ.run("Z Project...", "projection=[Sum Slices]”);
>
> But…I’m unsure how to (in java) refer to the “SUM_Stack” image (so that I can add it to the RGStack - with title “Red+Green”.
>
> So - two part question:
>
> a) is there a way to directly perform the Z Projection (in java)  to replicate the SUM_Stack I can generate in the interface?
> b) failing that, if I use  IJ.run("Z Project...", "projection=[Sum Slices]”);   how do I get a handle on the resulting RGBimage, so that I can add it
>   to my 2-element stack (making it a 3-element stack: “red” image, “green” image, Summed image).
>
> Either method will work for me.
>
> [note that the ideal answer would edit my second code fragment above, so it gets the intended (is it obvious?) result.]
>
> Thank you for your time.
>
> As a last resort, I can write a routine to take my two RGB images and create a third projected image.  I’ve written that program about 20 times over the past 40 years - but I’m trying real hard to resist the urge to “just do it myself” and learn how to use the standard ImageJ tools.  My customer is taking the weekend to write a macro to do the projection (and possibly the insertion into the stack).  I’d like to get a fully automated version working first...
>
> --

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

Re: ZProjector - can't process RGB stack?

Kenneth Sloan-3
Thanks again to Wayne for instant response - he replied earlier with a quick fix.  This one looks even better.

--
Kenneth Sloan
[hidden email] <mailto:[hidden email]>
Vision is the art of seeing what is invisible to others.




> On Jun 28, 2017, at 09:20 , Wayne Rasband <[hidden email]> wrote:
>
>> On Jun 23, 2017, Kenneth Sloan wrote:
>>
>> Context: Java plugin
>>
>> I’m currently building a stack containing two RGB images, like so:
>>
>>   ImageStack RGStack = greenIPlus.createEmptyStack();
>>   RGStack.addSlice("Red",redIPlus.getProcessor());
>>   RGStack.addSlice("Green",greenIPlus.getProcessor());
>>   ImagePlus RGIPlus = new ImagePlus("Stack",RGStack);
>>
>> Here, “red” and “green” refer to the dominant color in each image, but both are RGB images.  I suppose I *could* make them single channel and
>> color them, but I’d prefer “simple”.
>>
>> If it matters, once this RGStack is built, I’m applying a fairly complicated overlay, which should appear no matter what slice is viewed.  That
>> all works now.  I’m just trying to enhance the stack by adding the Projection.
>>
>> I want to also include a z-projected version, combining the two images.  I tried this:
>>
>>   ZProjector zp = new ZProjector(RGIPlus);
>>   zp.setStartSlice(1);
>>   zp.setStopSlice(2);
>>   zp.setMethod(zp.SUM_METHOD);
>>   zp.doProjection();
>>   ImagePlus projectionIPlus = zp.getProjection();;
>>   RGStack.addSlice("Red+Green",projectionIPlus.getProcessor());
>>
>> But, zp.doProjection() complains that it can only handle non-RGB stacks.
>
> The latest ImageJ daily build (1.51q3) adds a recordable ZProjector.run() method that works with RGB stacks and hyperstacks. The following JavaScript code demonstrates how to use it.
>
> -wayne
>
>
>  // T1 Head MRI dataset (16-bit)
>  imp = IJ.openImage("http://wsr.imagej.net/images/t1-head.zip");
>  imp2 = ZProjector.run(imp,"avg");
>  imp2.show();
>  imp3 = ZProjector.run(imp,"max",50,60);
>  imp3.show();
>
>  // Drosophila Brain (RGB)
>  imp = IJ.openImage("http://wsr.imagej.net/images/flybrain.zip");
>  imp = ZProjector.run(imp,"sd",10,40);
>  imp.show();
>
>  // Confocal Series (4D hyperstack)
>  imp = IJ.openImage("http://wsr.imagej.net/images/confocal-series.zip");
>  imp = ZProjector.run(imp,"sd");
>  imp.show();
>
>  // Mitosis (5D hyperstack)
>  imp = IJ.openImage("http://wsr.imagej.net/images/Spindly-GFP.zip");
>  imp2 = ZProjector.run(imp,"max all"); // all time frames
>  imp2.show();
>  imp.setPosition(1,1,33);
>  imp2 = ZProjector.run(imp,"max"); // t=33
>  imp2.show();
>
>
>> But…when I use the gui - I can select the stack and ask for Image->Stacks->Z Project and it works just fine.  It generates
>> an RGB Color image called “SUM_Stack”.
>>
>> Recording this gives:
>>
>>
>> run("Z Project...", "projection=[Sum Slices]”);
>> selectWindow("Stack”);
>>
>> I suppose I could use IJ.run("Z Project...", "projection=[Sum Slices]”);
>>
>> But…I’m unsure how to (in java) refer to the “SUM_Stack” image (so that I can add it to the RGStack - with title “Red+Green”.
>>
>> So - two part question:
>>
>> a) is there a way to directly perform the Z Projection (in java)  to replicate the SUM_Stack I can generate in the interface?
>> b) failing that, if I use  IJ.run("Z Project...", "projection=[Sum Slices]”);   how do I get a handle on the resulting RGBimage, so that I can add it
>>  to my 2-element stack (making it a 3-element stack: “red” image, “green” image, Summed image).
>>
>> Either method will work for me.
>>
>> [note that the ideal answer would edit my second code fragment above, so it gets the intended (is it obvious?) result.]
>>
>> Thank you for your time.
>>
>> As a last resort, I can write a routine to take my two RGB images and create a third projected image.  I’ve written that program about 20 times over the past 40 years - but I’m trying real hard to resist the urge to “just do it myself” and learn how to use the standard ImageJ tools.  My customer is taking the weekend to write a macro to do the projection (and possibly the insertion into the stack).  I’d like to get a fully automated version working first...
>>
>> --
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html


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