Running Shell Script with Macro, Macro stops when it gets to CLIJ2

Below Is the shell script which takes .lif inputs, splits the channels, and runs 2 of the channels through UNET models, then runs the analysis macro.ijm that I’ll post below.

The macro starts, opens the first image and then runs into an error, it seems like a separate instance of ImageJ tries to open when the first CLIJ2 portion starts.

If I run the macro by itself it works fine.

(sorry for any formatting errors)

Error Message When Running Script:
(Fiji Is Just) ImageJ 2.1.0/1.53c; Java 1.8.0_172 [64-bit]; Linux 5.4.0-52-generic; 1152MB of 43856MB (2%)

java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Macro canceled
at net.imagej.legacy.LegacyService.runLegacyCompatibleCommand(LegacyService.java:307)
at net.imagej.legacy.DefaultLegacyHooks.interceptRunPlugIn(DefaultLegacyHooks.java:166)
at ij.IJ.runPlugIn(IJ.java)
at ij.Executer.runCommand(Executer.java:150)
at ij.Executer.run(Executer.java:68)
at ij.IJ.run(IJ.java:317)
at ij.IJ.run(IJ.java:328)
at ij.macro.Functions.doRun(Functions.java:686)
at ij.macro.Functions.doFunction(Functions.java:98)
at ij.macro.Interpreter.doStatement(Interpreter.java:278)
at ij.macro.Interpreter.doBlock(Interpreter.java:712)
at ij.macro.Interpreter.doStatement(Interpreter.java:323)
at ij.macro.Interpreter.doFor(Interpreter.java:634)
at ij.macro.Interpreter.doStatement(Interpreter.java:305)
at ij.macro.Interpreter.doStatements(Interpreter.java:264)
at ij.macro.Interpreter.run(Interpreter.java:160)
at ij.macro.Interpreter.run(Interpreter.java:93)
at ij.macro.Interpreter.run(Interpreter.java:104)
at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:161)
at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:145)
at ij.IJ.runMacroFile(IJ.java:165)
at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1165)
at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1161)
at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:1095)
at net.imagej.legacy.IJ1Helper.runMacroFile(IJ1Helper.java:1161)
at net.imagej.legacy.LegacyCommandline$Macro.handle(LegacyCommandline.java:185)
at org.scijava.console.DefaultConsoleService.processArgs(DefaultConsoleService.java:99)
at org.scijava.AbstractGateway.launch(AbstractGateway.java:103)
at net.imagej.Main.main(Main.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:291)
at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:198)
at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:89)
Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Macro canceled
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at net.imagej.legacy.LegacyService.runLegacyCompatibleCommand(LegacyService.java:303)
… 35 more
Caused by: java.lang.RuntimeException: Macro canceled
at ij.macro.Interpreter.error(Interpreter.java:1359)
at ij.macro.Interpreter.abort(Interpreter.java:2099)
at ij.IJ.error(IJ.java:764)
at ij.IJ.error(IJ.java:752)
at ij.macro.Functions.registerExtensions(Functions.java:4936)
at net.haesleinhuepf.clij2.utilities.CLIJ2MacroExtensions.run(CLIJ2MacroExtensions.java:63)
at org.scijava.command.CommandModule.run(CommandModule.java:196)
at org.scijava.module.ModuleRunner.run(ModuleRunner.java:165)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Shell Script: Run.sh

echo “please enter full path to project folder”
read varname

echo “OK i’ll go do some work then…”

mkdir -p $varname/neu
mkdir -p $varname/mac
mkdir -p $varname/bv

