Re: Issue about ImagePlus

Posted by Wayne Rasband-2 on
URL: http://imagej.273.s1.nabble.com/Issue-about-ImagePlus-tp5024349p5024353.html

> On Jan 10, 2021, at 2:12 PM, CARL Philippe (LBP) <[hidden email]> wrote:
>
> Dear all,
> Happy new year for everybody (hoping that it will be better than the last one)!
> Empirically I found an issue that I'm not really able to understand.

Hi Philippe,
The window is not closed in the second example because the ‘imp1’ variable points to a different ImagePlus, a non-displayed hyperstack version of the original image. It is the HyperStackConverter.toHyperStack() method that is static, not the ImagePlus it returns.

-waye

> So the following code is working as expected (i.e. the imp1 gets closed as expected):
> public class My_Plugin1 implements PlugIn {
> ImagePlus imp1, imp2, imp3;
> public void run(String arg) {
> imp1 = IJ.openImage("https://imagej.net/images/bat-cochlea-volume.zip");
> imp1.show();
> imp2 = HyperStackConverter.toHyperStack(imp1, 2, 3, 19, "default", "Grayscale");
> imp3 = SubHyperstackMaker.makeSubhyperstack(imp2, "1", "1-3", "1-19");
> imp3.show();
> imp1.close();
> imp2.close();
> }
> }
> But with the following code:
> public class My_Plugin2 implements PlugIn {
> ImagePlus imp1, imp3;
> public void run(String arg) {
> imp1 = IJ.openImage("https://imagej.net/images/bat-cochlea-volume.zip");
> imp1.show();
> imp1 = HyperStackConverter.toHyperStack(imp1, 2, 3, 19, "default", "Grayscale");
> imp3 = SubHyperstackMaker.makeSubhyperstack(imp1, "1", "1-3", "1-19");
> imp3.show();
> imp1.close();
> }
> }
> the imp1 window isn't closed.
> Is this because the HyperStackConverter.toHyperStack method is creating a static ImagePlus and not a ImagePlus?
> I thank you very much in advance for your lighting on this.
> My best regards,
> Philippe

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