Problem writing a line in Macro

Hello,

I am trying to get this macro to work in FIJI.

run("Enhance Contrast...", "saturated=0.4");
run("Sharpen");
imageTitle=getTitle(); 
rename(""+imageTitle+"_red.tif");
run("Threshold...");
waitForUser;
run("Convert to Mask");
run("Remove Outliers...", "radius=0.8 threshold=50 which=Bright");
run("Analyze Particles...", "size=40-Infinity display summarize");
run("Skeletonize (2D/3D)"); 
run("Analyze Skeleton (2D/3D)", "prune=[lowest intensity voxel]);
selectWindow(""+imageTitle+"_red.tif"); 
run("Strahler Analysis", "max.=20 infer ignore method=[lowest intensity voxel] 8- bit=[Tagged skeleton] display_iteration show");

When I run it, I receive the message shown in the image below. How can I fix this?

Thank you,

Vanessa

Vanessa,

quite often if you see this error message, the problem is in the line before.

run(“Analyze Skeleton (2D/3D)”, "prune=[lowest intensity voxel]);

I guess an inverted comma is missing – no?

HTH

Herbie

1 Like

The script editor provides syntax highlighting which makes spotting this kind of errors easier. Look at the different color in line 11 to find the problem as pointed out by @anon96376101.


When posting here on the forum, you can use the markdown syntax: include your code between triplets of backticks (```) to format code with syntax highlighting. I edited your post above to show this.

2 Likes

Hello @imagejan and @anon96376101,
Thank you for your response! The problem still persists even after removing the opened inverted comma or adding an inverted comma

Vanessa,

sorry I can’t help you further because I don’t use Fiji and don’t have the various plugins installed in ImageJ.

When I run your macro, it stops at line 10 because I don’t have “Skeletonize (2D/3D)” installed.

I’m sure you will find the problem by carefully checking the syntax of your macro, especially the spelling of plugin names. (Is this “max.=20” correct?)

Best

Herbie

Vanessa,

you may also try:

imageTitle = getTitle() + “_red.tif”;
rename( imageTitle );

selectImage( imageTitle );

Best

Herbie

Herbie,

The line that says max.=20 i retrieved from running the macro recording while setting the running the plugin, so i believe it is correct. I also tried the suggestions your made below and unfortunately the macro still does not seem to be working. Thank you for all your suggestions!

Kind regards,

Vanessa

Hi Vanessa,

Can you give more detail on how exactly it is not working?

When I try to run the macro with @anon96376101 's suggestions, with the latest Fiji/Java8/BAR updates, there is no more syntax error, but instead I get an exception:

javax.script.ScriptException: Sourced file: eval stream : Undefined argument: roi : at Line: 429 : in file: eval stream : ( pruneChoice , true , false , origImp , true , false , roi ) in eval stream at line number 429 at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:93) at bsh.engine.BshScriptEngine.eval(BshScriptEngine.java:52) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249) at org.scijava.script.ScriptModule.run(ScriptModule.java:173) at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167) at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126) at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65) at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

However, the command you used is consistent with what the macro recorder gives me running the Strahler analysis command. Maybe the command expects another argument (roi) that is not recorded by the Macro recorder?

Whoa, that’s the BeanShell engine, not the IJ1 Macro engine. Are you sure “IJ1 Macro” was selected in the Language menu?

IJ1 Macro was selected in the Language menu for the macro. But the Strahler Analysis command itself (from the BAR update site) is a bsh script.

Aha, OK, that makes sense.

When I run the corrected script with a “Java 6” flavored Fiji (i.e.: the Java-8 update site disabled) on the Blobs sample image, I receive an error in the log:

**** Strahler Analysis Error: Required file(s) not found:
java.lang.ClassNotFoundException: sc.fiji.skeletonize3D.Skeletonize3D_
 
Strahler Analysis requires a recent version of AnalyzeSkeleton_.jar and Skeletonize3D_.jar.
The easiest way to install these files is to use Fiji:
Run Help>Update and ensure you are subscribed to the Fiji update site.
 
Please visit http://forum.image.sc/ if you come across any hurdles.

This makes sense, because Skeletonize3D_ was moved to a new package, but only on the Java-8 update site. So I guess that means the Strahler Analysis command now only works when the Java-8 update site is enabled.

If I run the script with a Fiji that has both Java-8 and BAR enabled, then I get the same error you are seeing, @tswayne. Maybe this is a bug in the Strahler Analysis script? What do you think, @tferr?

1 Like

Hi @ctrueden,

I should mention that the script works fine for me up until the line 11. If i remove line 11 and beyond everything works perfectly, and consequently I don’t think it is an issue with strahler, but probably my script. Strahler seems to be functioning fine when i use it outside of this script

This is the version of the script I was using for testing:

run("Enhance Contrast...", "saturated=0.4");
run("Sharpen");
imageTitle=getTitle(); 
rename(""+imageTitle+"_red.tif");
run("Threshold...");
waitForUser;
run("Convert to Mask");
run("Remove Outliers...", "radius=0.8 threshold=50 which=Bright");
run("Analyze Particles...", "size=40-Infinity display summarize");
run("Skeletonize (2D/3D)"); 
run("Analyze Skeleton (2D/3D)", "prune=[lowest intensity voxel]");
selectWindow(""+imageTitle+"_red.tif"); 
run("Strahler Analysis", "max.=20 infer ignore method=[lowest intensity voxel] 8- bit=[Tagged skeleton] display_iteration show");

Note that the only change from yours above is the addition of a " character near the end of line 11, to fix the syntax error.

Oh thank you, I see what you’re saying. Since I couldn’t get this macro to work I just made a new one shown below.

   run("Enhance Contrast...", "saturated=0.4");
   run("Sharpen");
   imageTitle=getTitle(); 
   rename("ImageJ");
   run("Threshold...");
   waitForUser;
   run("Remove Outliers...", "radius=0.8 threshold=50 which=Bright");
   run("Analyze Particles...", "size=40-Infinity display summarize");
   selectWindow("Summary"); 
   saveAs("Results", "/Users/Vanessa/Dropbox/Kfile/New K Images March 23rd/"+imageTitle+"_IJcount.xls");
   run ("Close") ;
   run("Skeletonize (2D/3D)"); 
   run("Strahler Analysis", "max.=20 infer ignore method=[lowest intensity voxel] 8- bit=[Tagged skeleton] display_iteration show");
   selectWindow("Strahler_Iteration_Log");
   saveAs("Results", "/Users/Vanessa/Dropbox/Kfile/New K Images March 23rd/"+imageTitle+"_StIterationlog.xls");
   run ("Close") ;
   selectWindow("Strahler_Table");
   saveAs("Results", "/Users/Vanessa/Dropbox/Kfile/New K Images March 23rd/"+imageTitle+"_Stnumberlog.xls");
   run ("Close") ;
   selectWindow("StrahlerMask_ImageJ");
   saveAs("Tiff", "/Users/Vanessa/Dropbox/Kfile/New Katie Images March 23rd/"+imageTitle+"_Strahlermask.tif");
   run ("Close") ;
   selectWindow("StrahlerIteration_ImageJ");
   saveAs("Tiff", "/Users/Vanessa/Dropbox/Kfile/New K Images March 23rd/"+imageTitle+"_StrahlerIterationPic.tif");
   run ("Close") ;
   selectWindow("ImageJ");
   run("Analyze Skeleton (2D/3D)", "prune=[lowest intensity voxel]");
   selectWindow("Results"); 
   saveAs("Results", "/Users/Vanessa/Dropbox/Kfile/New K Images March 23rd/"+imageTitle+"_IJresults.xls");
   run ("Close") ;
   selectWindow("Tagged skeleton"); 
   saveAs("Tiff", "/Users/Vanessa/Dropbox/Kfile/New K Images March 23rd/"+imageTitle+"_taggedskeleton.tif");
   run("Close"); 
   selectWindow("ImageJ");
   run("Close"); 

I’m trying batch process a set of images with this macro ( Process>Batch>Macro) . However when the macro gets to the run threshold step the thresholding application comes up but I can’t see image that i need to see to threshold properly. This doesn’t happen when I run the macro outside of the batch processing application. Do you have any idea why this is occurring?

Sorry Vanessa,

but it seems that you are jumping from one problem to the next more complicated.

You write:
“Oh thank you, I see what you’re saying. Since I couldn’t get this macro to work I just made a new one shown below.”

What do you actually see, and why isn’t your initial macro working?

Could you please be more specific concerning the error message?

Somehow puzzled

Herbie

My apologies Herbie,

I didn’t initially understand what the previous message I responded to what was running and misinterpreted it. After ctrueden responded I realized he was running my initial macro without the initial syntax error which is why I said I see what you’re saying. Perhaps I should have better worded that, sorry!

I have no idea why my initial macro was not working and consequently I just tried to make a new one using different steps to bypass the issue and this macro works well for me. What I did in this new macro was replace the initial line 4 with rename(“ImageJ”); instead of renaming it what the initial file name was since this was not working, i’m not sure why the initial written line wasn’t working though.
I also removed the covert to mask step in line 7, but this step was not resulting in any issues, I just realized I didn’t need to include it in my macro any longer and removed it. I also added some Save steps and additional run plugin steps in this macro, again just for my own use, not because any issues were being created without them. Overall this macro works very well when I run it on my images an completes all the steps I need it to. I am now trying to insert this macro into the batch processing application. It seems to be working and I don’t receive any error messages but the only issue is that when I am prompted to threshold my image, although I am able to threshold the image I can’t see the image that I am thresholding like I can when I run the macro outside of the batch processing application. So I can set my threshold, and click apply and okay, but not really see what I am thresholding on the image. Does this make sense? Should I be starting a new thread for this issue?

Vanessa,

from my professional point of view it is not a good idea to leave problems unsolved.

Furthermore, you write:
“What I did in this new macro was replace the initial line 4 with
rename(“ImageJ”); instead of renaming it what the initial file name was
since this was not working, i’m not sure why the initial written line
wasn’t working though.”

That’s not true because these lines work perfectly:

imageTitle=getTitle();
rename(""+imageTitle+"_red.tif");

Regarding the batch processing, I’m not perfectly sure but it may be that it uses batchmode (cf. the macro respective functions) and with it you won’t see any images.

Instead of using batch processing, you may just put your processing steps in a suitable loop. There are more than enough example macros that show you how to do that.

HTH

Herbie

Herbie,

To be more clear, modifying line 4 allowed me to remove the other line that was causing the problem : selectWindow(""+imageTitle+"_red.tif"); . However if I were to now add the line back to the initial macro and wrote: selectWindow(“ImageJ”); after adding the new line in line4, the macro works well. I understand that this doesn’t solve the problem, but instead just bypasses it.

Thank you for suggesting to use loops and your input as to why the batch processing may not be working how I expected it to be. I am very new to writing macros and don’t know much about writing loops but I’m sure I can find helpful examples now that you have suggested it.

Best,

Vanessa

Vanessa,

just for the record, as the following macro lines show

imageTitle=getTitle();
rename(""+imageTitle+"_red.tif");
newImage(“Interruption”, “8-bit ramp”, 128, 128, 1);
selectWindow(""+imageTitle+"_red.tif");

“selectWindow(”"+imageTitle+"_red.tif");"
works perfectly.

Regarding examples, here is a list of example macros:
http://imagej.net/macros/

Best

Herbie

@ctrueden I am really sorry for not replying earlier. The Strahler plugin is simply too complex to be written in BeanShell. It have just ported it to Java. The new version is now distributed through the new Neuroanatomy update site, as recently announced.

@VanessaG, I strongly recommend you to use the new plugin. I am convinced it will solve most issues. Do let me know if otherwise. Please note that the outdated (and buggy) BeanShell version will soon be removed from the BAR update site.

2 Likes