Thresholding and measuring major and minor axes


Hi there, I’m trying to find the major and minor axes of this ellipse but I’m having trouble thresholding it in a way that imagej can analyze the particles. I’ve been using process find edges, then thresholding, and then make binary and dilating.



Hi @Thomas_Wu

to get you started you can run the following IJ1 macro (depends on the BioVoxxel toolbox which you can add as an update site.
Run it on your very original from which it actually takes only a part for the processing. The results table should gie you teh major and minor axis in teh respective columns.

This needs some improvement to get a more specific output, but might get you started

original = getTitle();
makeRectangle(524, 424, 1256, 1588);
run("Duplicate...", "title=["+original+"_copy");
duplicate = getTitle();
run("Pseudo flat field correction", "blurring=90");
close(duplicate + "_background");
run("Variance...", "radius=4");
setAutoThreshold("Mean dark");
setOption("BlackBackground", true);
run("Convert to Mask");
run("EDM Binary Operations", "iterations=40 operation=close");
run("Fill Holes");
run("EDM Binary Operations", "iterations=160 operation=open");
run("Set Measurements...", "area mean standard modal min centroid center perimeter bounding fit shape feret's integrated median skewness kurtosis area_fraction stack display redirect=None decimal=3");
run("Analyze Particles...", "pixel display");
run("Create Selection");
run("Restore Selection");


Hi there thanks for you help! This is my original image:

I ran the macro and got the following result:

I’m not sure exactly what your macro is doing. Why is it outlining the little bubbles on the bottom left?

I was reading the documentation for EDM Binary Operations, but I don’t understand it. What are the parameters in the macro?


This is a little weird. My output looks like this…

starting with your original image. Though, not perfect it should definitely not outline the bubbles on the lefthand site. did you change any parameter settings?

The parameters in the EDM Binary Operation plugin part do an erosion and dilation sequence on the thresholded particles with open running erode -> dilate and close running dilate -> erode. This helps to create connections innitially missing and getting rid of unwanted connections and as a side effect also of small particles (in your case some of teh thresholded bubbles.

The numbers used for the parameters where based on a quick testing by using the EDM Binary Operations manually in preview mode to check at which point I would reach a binary object kind of closely resembling your structure desired to extract from the image.

Hope this is making it a little clearer and you can try to modify it accordingly


How does the cropping portion of the code work?


just places a rectangular selection on your image and uses the standard IJ function ►Image ►Crop…

I just included this, because of the vinetting in your image. If the dark corners are kept, it would most likely mess up the run("Pseudo flat field correction", "blurring=90"); part.

If your structure of interest is in every image at a very different place then you might need to do that part manually. But if the dark corners are consistently at the same place you might at least be able to define a general ROI excluding those in you stack before running teh macro without any cropping.


What does the blurring = 90 parameter do in the pseudo flat field correction as well as the radius=4 in the variance?


You can actually select the macro code in the scripting editor and go to ►Run ►Run selected code
while changing the parameters to see what happens.

The pseudo flat field correction corrects for unequal lighting and the variance tries to make the edges of your objects better identifiable.