Analysis of images in folder by macro stops if image is empty

I am trying to analyze (morphology,skeletal and fractal dimension) multiple images (about 500) containing particles. The images are in a single folder. I have a working macro that analyzes the images and saves the results as individual csv files. However, when the macro encounters an empty iamge, i.e. no particle, the macro quits since an error window is thrown by Fiji, such as no other pixels than background pixels and opening windows with similar messages. Does anyone know how to work around this?

Have you tried this:


1 Like

I will definitely give it a try, and share the results here.

1 Like

I tried redirectErrorMessages(). This seems to trap errors in opening images. However, my error is that a measurement fails on a successfully opened image, since the image contains no particles. I run the Extended Particle Analyzer plugin from the Biovoxxel plugin on an empty mask (in batch mode):

run(“Set Measurements…”, “area centroid center perimeter bounding fit shape feret’s integrated display redirect=None decimal=5”);
run(“Analyze Particles…”, " show=Masks exclude clear");
run(“Extended Particle Analyzer”, " show=Nothing redirect=None display keep=None");

This returns a result window that is empty. The macro exits from the loop it is in by that, or by the attempt to write results to disk (in batch mode). The macro finishes with cleanup outside the folder loop.

saveAs(“Results”, path+"-morph.csv");

If this is related to the Biovoxxel plugin and not to the standard particle analyzer eventually @biovoxxel can help.

If extended particle analyzer sends no results, then does that mean that nResults is equal to zero? If so, then just add a check:
if(nResults != 0) { saveAs("Results", path+"-morph.csv"); }

1 Like

I don’t know if it is biovoxxel specific. The macro saves the result window as a normal ImageJ window if there are results listed.
I tried the nResults != 0 approach, did not work unfortunately. I will try adding a dummy result line to the window with the right headers to prevent it from being empty, as a workaround. I postprocess the result.csv’s anyhow in R, so stripping the first line after import is not a problem.

1 Like

I finally found the workaround. It turned out to be the fractal analysis that followed the biovoxxel analysis. I replaced the biovoxxel extended particle analysis with the morphology plugin from Landini (great extensive pugin set), Particles4 or Particles8. That plugin returns an nResults value that I can check for being 0. An if condition executes the fractal analysis (or not).
Thanks for the responses and inspiration.

1 Like

I’ll check this and come back to you if I find a bux and fix it in the next version