Re: How to get one image from a stack?

Posted by Rasband, Wayne (NIH/NIMH) [E] on
URL: http://imagej.273.s1.nabble.com/How-to-get-one-image-from-a-stack-tp5001606p5001613.html

On Jan 30, 2013, at 12:04 PM, M.Gbarin wrote:

> Hallo everyone,
>
> I wrote a program to select a stack and to find an image, which I need.
> Now I want to work on this image only!
>
> has someone an idea how to get it in a separately??

Here is Java code that, on a duplicate of the active image, runs Median and Variance filters, converts to binary, and inverts the pixels of the second image in the stack.

  ImagePlus imp = IJ.getImage();
  ImagePlus bimp = imp.duplicate();
  bimp.setTitle("bimp");
  IJ.run(bimp, "Median...", "sigma=3 stack");
  IJ.run(bimp, "Variance...", "radius=3 stack");
  IJ.run(bimp, "Convert to Mask", "calculate black");
  ImageStack bstack = bimp.getStack();
  ImageProcessor ip = bstack.getProcessor(2);
  for (int i=0; i<ip.getPixelCount(); i++)
     ip.setf(i, 255-ip.getf(i));
  bimp.setStack(bstack);
  bimp.show();

-wayne

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