Dear all,
I have programmed a simple code for the processing of some biological images. Without going into the specifics, the code splits channels, gets the green channel, runs convolution, makes binary and then analyses particles. So far so good. Then, it uses ROI manager, takes labels and changes color to magenta. The idea is to overlay the original image at the end. So, the "Add Image..." command is issued, the resulting image is flattened and saved as tif. My problem is the run("Add Image...","image="+original) command, or, better said, where I execute it. If I open a new macro window in ImageJ (ImageJ->Plugins->Macros->New->Macro), write down the code and execute it from that window (Macros->Run macro), it works just fine. ... run("Analyze Particles...", "size=0-500 pixel circularity=0-1 show=Nothing add"); roiManager("Show all without labels"); run("Colors...","selection=magenta"); open(<sourcePath>); original=getTitle(); print(">>>> "+original); selectImage(4); //1, 2 and 3 correspond to the channels... roi=getTitle(); print(">>>> "+roi); run("Add Image...","image="+original); run("Flatten"); saveAs("Tiff",<destinyPath>+roi); Now, if I write the macro in a text editor and do ImageJ->Plugins->Macros->Run the command run("Add Image...","image="+original) does not work. If I comment it, and save to file the original and the roi (flattened) images, everything is good, but this command doe snot work and I can get the original image to be added to the roi image. How can this be possible? My machine is a Windows 8.1 64-bit and I am using ImageJ 1.49n. Probably (more than likely), I am missing some specifics of ImageJ macro programming, but I go over it again, and again, and don't see it (as it usually happens). Please could someone help me? Many thanks in advance, Anália |
Dear Anália,
Any change you have spaces in the image name? If so you need: run("Add Image...","image="+[original]); Kees Dr Ir K.R. Straatman Senior Experimental Officer Advanced Imaging Facility Centre for Core Biotechnology Services University of Leicester http://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/lite/aif -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of analia Sent: 06 February 2015 10:48 To: [hidden email] Subject: Weird macro behaviour Dear all, I have programmed a simple code for the processing of some biological images. Without going into the specifics, the code splits channels, gets the green channel, runs convolution, makes binary and then analyses particles. So far so good. Then, it uses ROI manager, takes labels and changes color to magenta. The idea is to overlay the original image at the end. So, the "Add Image..." command is issued, the resulting image is flattened and saved as tif. My problem is the run("Add Image...","image="+original) command, or, better said, where I execute it. If I open a new macro window in ImageJ (ImageJ->Plugins->Macros->New->Macro), write down the code and execute it from that window (Macros->Run macro), it works just fine. ... run("Analyze Particles...", "size=0-500 pixel circularity=0-1 show=Nothing add"); roiManager("Show all without labels"); run("Colors...","selection=magenta"); open(<sourcePath>); original=getTitle(); print(">>>> "+original); selectImage(4); //1, 2 and 3 correspond to the channels... roi=getTitle(); print(">>>> "+roi); run("Add Image...","image="+original); run("Flatten"); saveAs("Tiff",<destinyPath>+roi); Now, if I write the macro in a text editor and do ImageJ->Plugins->Macros->Run the command run("Add Image...","image="+original) does not work. If I comment it, and save to file the original and the roi (flattened) images, everything is good, but this command doe snot work and I can get the original image to be added to the roi image. How can this be possible? My machine is a Windows 8.1 64-bit and I am using ImageJ 1.49n. Probably (more than likely), I am missing some specifics of ImageJ macro programming, but I go over it again, and again, and don't see it (as it usually happens). Please could someone help me? Many thanks in advance, Anália -- View this message in context: http://imagej.1557.x6.nabble.com/Weird-macro-behaviour-tp5011475.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 |
Dear Kees,
the name of the image has no spaces. Moreover, the command run("Add Image...","image="+[original]) gives me an error in "[" If I re-write to run("Add Image...","image=[original]"); I obtain the previous behaviour. That is, instead of adding the original image to the ROI, it gives me the original image. I just don't understand what is so different in running the macro from the macro editor or running it from outside... it is exactly the same code. Thanks, Anália |
On Friday 06 Feb 2015 06:43:59 you wrote:
> Dear Kees, > > the name of the image has no spaces. > Moreover, the command run("Add Image...","image="+[original]) gives me an > error in "[" > > If I re-write to run("Add Image...","image=[original]"); I obtain the > previous behaviour. That is, instead of adding the original image to the > ROI, it gives me the original image. Perhaps you need to do: run("Add Image...","image=["+original+"]"); or: run("Add Image...","image=[&original]"); I have not tried this last one, it might not work. Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Gabriel,
unfortunately neither options worked :-( I have created a small test macro to help you reproduce my problem, along with some data. 51_FA_65_5.tif (green)-1 is the input image and 51_FA_65_5.tif is the original image. The image 51_FA_65_5.tif (green)-1 results from previous processing of 51_FA_65_5.tif, so that I could simplify the code and focus on the issue. Now, if I open the 51_FA_65_5.tif (green)-1 in ImageJ and write down the code in the macro editor (ImageJ->Plugins->New) and run it from that window (Macros->Run Macro) I get the roi.tif (as supposed to). If I try to run the macro ImageJ->Plugins->Macros->Run, I don't get any error but the roi.tif is not created. And if I comment the Add Image command I do get the file created (although not with the desired contents, of course). Thanks, Anália |
Dear Anália,
I don't seem to be able to reproduce your problem. It does not matter if I run your macro via the editor or via Macros > Run or Macros > Install, the result is a saved merged file. The only thing I changed in your macro is the path the files are stored and saved to. Kees -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of analia Sent: 06 February 2015 16:03 To: [hidden email] Subject: Re: Weird macro behaviour Dear Gabriel, unfortunately neither options worked :-( I have created a small test macro <https://drive.google.com/file/d/0B3yFlb9_8aVZQ1JQZmI0NXBqdG8/view?usp=sharing> to help you reproduce my problem, along with some data. 51_FA_65_5.tif (green)-1 is the input image and 51_FA_65_5.tif is the original image. The image 51_FA_65_5.tif (green)-1 results from previous processing of 51_FA_65_5.tif, so that I could simplify the code and focus on the issue. Now, if I open the 51_FA_65_5.tif (green)-1 in ImageJ and write down the code in the macro editor (ImageJ->Plugins->New) and run it from that window (Macros->Run Macro) I get the roi.tif (as supposed to). If I try to run the macro ImageJ->Plugins->Macros->Run, I don't get any error but the roi.tif is not created. And if I comment the Add Image command I do get the file created (although not with the desired contents, of course). Thanks, Anália -- View this message in context: http://imagej.1557.x6.nabble.com/Weird-macro-behaviour-tp5011475p5011486.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 |
Dear Kees,
so that we are clear: you get the roi.tif image (as shown in the sample data) in both execution approaches. Is this correct? Because what I get if I do Macros > Install or Macro > Run is the original imageas result of the overlay, it is like the roi image gets replaced rather than overlayed. I have tried countless variations of the procedure, changed directories (to prevent any issues with spaces and encoding characters)... and, as I told you before, when I comment the Add Image... command, I do get the "simple" <a href="http://<a href="https://drive.google.com/file/d/0B3yFlb9_8aVZamEzQ0NBR2RNWVE/view?usp=sharing">">roi image saved correctly. It seems like there is some sort of bug/issue with this command. I really don't know what else to do :-( Could it be an issue with my OS (Windows 8.1 64 bits), ImageJ version (1.49n) or Java version (1.8.0_25)? If you which I can prepare a step by step documentation (snapshots) of me running the macro... Many thanks, Anália |
Dear Anália,
That is correct. I get in all cases the merged image, both using ImageJ (ImageJ 1.49o, Java 1.7.0_71 (32-bit), Windows 7) or Fiji (ImageJ 1.49m, Java 1.6.0_24 (64-bit), Windows 7) running the code: macro test{ //open("51_FA_65_5.tif (green)-1.tif"); open("Z:\\tmp\\smalltest\\51_FA_65_5.tif (green)-1.tif"); title=getTitle(); run("Analyze Particles...", "size=0-500 circularity=0-1 show=Nothing add"); // size and circularity parameters roiManager("Show all without labels"); run("Colors...","selection=magenta"); //open("51_FA_65_5.tif"); open("Z:\\tmp\\smalltest\\51_FA_65_5.tif"); original=getTitle(); print(">>>>O: "+original); //saveAs("Tiff",out+"/"+original); selectImage(1); roi=getTitle(); print(">>>>R: "+roi); run("Add Image...","image="+original); run("Flatten"); saveAs("Tiff","Z:\\tmp\\smalltest\\roi_Run.tif"); run("Close"); run("Clear Results"); close(); } As far as I can see that is your original code. Can you try a different computer and see if it solves the problem? I would not expect a change to Windows 8 causing this.. Kees -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of analia Sent: 06 February 2015 19:38 To: [hidden email] Subject: Re: Weird macro behaviour Dear Kees, so that we are clear: you get the roi.tif <https://drive.google.com/file/d/0B3yFlb9_8aVZcWlMMU9YMU1CRHM/view?usp=sharing> image (as shown in the sample data) in both execution approaches. Is this correct? Because what I get if I do Macros > Install or Macro > Run is the original image <https://drive.google.com/file/d/0B3yFlb9_8aVZMGJKTnpmMlN3aTA/view?usp=sharing> as result of the overlay, it is like the roi image gets replaced rather than overlayed. I have tried countless variations of the procedure, changed directories (to prevent any issues with spaces and encoding characters)... and, as I told you before, when I comment the Add Image... command, I do get the "simple" <a href="http://<a href="https://drive.google.com/file/d/0B3yFlb9_8aVZamEzQ0NBR2RNWVE/view?usp=sharing">">roi image saved correctly. It seems like there is some sort of bug/issue with this command. I really don't know what else to do :-( Could it be an issue with my OS (Windows 8.1 64 bits), ImageJ version (1.49n) or Java version (1.8.0_25)? If you which I can prepare a step by step documentation (snapshots) of me running the macro... Many thanks, Anália -- View this message in context: http://imagej.1557.x6.nabble.com/Weird-macro-behaviour-tp5011475p5011494.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 Overview_Fiji.jpg (57K) Download Attachment |
On Feb 9, 2015, at 5:43 AM, Straatman, Kees (Dr.) <[hidden email]> wrote:
> > Dear Anália, > > That is correct. I get in all cases the merged image, both using ImageJ (ImageJ 1.49o, Java 1.7.0_71 (32-bit), Windows 7) or Fiji (ImageJ 1.49m, Java 1.6.0_24 (64-bit), Windows 7) running the code: This is probably a race condition that you can work around by adding run("From ROI Manager”); just before run("Flatten”); The Image>Overlay>From ROI Manager command adds the ROI Manager’s "Show all without labels” overlay to the end of the standard overlay. -wayne > macro test{ > //open("51_FA_65_5.tif (green)-1.tif"); > > open("Z:\\tmp\\smalltest\\51_FA_65_5.tif (green)-1.tif"); > title=getTitle(); > > run("Analyze Particles...", "size=0-500 circularity=0-1 show=Nothing add"); // size and circularity parameters > > roiManager("Show all without labels"); > run("Colors...","selection=magenta"); > > //open("51_FA_65_5.tif"); > open("Z:\\tmp\\smalltest\\51_FA_65_5.tif"); > original=getTitle(); > print(">>>>O: "+original); > > //saveAs("Tiff",out+"/"+original); > > selectImage(1); > roi=getTitle(); > print(">>>>R: "+roi); > > run("Add Image...","image="+original); > run("Flatten"); > > saveAs("Tiff","Z:\\tmp\\smalltest\\roi_Run.tif"); > > run("Close"); > run("Clear Results"); > > close(); > > > } > > As far as I can see that is your original code. > > Can you try a different computer and see if it solves the problem? I would not expect a change to Windows 8 causing this.. > > Kees > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of analia > Sent: 06 February 2015 19:38 > To: [hidden email] > Subject: Re: Weird macro behaviour > > Dear Kees, > > so that we are clear: you get the roi.tif <https://drive.google.com/file/d/0B3yFlb9_8aVZcWlMMU9YMU1CRHM/view?usp=sharing> > image (as shown in the sample data) in both execution approaches. Is this correct? > > Because what I get if I do Macros > Install or Macro > Run is the original image <https://drive.google.com/file/d/0B3yFlb9_8aVZMGJKTnpmMlN3aTA/view?usp=sharing> > as result of the overlay, it is like the roi image gets replaced rather than overlayed. > > I have tried countless variations of the procedure, changed directories (to prevent any issues with spaces and encoding characters)... and, as I told you before, when I comment the Add Image... command, I do get the "simple" > <a href="http://<a > href="https://drive.google.com/file/d/0B3yFlb9_8aVZamEzQ0NBR2RNWVE/view?usp=sharing">">roi > image saved correctly. > It seems like there is some sort of bug/issue with this command. I really don't know what else to do :-( > > Could it be an issue with my OS (Windows 8.1 64 bits), ImageJ version > (1.49n) or Java version (1.8.0_25)? > If you which I can prepare a step by step documentation (snapshots) of me running the macro... > > Many thanks, > Anália > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Weird-macro-behaviour-tp5011475p5011494.html > Sent from the ImageJ mailing list archive at Nabble.com. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear all,
I have tried out different versions of ImageJ (including the one with bundled java) and Java, and my code kept the same behaviour, i.e. I could never get the desired output. I followed Wayne's recommendation and added the command run("From ROI manager") before the run("Flatten"). By doing so, my macro works OK. Apparently, some of you can skip this step, but I cannot. In the next days, I will be running tests in other computers to be sure that the code is stable. Many thanks for all the help, Anália |
Free forum by Nabble | Edit this page |