for filename in varname/raw/*.lif; do newfile="(basename $filename .lif)"
#echo “$newfile”_mac.tif
./bftools/bfconvert -channel 0 $filename $varname/neu/"$newfile"_neu.tif
./bftools/bfconvert -channel 1 $filename $varname/mac/"$newfile"_mac.tif
./bftools/bfconvert -channel 2 $filename $varname/bv/"$newfile"_bv.tif

done

mkdir -p $varname/mac_out
mkdir -p $varname/bv_out

yapic predict ./models/mac2d.h5 “$varname/mac/*.tif” $varname/mac_out/
rm ./mac_out/class_2

yapic predict ./models/BV2.h5 “$varname/bv/*.tif” $varname/bv_out/
rm $varname/bv_out/class_2

echo “running ImageJ…”

/home/analysis/Fiji.app/ImageJ-linux64 -macro ./macro.ijm $varname

echo “finished”

ImageJ macro.ijm:

//Matts Magic Macrophage Making Machine Macro
xb = getArgument();
testfolder = xb + "/";

mac_file_path = testfolder + "mac/"
bv_file_path = testfolder + "bv/"
neun_file_path = testfolder + "neu/"
yapic = testfolder + "mac_out/"
yapic_bv = testfolder + "bv_out/"
lifs = testfolder + "raw/"

ns = "_neu.tif"
ms = "_mac.tif"
bs = "_bv.tif"
yms = "_mac_class_1.tif"
ybs = "_bv_class_1.tif"


close("*");


results_p = testfolder

//Create folders to hold label maps and data tables 
File.makeDirectory(results_p + "/PV_maps");
File.makeDirectory(results_p + "/NPV_maps");
File.makeDirectory(results_p + "/data_tables");


pvmaps_save = results_p + "/PV_maps/";
npvmaps_save = results_p + "/NPV_maps/";
results_save = results_p + "/data_tables/";




//get the time at the beggining
start_time = getTime();

//get files from lifs folder
files = getFileList(yapic_bv);
nf = lengthOf(files);

print(nf);

for (i = 0; i < lengthOf(files); i++) {
	x = i + 1;
  
  //print out current status of batch	
	print("running file " + x + " out of " + nf);
	run("Bio-Formats Windowless Importer", "open=" + yapic_bv + files[i] + " color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
	raw = getTitle();
	start_time_image = getTime();

	

	
  //create variable for identifying which yapic out file to open as well 	
	name = replace(raw , "_bv_class_1.tif" , "" ); 

	
	//start CLIJ and push bv image	
	run("CLIJ2 Macro Extensions", "cl_device=[Quadro P5000]");
	Ext.CLIJ2_clear();
	Ext.CLIJ2_push(raw);
	
	//Threshold 
	Ext.CLIJ2_thresholdOtsu(raw, yapbv_bin);
	Ext.CLIJ2_pull(yapbv_bin);
	print("Blood Vessels Found for " + name);


	print("Identifying macrophages for " + name);

//OPEN UP YAPIC OUTPUT AND SPLIT INTO PERIVASCULAR AND NON PERIVASCULAR MAPS	
	run("Bio-Formats Windowless Importer", "open=" + yapic + name + yms + " color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
	
	yap = getTitle();
	
  // push mac_output images to GPU
	Ext.CLIJ2_push(yap);
	
  //threshold macrophages from yapic out	
  	Ext.CLIJ2_minimum3DSphere(yap, yapmin, 1.1,1.1,1.1);
	Ext.CLIJ2_thresholdOtsu(yapmin, yap_bin);
	Ext.CLIJ2_connectedComponentsLabelingDiamond(yap_bin, labelmap);

 	print("Macrophages Segmented for " + raw);
	run("Clear Results");
	

	Ext.CLIJ2_statisticsOfBackgroundAndLabelledPixels(yap_bin, labelmap);

	print("Identifying perivascular macrophages " + raw);
  // push pixel count for size filter to GPU
	Ext.CLIJ2_pushResultsTableColumn(PIXEL_COUNT, "PIXEL_COUNT");
	Ext.CLIJ2_excludeLabelsWithValuesWithinRange(PIXEL_COUNT, labelmap, filtered_labelmap, 0, 1500);
	run("Clear Results");
	

	
	Ext.CLIJ2_statisticsOfBackgroundAndLabelledPixels(yapbv_bin, filtered_labelmap);

	Ext.CLIJ2_pushResultsTableColumn(bvsum, "SUM_INTENSITY");
	
 //extract and save labelmap of perivascular macrophages
	Ext.CLIJ2_excludeLabelsWithValuesWithinRange(bvsum, filtered_labelmap, PeriVascular, 0, 100);
	Ext.CLIJ2_saveAsTIF(PeriVascular, pvmaps_save + name);
	Ext.CLIJ2_pull(PeriVascular);
	rename("PV_" + name);
	pvmap = getTitle();
	
print("Identifying non-perivascular macrophages for image " + raw);
// extract and save labelmap of non-perivascular macrophages 
	Ext.CLIJ2_excludeLabelsWithValuesOutOfRange(bvsum, filtered_labelmap, NonPeriVascular, 0, 100);
	Ext.CLIJ2_saveAsTIF(NonPeriVascular, npvmaps_save + name);
	Ext.CLIJ2_pull(NonPeriVascular);
	rename("NPV_" + name);
	npvmap = getTitle();

print("Saving Data for " + name);	


//GET RAW IMAGE DATA OF PV AND NONPV CELLS	
	run("CLIJ2 Macro Extensions", "cl_device=[Quadro P5000]");
	Ext.CLIJ2_clear();
	
	run("Clear Results");


//open raw mac image

	open(mac_file_path + name + ms);
	mac = getTitle();
  //get Perivascular data
	Ext.CLIJ2_push(pvmap);
	Ext.CLIJ2_push(mac)
	Ext.CLIJ2_statisticsOfBackgroundAndLabelledPixels(mac, pvmap);
	
  
	

  //Rename Table columns	
	Table.renameColumn("MINIMUM_INTENSITY", "mac_Min_Int");
	Table.renameColumn("SUM_INTENSITY", "mac_Sum_Int");
	Table.renameColumn("MEAN_INTENSITY", "mac_Mean_Int");
	Table.renameColumn("MAXIMUM_INTENSITY", "mac_MAX_INT");
	Table.renameColumn("PIXEL_COUNT", "mac_PIXEL_COUNT");
  //update table	
	Table.update();

	saveAs("results", results_save + "PV_mac_" + name+ ".csv");
	run("Clear Results");
	
	  
  //get Perivascular data
	Ext.CLIJ2_push(npvmap);
	Ext.CLIJ2_statisticsOfBackgroundAndLabelledPixels(mac, npvmap);

 
	
	

  //Rename Table columns	
	Table.renameColumn("MINIMUM_INTENSITY", "mac_Min_Int");
	Table.renameColumn("SUM_INTENSITY", "mac_Sum_Int");
	Table.renameColumn("MEAN_INTENSITY", "mac_Mean_Int");
	Table.renameColumn("MAXIMUM_INTENSITY", "mac_MAX_INT");
	Table.renameColumn("PIXEL_COUNT", "mac_PIXEL_COUNT");
  //update table	
	Table.update();

	saveAs("results", results_save + "NPV_mac_" + name+ ".csv");
	run("Clear Results");


//open raw BV image again
	open(bv_file_path + name + bs);
	BV = getTitle();
//GET DATA FROM RAW BLOOD VESSEL IMAGE
	Ext.CLIJ2_push(BV)

Ext.CLIJ2_statisticsOfBackgroundAndLabelledPixels(BV, pvmap);
	
  //Delete columns and relable data tables
	Table.deleteColumn('BOUNDING_BOX_X');
	Table.deleteColumn('BOUNDING_BOX_Y');
	Table.deleteColumn('BOUNDING_BOX_Z');
	Table.deleteColumn('BOUNDING_BOX_END_X');
	Table.deleteColumn('BOUNDING_BOX_END_Y');
	Table.deleteColumn('BOUNDING_BOX_END_Z');
	Table.deleteColumn('BOUNDING_BOX_WIDTH');
	Table.deleteColumn('BOUNDING_BOX_HEIGHT');
	Table.deleteColumn('BOUNDING_BOX_DEPTH');
	Table.deleteColumn('STANDARD_DEVIATION_INTENSITY');
	Table.deleteColumn('SUM_INTENSITY_TIMES_X');
	Table.deleteColumn('SUM_INTENSITY_TIMES_Y');
	Table.deleteColumn('SUM_INTENSITY_TIMES_Z');
	Table.deleteColumn('MASS_CENTER_X');
	Table.deleteColumn('MASS_CENTER_Y');
	Table.deleteColumn('MASS_CENTER_Z');
	Table.deleteColumn('SUM_X');
	Table.deleteColumn('SUM_Y');
	Table.deleteColumn('SUM_Z');
	Table.deleteColumn('CENTROID_X');
	Table.deleteColumn('CENTROID_Y');
	Table.deleteColumn('CENTROID_Z');
	Table.deleteColumn('SUM_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MEAN_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MAX_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MAX_MEAN_DISTANCE_TO_MASS_CENTER_RATIO');
	Table.deleteColumn('SUM_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MEAN_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MAX_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MAX_MEAN_DISTANCE_TO_CENTROID_RATIO');
	

  //Rename Table columns	
	Table.renameColumn("MINIMUM_INTENSITY", "BV_MINIMUM_INTENSITY");
	Table.renameColumn("SUM_INTENSITY", "BV_SUM_INTENSITY");
	Table.renameColumn("MEAN_INTENSITY", "BV_MEAN_INTENSITY");
	Table.renameColumn("MAXIMUM_INTENSITY", "BV_MAXIMUM_INTENSITY");
	Table.renameColumn("PIXEL_COUNT", "BV_PIXEL_COUNT");
  //update table	
	Table.update();

	saveAs("results", results_save + "PV_BloodVessels_" + name+ ".csv");
	run("Clear Results");
	
	  
  //get Perivascular data
	Ext.CLIJ2_statisticsOfBackgroundAndLabelledPixels(BV, npvmap);

  //Delete columns and relable data tables
	Table.deleteColumn('BOUNDING_BOX_X');
	Table.deleteColumn('BOUNDING_BOX_Y');
	Table.deleteColumn('BOUNDING_BOX_Z');
	Table.deleteColumn('BOUNDING_BOX_END_X');
	Table.deleteColumn('BOUNDING_BOX_END_Y');
	Table.deleteColumn('BOUNDING_BOX_END_Z');
	Table.deleteColumn('BOUNDING_BOX_WIDTH');
	Table.deleteColumn('BOUNDING_BOX_HEIGHT');
	Table.deleteColumn('BOUNDING_BOX_DEPTH');
	Table.deleteColumn('STANDARD_DEVIATION_INTENSITY');
	Table.deleteColumn('SUM_INTENSITY_TIMES_X');
	Table.deleteColumn('SUM_INTENSITY_TIMES_Y');
	Table.deleteColumn('SUM_INTENSITY_TIMES_Z');
	Table.deleteColumn('MASS_CENTER_X');
	Table.deleteColumn('MASS_CENTER_Y');
	Table.deleteColumn('MASS_CENTER_Z');
	Table.deleteColumn('SUM_X');
	Table.deleteColumn('SUM_Y');
	Table.deleteColumn('SUM_Z');
	Table.deleteColumn('CENTROID_X');
	Table.deleteColumn('CENTROID_Y');
	Table.deleteColumn('CENTROID_Z');
	Table.deleteColumn('SUM_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MEAN_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MAX_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MAX_MEAN_DISTANCE_TO_MASS_CENTER_RATIO');
	Table.deleteColumn('SUM_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MEAN_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MAX_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MAX_MEAN_DISTANCE_TO_CENTROID_RATIO');
	

  //Rename Table columns	
	Table.renameColumn("MINIMUM_INTENSITY", "BV_MINIMUM_INTENSITY");
	Table.renameColumn("SUM_INTENSITY", "BV_SUM_INTENSITY");
	Table.renameColumn("MEAN_INTENSITY", "BV_MEAN_INTENSITY");
	Table.renameColumn("MAXIMUM_INTENSITY", "BV_MAXIMUM_INTENSITY");
	Table.renameColumn("PIXEL_COUNT", "BV_PIXEL_COUNT");
	
  //update table	
	Table.update();

	saveAs("results", results_save + "NPV_BloodVessels_" + name + ".csv");
	run("Clear Results");

//open NEUN image

 	open(neun_file_path + name + ns);
 	neu = getTitle();
 	
//GET DATA FROM RAW NeuN IMAGE
	Ext.CLIJ2_push(neu);

Ext.CLIJ2_statisticsOfBackgroundAndLabelledPixels(neu, pvmap);
	
  //Delete columns and relable data tables
	Table.deleteColumn('BOUNDING_BOX_X');
	Table.deleteColumn('BOUNDING_BOX_Y');
	Table.deleteColumn('BOUNDING_BOX_Z');
	Table.deleteColumn('BOUNDING_BOX_END_X');
	Table.deleteColumn('BOUNDING_BOX_END_Y');
	Table.deleteColumn('BOUNDING_BOX_END_Z');
	Table.deleteColumn('BOUNDING_BOX_WIDTH');
	Table.deleteColumn('BOUNDING_BOX_HEIGHT');
	Table.deleteColumn('BOUNDING_BOX_DEPTH');
	Table.deleteColumn('STANDARD_DEVIATION_INTENSITY');
	Table.deleteColumn('SUM_INTENSITY_TIMES_X');
	Table.deleteColumn('SUM_INTENSITY_TIMES_Y');
	Table.deleteColumn('SUM_INTENSITY_TIMES_Z');
	Table.deleteColumn('MASS_CENTER_X');
	Table.deleteColumn('MASS_CENTER_Y');
	Table.deleteColumn('MASS_CENTER_Z');
	Table.deleteColumn('SUM_X');
	Table.deleteColumn('SUM_Y');
	Table.deleteColumn('SUM_Z');
	Table.deleteColumn('CENTROID_X');
	Table.deleteColumn('CENTROID_Y');
	Table.deleteColumn('CENTROID_Z');
	Table.deleteColumn('SUM_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MEAN_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MAX_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MAX_MEAN_DISTANCE_TO_MASS_CENTER_RATIO');
	Table.deleteColumn('SUM_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MEAN_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MAX_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MAX_MEAN_DISTANCE_TO_CENTROID_RATIO');
	

  //Rename Table columns	
	Table.renameColumn("MINIMUM_INTENSITY", "NeuN_MINIMUM_INTENSITY");
	Table.renameColumn("SUM_INTENSITY", "NeuN_SUM_INTENSITY");
	Table.renameColumn("MEAN_INTENSITY", "NeuN_MEAN_INTENSITY");
	Table.renameColumn("MAXIMUM_INTENSITY", "NeuN_MAXIMUM_INTENSITY");
	Table.renameColumn("PIXEL_COUNT", "NeuN_PIXEL_COUNT");
  //update table	
	Table.update();

	saveAs("results", results_save + "PV_NeuN_" + name + ".csv");
	run("Clear Results");
	
	  
  //get Perivascular data
	Ext.CLIJ2_statisticsOfBackgroundAndLabelledPixels(neu, npvmap);

  //Delete columns and relable data tables
	Table.deleteColumn('BOUNDING_BOX_X');
	Table.deleteColumn('BOUNDING_BOX_Y');
	Table.deleteColumn('BOUNDING_BOX_Z');
	Table.deleteColumn('BOUNDING_BOX_END_X');
	Table.deleteColumn('BOUNDING_BOX_END_Y');
	Table.deleteColumn('BOUNDING_BOX_END_Z');
	Table.deleteColumn('BOUNDING_BOX_WIDTH');
	Table.deleteColumn('BOUNDING_BOX_HEIGHT');
	Table.deleteColumn('BOUNDING_BOX_DEPTH');
	Table.deleteColumn('STANDARD_DEVIATION_INTENSITY');
	Table.deleteColumn('SUM_INTENSITY_TIMES_X');
	Table.deleteColumn('SUM_INTENSITY_TIMES_Y');
	Table.deleteColumn('SUM_INTENSITY_TIMES_Z');
	Table.deleteColumn('MASS_CENTER_X');
	Table.deleteColumn('MASS_CENTER_Y');
	Table.deleteColumn('MASS_CENTER_Z');
	Table.deleteColumn('SUM_X');
	Table.deleteColumn('SUM_Y');
	Table.deleteColumn('SUM_Z');
	Table.deleteColumn('CENTROID_X');
	Table.deleteColumn('CENTROID_Y');
	Table.deleteColumn('CENTROID_Z');
	Table.deleteColumn('SUM_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MEAN_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MAX_DISTANCE_TO_MASS_CENTER');
	Table.deleteColumn('MAX_MEAN_DISTANCE_TO_MASS_CENTER_RATIO');
	Table.deleteColumn('SUM_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MEAN_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MAX_DISTANCE_TO_CENTROID');
	Table.deleteColumn('MAX_MEAN_DISTANCE_TO_CENTROID_RATIO');
	

  //Rename Table columns	
	Table.renameColumn("MINIMUM_INTENSITY", "NeuN_MINIMUM_INTENSITY");
	Table.renameColumn("SUM_INTENSITY", "NeuN_SUM_INTENSITY");
	Table.renameColumn("MEAN_INTENSITY", "NeuN_MEAN_INTENSITY");
	Table.renameColumn("MAXIMUM_INTENSITY", "NeuN_MAXIMUM_INTENSITY");
	Table.renameColumn("PIXEL_COUNT", "NeuN_PIXEL_COUNT");
	
  //update table	
	Table.update();

	saveAs("results", results_save + "NPV_NeuN_" + name+ ".csv");
	
	run("Clear Results");
	
	print("Done! Image " + raw + " took: " + ((getTime() - start_time_image)/1000) + " sec to complete");	
	
	close("*");

	
	
}
print("Total macro time took: " + ((getTime()-start_time)/1000) + " seconds")

Hey @Matt_Hunt,

I would love to help you with this one, but I’m afraid I can’t run this macro on my computer. Would you mind posting a minimal macro that reproduces the error?

For example, can you execute this macro on your computer?

run("CLIJ2 Macro Extensions", "cl_device=[Quadro P5000]");

Best,
Robert

Screenshot from 2020-11-14 13-18-26

Thanks for super fast reply!!!

Also Running Ubuntu 18.04 with Lambda Stack if that helps as well!

I made a super simple new bash script: Run.sh
and quick macro: test.ijm

If I run the shell script the macro opens the image and then fails when it gets to CLIJ, but if I run the macro from within the same instance of ImageJ through the text editor, then it works fine!

Run.sh

echo "OK i'll go do some work then..." 
/home/analysis/Desktop/MH_pipeline/Fiji.app/ImageJ-linux64  -macro /home/analysis/Desktop/MH_pipeline/test.ijm

test.ijm

run("Bio-Formats Windowless Importer", "open=/home/analysis/Desktop/ptest/bv_out/190517_LPSIT_15_DRG_bv_class_1.tif color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");

raw = getTitle();
run("CLIJ2 Macro Extensions", "cl_device=[Quadro P5000]")
	Ext.CLIJ2_clear();
	Ext.CLIJ2_push(raw);


	//Threshold 
	Ext.CLIJ2_thresholdOtsu(raw, yapbv_bin);
	Ext.CLIJ2_pull(yapbv_bin);

Can you please try this macro?

I’m trying to figure out if CLIJ works and/or if CLIJ has any issue with anything else that was execute in advance :wink:

Still getting the same error when running the shell script with just

run(“CLIJ2 Macro Extensions”, “cl_device=[Quadro P5000]”);

Error Message

(Fiji Is Just) ImageJ 2.0.0-rc-72/1.53f; Java 1.8.0_172 [64-bit]; Linux 5.4.0-52-generic; 222MB of 40341MB (<1%)
 
java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Macro canceled
	at net.imagej.legacy.LegacyService.runLegacyCompatibleCommand(LegacyService.java:307)
	at net.imagej.legacy.DefaultLegacyHooks.interceptRunPlugIn(DefaultLegacyHooks.java:166)
	at ij.IJ.runPlugIn(IJ.java)
	at ij.Executer.runCommand(Executer.java:150)
	at ij.Executer.run(Executer.java:68)
	at ij.IJ.run(IJ.java:323)
	at ij.IJ.run(IJ.java:334)
	at ij.macro.Functions.doRun(Functions.java:691)
	at ij.macro.Functions.doFunction(Functions.java:98)
	at ij.macro.Interpreter.doStatement(Interpreter.java:278)
	at ij.macro.Interpreter.doStatements(Interpreter.java:264)
	at ij.macro.Interpreter.run(Interpreter.java:160)
	at ij.macro.Interpreter.run(Interpreter.java:93)
	at ij.macro.Interpreter.run(Interpreter.java:104)
	at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:162)
	at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:146)
	at ij.IJ.runMacroFile(IJ.java:171)
	at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1165)
	at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1161)
	at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:1095)
	at net.imagej.legacy.IJ1Helper.runMacroFile(IJ1Helper.java:1161)
	at net.imagej.legacy.LegacyCommandline$Macro.handle(LegacyCommandline.java:185)
	at org.scijava.console.DefaultConsoleService.processArgs(DefaultConsoleService.java:99)
	at org.scijava.AbstractGateway.launch(AbstractGateway.java:103)
	at net.imagej.Main.main(Main.java:55)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:291)
	at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:198)
	at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:89)
Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Macro canceled
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at net.imagej.legacy.LegacyService.runLegacyCompatibleCommand(LegacyService.java:303)
	... 31 more
Caused by: java.lang.RuntimeException: Macro canceled
	at ij.macro.Interpreter.error(Interpreter.java:1359)
	at ij.macro.Interpreter.abort(Interpreter.java:2099)
	at ij.IJ.error(IJ.java:770)
	at ij.IJ.error(IJ.java:758)
	at ij.macro.Functions.registerExtensions(Functions.java:4969)
	at net.haesleinhuepf.clij2.utilities.CLIJ2MacroExtensions.run(CLIJ2MacroExtensions.java:63)
	at org.scijava.command.CommandModule.run(CommandModule.java:196)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:165)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
	at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Ok. The error appears to happen in ImageJs extensions mechanism

Which is here:

It appears ImageJs macro extensions think, there is no macro running because there is no active interpreter. Let me call @Wayne for help. Maybe he can help us in running a macro with macro extensions from command line.

that would be awesome! Thank you so much!

Hey Robert, I think I got close to getting it to work. If I ran a shell script that looked like the following

run.sh
./macro.sh & ./macro.sh

test.ijm

run("Bio-Formats Windowless Importer", "open=/home/analysis/Desktop/ptest/bv_out/190517_LPSIT_15_DRG_bv_class_1.tif color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");

raw = getTitle();
run("CLIJ2 Macro Extensions", "cl_device=[Quadro P5000]")
	Ext.CLIJ2_clear();
	Ext.CLIJ2_push(raw);


	//Threshold 
	Ext.CLIJ2_thresholdOtsu(raw, yapbv_bin);
	Ext.CLIJ2_pull(yapbv_bin);

macro.sh

`/home/analysis/Desktop/MH_pipeline/Fiji.app/ImageJ-linux64  -macro /home/analysis/Desktop/MH_pipeline/test.ijm`

I could get it it to work, but anything more complicated still failed and I know there has to be a better way!

If you tell us which script fails and what’s the error message, we can take another look :wink:

So I can get past
run(“CLIJ2 Macro Extensions”, “cl_device=[Quadro P5000]”)

but then it still is saying it doesn’t recognize Ext.CLIJ2_clear();

And now I can’t get the example I gave in my previous post to work either!

I tried using the 3D roi manager which also uses macro Extensions and ran into the same issue so I definitely don’t think it is CLIJ specific! Do you think I should post this to the general imageJ forum?

You can also check the other threads or people who manged to run macros from command line:
https://forum.image.sc/search?q=run%20clij%20command%20line