Login  Register

Re: ZProjector - can't process RGB stack?

Posted by Wayne Rasband-2 on Jun 28, 2017; 2:20pm
URL: http://imagej.273.s1.nabble.com/ZProjector-can-t-process-RGB-stack-tp5018958p5018986.html

> 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