This post was updated on .
Hi all,
Simple problem that probably has a simple fix. Any help would be appreciated-- During the course of my image analysis I have the image I opened (A1 DAPI.jpg, for example), the same image converted to mask (A1 DAPI-1.jpg), and then the same image reverted with maxima stuck onto it (A1 DAPI-1.jpg Maxima). There comes a critical point where I need to have ImageJ (well, Fiji) close all but the Maxima image. How do I do this? Is there a closeAllButActive function that I am not aware of? I've looked high and low but haven't found much. Failing that, is there a way to tell the macro to close any/all images that don't have the word "Maxima" in the image title? I would rather not close any open ROI or Results windows if I can help it. Thanks, IJ wizards. |
Here is a macro that closes all images apart from the image that is
currently at the front/active. There may be a more elegant way of doing this, but it works for me. Hope this helps, Volko currentImageID=getImageID(); //get image ID for current image totalOpenImages=nImages; //get total number of open images imageIDs=newArray(nImages); //create array to hold all image IDs for(i=0;i<nImages;i++){ //and populate array with image IDs selectImage(i+1); imageIDs[i]=getImageID(); }; for(i=0;i<totalOpenImages;i++){ //run through array of image IDs if(imageIDs[i]!=currentImageID){ //and check whether it matches current image selectImage(imageIDs[i]); //if it doesn't match, select image and close it close(); }; }; On 14/08/2015 02:19, jswalker wrote: > Hi all, > > Simple problem that probably has a simple fix. Any help would be > appreciated-- > > During the course of my image analysis I have the image I opened (A1 > DAPI.jpg, for example), the same image converted to mask (A1 DAPI-1.jpg), > and then the same image reverted with maxima stuck onto it (A1 DAPI-1.jpg > Maxima). > > There comes a critical point where I need to have ImageJ (well, Fiji) close > all but the Maxima image. How do I do this? > > Is there a closeAllButActive function that I am not aware of? > Failing that, is there a way to tell the macro to close any/all images that > /don't/ have the word "Maxima" in the image title? > > I would rather not close any open ROI or Results windows if I can help it. > > Thanks, IJ wizards. > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Close-all-but-active-window-tp5014024.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by jswalker
I just realised that there is a much simpler way to close all image
windows apart from the front image - just use close("\\Others") See Macro documentation (http://imagej.nih.gov/ij/developer/macro/functions.html#C). Volko On 14/08/2015 02:19, jswalker wrote: > Hi all, > > Simple problem that probably has a simple fix. Any help would be > appreciated-- > > During the course of my image analysis I have the image I opened (A1 > DAPI.jpg, for example), the same image converted to mask (A1 DAPI-1.jpg), > and then the same image reverted with maxima stuck onto it (A1 DAPI-1.jpg > Maxima). > > There comes a critical point where I need to have ImageJ (well, Fiji) close > all but the Maxima image. How do I do this? > > Is there a closeAllButActive function that I am not aware of? > Failing that, is there a way to tell the macro to close any/all images that > /don't/ have the word "Maxima" in the image title? > > I would rather not close any open ROI or Results windows if I can help it. > > Thanks, IJ wizards. > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Close-all-but-active-window-tp5014024.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by jswalker
Hi,
Use selectImage(image of interest): close("\\Others"); Best Oli On 14 Aug 2015 6:51 am, Volko Straub <[hidden email]> wrote: Here is a macro that closes all images apart from the image that is currently at the front/active. There may be a more elegant way of doing this, but it works for me. Hope this helps, Volko currentImageID=getImageID(); //get image ID for current image totalOpenImages=nImages; //get total number of open images imageIDs=newArray(nImages); //create array to hold all image IDs for(i=0;i<nImages;i++){ //and populate array with image IDs selectImage(i+1); imageIDs[i]=getImageID(); }; for(i=0;i<totalOpenImages;i++){ //run through array of image IDs if(imageIDs[i]!=currentImageID){ //and check whether it matches current image selectImage(imageIDs[i]); //if it doesn't match, select image and close it close(); }; }; On 14/08/2015 02:19, jswalker wrote: > Hi all, > > Simple problem that probably has a simple fix. Any help would be > appreciated-- > > During the course of my image analysis I have the image I opened (A1 > DAPI.jpg, for example), the same image converted to mask (A1 DAPI-1.jpg), > and then the same image reverted with maxima stuck onto it (A1 DAPI-1.jpg > Maxima). > > There comes a critical point where I need to have ImageJ (well, Fiji) close > all but the Maxima image. How do I do this? > > Is there a closeAllButActive function that I am not aware of? > Failing that, is there a way to tell the macro to close any/all images that > /don't/ have the word "Maxima" in the image title? > > I would rather not close any open ROI or Results windows if I can help it. > > Thanks, IJ wizards. > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Close-all-but-active-window-tp5014024.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Is it possible to do this from the gui as well, not in a macro? Often that would be useful too.
Thanks, Michael > On 14 באוג׳ 2015, at 05:06, Burri Olivier <[hidden email]> wrote: > > Hi, > > Use > selectImage(image of interest): > close("\\Others"); > > Best > > Oli > > On 14 Aug 2015 6:51 am, Volko Straub <[hidden email]> wrote: > Here is a macro that closes all images apart from the image that is > currently at the front/active. There may be a more elegant way of doing > this, but it works for me. > Hope this helps, > Volko > > currentImageID=getImageID(); //get image ID for current image > totalOpenImages=nImages; //get total number of open images > imageIDs=newArray(nImages); //create array to hold all image IDs > for(i=0;i<nImages;i++){ //and populate array with > image IDs > selectImage(i+1); > imageIDs[i]=getImageID(); > }; > > for(i=0;i<totalOpenImages;i++){ //run through array of image IDs > if(imageIDs[i]!=currentImageID){ //and check whether it matches > current image > selectImage(imageIDs[i]); //if it doesn't match, > select image and close it > close(); > }; > }; > >> On 14/08/2015 02:19, jswalker wrote: >> Hi all, >> >> Simple problem that probably has a simple fix. Any help would be >> appreciated-- >> >> During the course of my image analysis I have the image I opened (A1 >> DAPI.jpg, for example), the same image converted to mask (A1 DAPI-1.jpg), >> and then the same image reverted with maxima stuck onto it (A1 DAPI-1.jpg >> Maxima). >> >> There comes a critical point where I need to have ImageJ (well, Fiji) close >> all but the Maxima image. How do I do this? >> >> Is there a closeAllButActive function that I am not aware of? >> Failing that, is there a way to tell the macro to close any/all images that >> /don't/ have the word "Maxima" in the image title? >> >> I would rather not close any open ROI or Results windows if I can help it. >> >> Thanks, IJ wizards. >> >> >> >> -- >> View this message in context: http://imagej.1557.x6.nabble.com/Close-all-but-active-window-tp5014024.html >> Sent from the ImageJ mailing list archive at Nabble.com. >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
> On Aug 14, 2015, at 11:04 AM, Michael Elbaum <[hidden email]> wrote:
> > Is it possible to do this from the gui as well, not in a macro? Often that would be useful too. You can create a menu command that runs a macro by saving the macro in the plugins folder, or an immediate sub-folder, using a file name that contains at least one underscore or ends in “.ijm”. To create a “Close Others” command, save a file that contains the line close("\\Others”); in the plugins folder as “Close_Others.ijm” and run the Help>Refresh Menus command. Use the Plugins>Shortcuts>Add Shortcut (previously “Create Shortcut”) command to create a keyboard shortcut for the new command. -wayne > On 14 באוג׳ 2015, at 05:06, Burri Olivier <[hidden email]> wrote: >> >> Hi, >> >> Use >> selectImage(image of interest): >> close("\\Others"); >> >> Best >> >> Oli >> >> On 14 Aug 2015 6:51 am, Volko Straub <[hidden email]> wrote: >> Here is a macro that closes all images apart from the image that is >> currently at the front/active. There may be a more elegant way of doing >> this, but it works for me. >> Hope this helps, >> Volko >> >> currentImageID=getImageID(); //get image ID for current image >> totalOpenImages=nImages; //get total number of open images >> imageIDs=newArray(nImages); //create array to hold all image IDs >> for(i=0;i<nImages;i++){ //and populate array with >> image IDs >> selectImage(i+1); >> imageIDs[i]=getImageID(); >> }; >> >> for(i=0;i<totalOpenImages;i++){ //run through array of image IDs >> if(imageIDs[i]!=currentImageID){ //and check whether it matches >> current image >> selectImage(imageIDs[i]); //if it doesn't match, >> select image and close it >> close(); >> }; >> }; >> >>> On 14/08/2015 02:19, jswalker wrote: >>> Hi all, >>> >>> Simple problem that probably has a simple fix. Any help would be >>> appreciated-- >>> >>> During the course of my image analysis I have the image I opened (A1 >>> DAPI.jpg, for example), the same image converted to mask (A1 DAPI-1.jpg), >>> and then the same image reverted with maxima stuck onto it (A1 DAPI-1.jpg >>> Maxima). >>> >>> There comes a critical point where I need to have ImageJ (well, Fiji) close >>> all but the Maxima image. How do I do this? >>> >>> Is there a closeAllButActive function that I am not aware of? >>> Failing that, is there a way to tell the macro to close any/all images that >>> /don't/ have the word "Maxima" in the image title? >>> >>> I would rather not close any open ROI or Results windows if I can help it. >>> >>> Thanks, IJ wizards. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Straub, Volko A. (Dr.)
Hi,
You have proposed for closing all image windows apart from the front image, it's better to use close("\\Others"). This command works well on marco recorder or... but can't use this command in script. I mean I have tried many ways such as (IJ.close("\\Others") , IJ.run("close\\Others") and so on...). But none of them works. Could you please help me how I can use close("\\Others") as an micromanager script? Thank you in advance, Haleh |
Hi Haleh,
as far as I know, the close("\\Others") is only available in macro mode. You can find the source code for the macro function here: https://github.com/imagej/imagej1/blob/master/ij/macro/Functions.java#L2910 So, you can either try IJ.runMacro("close(\"\\Others\");"); <I did not try whether I've got the syntax with all the quotes etc. right> or alternatively, you can replicate the loop for closing all images from the source code I've mentioned above. Michael ________________________________________________________________ On 2016-11-09 15:08, Haleh wrote: > Hi, > > You have proposed for closing all image windows apart from the front image, > it's better to use > close("\\Others"). This command works well on marco recorder or... but can't > use this command in script. I mean I have tried many ways such as > (IJ.close("\\Others") , IJ.run("close\\Others") and so on...). But none of > them works. > Could you please help me how I can use close("\\Others") as an micromanager > script? > > Thank you in advance, > Haleh > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Michael,
Thanks a lot for your prompt response and help. I just tried your command to run macro from script ( IJ.runMacro("close(\"\\Others\");"); ). It seems working well as It doesn't give any error. But at the end I noticed that It does not close other windows. In fact, it seems that program is running without considering this command. Regards, Haleh |
Hi Haleth,
oops, sorry, I see, it's a matter of backslashes. The Javascript (or java) code should be IJ.runMacro("print(\"work\");close(\"\\\\Others\");print(\"done\");"); The Javascript interpreter (or Java compiler) converts the quadruple backslashes to double, the macro interpreter double to single. At the end of all conversions, a single backslash is required. Michael ________________________________________________________________ On 2016-11-10 11:48, Haleh wrote: > Hi Michael, > > Thanks a lot for your prompt response and help. > I just tried your command to run macro from script ( > IJ.runMacro("close(\"\\Others\");"); ). It seems working well as It doesn't > give any error. But at the end I noticed that It does not close other > windows. In fact, it seems that program is running without considering this > command. > > > Regards, > > Haleh > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Close-all-but-active-window-tp5014024p5017556.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Michael, Sorry for responding late. I just checked Javascript with your command, it works quite well :). Thanks a lot. This saves me a lot of time.Thanks again for your explanation of backslashes. It was worth to learn it. One question, are we able to choose two window (two Images) by using selectwindow (). I would like to keep two or three.. window open (Among several images) in order to do process on them and close others. like: IJ.selectWindow("Stack1.tif"); IJ.selectWindow("Stack2.tif"); IJ.runMacro("print(\"work\");close(\"\\\\Others\");print(\"done\");"); As you know selectWindow() just considers last window then close all. Is there any way to select more than one window ? Thank you in advance, Haleh De: "Michael Schmid-3 [via ImageJ]" <[hidden email]> À: "Haleh" <[hidden email]> Envoyé: Jeudi 10 Novembre 2016 22:13:33 Objet: Re: Close all but active window Hi Haleth, oops, sorry, I see, it's a matter of backslashes. The Javascript (or java) code should be IJ.runMacro("print(\"work\");close(\"\\\\Others\");print(\"done\");"); The Javascript interpreter (or Java compiler) converts the quadruple backslashes to double, the macro interpreter double to single. At the end of all conversions, a single backslash is required. Michael ________________________________________________________________ On 2016-11-10 11:48, Haleh wrote: > Hi Michael, > > Thanks a lot for your prompt response and help. > I just tried your command to run macro from script ( > IJ.runMacro("close(\"\\Others\");"); ). It seems working well as It doesn't > give any error. But at the end I noticed that It does not close other > windows. In fact, it seems that program is running without considering this > command. > > > Regards, > > Haleh > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Close-all-but-active-window-tp5014024p5017556.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > ImageJ mailing list: http://imagej.nih.gov/ij/list.html If you reply to this email, your message will be added to the discussion below: http://imagej.1557.x6.nabble.com/Close-all-but-active-window-tp5014024p5017567.html |
Hi Haleh,
sorry, you can have only one window selected at a time. If you need to keep more than one image, you have to create a loop over all images. Here is a rough Javascript example. It only cares about visible images, not about images created in BatchMode or images not shown for other reasons. allIDs = WindowManager.getIDList(); if (allIDs==null) exit(); // return; for (i = 0; i<allIDs.length; i++) { imp = WindowManager.getImage(allIDs[i]); title = imp.getTitle(); if (title != "Stack1.tif" && title != "Stack1.tif") { win = imp.getWindow(); if (win != null) { imp.changes = false; win.close(); } } } Michael ________________________________________________________________ On 2016-11-14 17:51, Haleh wrote: > Hi Michael, > > Sorry for responding late. I just checked Javascript with your > command, it works quite well :). Thanks a lot. This saves me a lot of > time. Thanks again for your explanation of backslashes. It was worth > to learn it. One question, are we able to choose two window (two > Images) by using selectwindow (). I would like to keep two or three.. > window open (Among several images) in order to do process on them and > close others. like: > > IJ.selectWindow("Stack1.tif"); IJ.selectWindow("Stack2.tif"); > IJ.runMacro("print(\"work\");close(\"\\\\Others\");print(\"done\");"); > > > As you know selectWindow() just considers last window then close all. > Is there any way to select more than one window ? > > Thank you in advance, Haleh -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Haley,
Maybe you can create one stack from Stack1.tif and Stack2.tif, close all other images and split the stack back into the 2 individual stacks. Kees -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid Sent: 14 November 2016 17:51 To: [hidden email] Subject: Re: Close all but active window Hi Haleh, sorry, you can have only one window selected at a time. If you need to keep more than one image, you have to create a loop over all images. Here is a rough Javascript example. It only cares about visible images, not about images created in BatchMode or images not shown for other reasons. allIDs = WindowManager.getIDList(); if (allIDs==null) exit(); // return; for (i = 0; i<allIDs.length; i++) { imp = WindowManager.getImage(allIDs[i]); title = imp.getTitle(); if (title != "Stack1.tif" && title != "Stack1.tif") { win = imp.getWindow(); if (win != null) { imp.changes = false; win.close(); } } } Michael ________________________________________________________________ On 2016-11-14 17:51, Haleh wrote: > Hi Michael, > > Sorry for responding late. I just checked Javascript with your > command, it works quite well :). Thanks a lot. This saves me a lot of > time. Thanks again for your explanation of backslashes. It was worth > to learn it. One question, are we able to choose two window (two > Images) by using selectwindow (). I would like to keep two or three.. > window open (Among several images) in order to do process on them and > close others. like: > > IJ.selectWindow("Stack1.tif"); IJ.selectWindow("Stack2.tif"); > IJ.runMacro("print(\"work\");close(\"\\\\Others\");print(\"done\");"); > > > As you know selectWindow() just considers last window then close all. > Is there any way to select more than one window ? > > Thank you in advance, Haleh -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Michael Schmid
Hi,
Thank you Micheal. I tried your commands. Unfortunately I got an error: (There are no images open). As my images are visible it might be problem in getting ID of desired images. Don't know !!! Haleh |
In reply to this post by Krs5
Hi Kees,
Thank for your help. But In my case I can't stack them, Close others and then split them. Thanks a lot. Haleh |
In reply to this post by Haleh
Hi Haleh,
sorry, there was a typo in the check for 'Stack1.tif' and 'Stack2.tif' (I wrote 'Stack1.tif' twice), otherwise it works for me. Here is a full JavaScript example: imp=IJ.createImage("Stack1.tif", "8-bit white", 128, 128, 2); imp.show(); imp=IJ.createImage("closeMe1", "8-bit white", 128, 128, 2); imp.show(); imp=IJ.createImage("closeMe2", "8-bit white", 128, 128, 1); imp.show(); imp=IJ.createImage("Stack2.tif", "8-bit white", 256, 256, 3); imp.show(); IJ.wait(1000); //allows the user to see what we have closeAllButStack12(); // Closes all visible images except for 'Stack1.tif' and 'Stack2.tif' // function closeAllButStack12() { allIDs = WindowManager.getIDList(); if (allIDs==null) return; // if null, there are no open images for (i = 0; i<allIDs.length; i++) { imp = WindowManager.getImage(allIDs[i]); title = imp.getTitle(); if (title != "Stack1.tif" && title != "Stack2.tif") { win = imp.getWindow(); if (win != null) { imp.changes = false; win.close(); } } } } Michael ________________________________________________________________ On 2016-11-18 12:03, Haleh wrote: > Hi, > > Thank you Micheal. > > I tried your commands. Unfortunately I got an error: (There are no images > open). As my images are visible it might be problem in getting ID of desired > images. Don't know !!! > > Haleh > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Close-all-but-active-window-tp5014024p5017594.html > Sent from the ImageJ mailing list archive at Nabble.com. > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |