Help with particle analysis

analyze-particles
macro
fiji
Tags: #<Tag:0x00007fd5431d0338> #<Tag:0x00007fd5431d01a8> #<Tag:0x00007fd5431d0068>

#1

I’m trying a macro to do batch process for particles analysis in Fiji, but got stuck at the redirect step. I got an error saying that the redirect image is not the same size as the current image. I’m quite new to ImageJ macro, so I hope someone can help me out. Thanks a lot. Code is below:

dir1=getDirectory("Get Directory");
list = getFileList(dir1);
setBatchMode(true);
for (i=0; i<list.length; i++) {
showProgress(i+1, list.length);
open(dir1 + list[i]);
run("Subtract Background...", "rolling=30");
original_file_name = File.name;
duplicated_file_name = File.nameWithoutExtension + "-1";
run("Duplicate...", "title=&duplicated_file_name");
run("Mean...", "radius=3");
run("Auto Local Threshold", "method = Bernsen radius=15 parameter_1=0 parameter_2=0 white");
setOption("BlackBackground", false);
run("Set Measurements...", "area mean min integrated display redirect=[&original_file_name] decimal = 3");
run("Analyze Particles...", "size=20-1000 circularity=0.20-1.00 show=[Bare Outlines] display exclude");
Close();}

#2

Hi @Tran_Minh_Tuan

this part of Analyze Particles seems to come up every now and so often when using it in macros…
You need to have a dynamic redirect and string interpolation (like in bash, python etc.) does not really work in ImageJ macro language, so you need to concatenate it instead:

run("Set Measurements...", "area mean min integrated display redirect=[&original_file_name] decimal = 3");

becomes

run("Set Measurements...", "area mean min integrated display redirect=[" + original_file_name + "] decimal = 3");

hope that works

Felix


Remove overlap and out-of-focus particles
#3

It actually does work in some instances. See https://imagej.nih.gov/ij/macros/ArgumentPassingDemo.txt for some examples. So in this case, it should actually work.


@Tran_Minh_Tuan: Is your input image by chance a stack? If so, run("Duplicate...", "title=&duplicated_file_name"); will only duplicate the currently active slice and not the complete stack. That would somehow explain that their dimensions differ.