Batch processing with Frangi vesselness filter

Hi guys,
I’m quite new to Fiji and macro writing so I could easily be missing something. I’m trying to use the Frangi Vesselness filter as part of a batch process macro but haven’t got very far. I keep getting error messages, either the “result” file can’t be found or it doesn’t like my placeholder names etc. I’ve tried using the macro templates with the online advice and several ways of loading the images etc but don’t get anywhere. I think the issue might be with the [ ] brackets in the frangi vesselness code, or maybe I’m mixing up script languages?
The script below works for the individual image but needs modifying for the macro:

open("N:/CD31_Soleus_4x_B&S_0_40/10-40-55_Kathryn_cD31 soleus_630_z19305_s5_4_0x_UltraII_C00_xyz-Table Z0003.ome.tif");
run("Frangi Vesselness", "input=[10-40-55_Kathryn_cD31 soleus_630_z19305_s5_4_0x_UltraII_C00_xyz-Table Z0003.ome.tif] dogauss=true spacingstring=[2, 2] scalestring=[2, 8]");
selectWindow("result");
run("Stack to Images");
selectWindow("1");
saveAs("Tiff", "N:/CD31_Soleus_Frangi/resultSplitZ0003.tif");
run("Close All");

Thanks for your help
FP

@medfmp
QUICK ANSWER:
I think the above code should be ‘ok’… as long as you remove the brackets in your Franginess code call (the space in the image name might be causing the issue… remove all spaces in your image file names to be sure):

run("Frangi Vesselness", "input=10-40-55_Kathryn_cD31 soleus_630_z19305_s5_4_0x_UltraII_C00_xyz-Table Z0003.ome.tif dogauss=true spacingstring=[2, 2] scalestring=[2, 8]");

LONG ANSWER:

What have you tried? Did you try incorporating Script Parameters yet? That will really help with generalizing your scripts and perhaps fix some of those hard-coded String issues in function calls.

Take a look at this code example (also available via the Script Editor in Templates > ImageJ 1.x > Batch > Process Folder (IJ1 Macro):

 * Macro template to process multiple images in a folder
 */

#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix

// See also Process_Folder.py for a version of this code
// in the Python scripting language.

processFolder(input);

// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
	list = getFileList(input);
	list = Array.sort(list);
	for (i = 0; i < list.length; i++) {
		if(File.isDirectory(input + File.separator + list[i]))
			processFolder(input + File.separator + list[i]);
		if(endsWith(list[i], suffix))
			processFile(input, output, list[i]);
	}
}

function processFile(input, output, file) {
	// Do the processing here by adding your own code.
	// Leave the print statements until things work, then remove them.
	print("Processing: " + input + File.separator + file);
	print("Saving to: " + output);
}

This script is described in an older recorded workshop on Scripting in ImageJ you might find helpful. The corresponding slides for that presentation are here (and the more updated versions are here).

Now - adapting the above to use your code snippet (WARNING: I did not test this code at all - as I don’t have datasets to run this on… so you’ll have to run/adapt it yourself to get things working as you want.)… something like this might get you started:

#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix

processFolder(input);

// function to scan folders/subfolders/files to find files with the specified suffix 
function processFolder(input) {
	list = getFileList(input);
	list = Array.sort(list);
	for (i = 0; i < list.length; i++) {
		if(File.isDirectory(input + File.separator + list[i]))
			processFolder(input + File.separator + list[i]);
		if(endsWith(list[i], suffix))
			processFile(input, output, list[i]);
	}
}

function processFile(input, output, file) {
	// personally, I always use Bio-Formats to open images... but if you want - you can use this code call instead:
	// open(input + File.separator + file);
	run("Bio-Formats", "open=[" + input + File.separator + file +"] autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
	run("Frangi Vesselness", "input=" + file + " dogauss=true spacingstring=[2, 2] scalestring=[2, 8]");
	selectWindow("result");
	title = getTitle();
	run("Stack to Images");
	selectWindow("1");
	save(output + File.separator + "FrangiOUTPUT_" + file);
	run("Close All");
}

Thank you for your fast reply. I tried the macro you kindly adapted for me and it works like a dream!!
I had tried the suggested macro template, I can see now where I was going wrong but wouldn’t have known how to fix it so thank you so much!!!

Fi

1 Like