 # Analyze Particles Angle Problem

This macro describes the problem with the angles returned from Analyze Particles.

``````//_______________MACRO START_____________________
//Analyze Particles Angle problem macro By Ron DeSpain 171029
//Problem with angles coming out of Analyze Particles...
//Two lines are drawn at +45deg and -45deg
//Best fit elliple maj axes returned are +45deg and +135deg
//The Summary Mean angle is 90deg instead of 0deg.
//the 135deg major axis is wrong so the average angle is wrong.

newImage("Lines", "RGB white", 511, 511, 1);
makeLine(216, 265, 292, 189);
run("Draw", "slice");
makeLine(220, 317, 312, 409);
run("Measure");
waitForUser("PROBLEM","Note that this line selections angle is -45deg");
run("Draw", "slice");

setForegroundColor(0, 0, 0);
run("Select None");
run("Set Measurements...", "area mean min centroid center fit redirect=None decimal=3");
setOption("BlackBackground", true);
run("Make Binary");
run("Analyze Particles...", "  show=Ellipses display clear include");
run("Summarize");
waitForUser("PROBLEM","the 135deg major axis angle is wrong \nit should be -45deg or 270deg\nso the mean angle of 90 deg is wrong.");
//________________MACRO END_______________________
``````
1 Like

OOps, I subtracted wrong in my head and got 360-45 = 270…duhh. I’m looking for a way to get the acute angle solution from “Analyze Particles…”

Here’s a corrected macro:

``````//MACRO BEGINS_______________
//Analyze Particles Angle problem macro By Ron DeSpain 171029
//Problem with angles coming out of Analyze Particles...
//Two lines are drawn at +45deg and -45deg
//Best fit elliple maj axes returned are +45deg and +135deg
//The Summary Mean angle is 90deg instead of 0deg.
//the 135deg major axis is wrong so the average angle is wrong.

newImage("Lines", "RGB white", 511, 511, 1);
makeLine(216, 265, 292, 189);
run("Draw", "slice");
makeLine(220, 317, 312, 409);
run("Measure");
waitForUser("PROBLEM","Note that this line selections angle is -45deg");
run("Draw", "slice");

setForegroundColor(0, 0, 0);
run("Select None");
run("Set Measurements...", "area mean min centroid center fit redirect=None decimal=3");
setOption("BlackBackground", true);
run("Make Binary");
run("Analyze Particles...", "  show=Ellipses display clear include");
run("Summarize");
waitForUser("PROBLEM","the 135deg major axis angle is wrong \nit should be -45deg or 315deg\nso the mean angle of 90 deg is wrong.");
//MACRO ENDS_________________
``````
1 Like

Dear @rondespain,

I guess it’s all a matter of definition:

``````newImage("Lines", "RGB white", 511, 511, 1);
makeLine(216, 265, 292, 189);
run("Measure");
makeLine(220, 317, 312, 409);
run("Measure");
makeLine(312, 409, 220, 317); // switched start and end coordinates
run("Measure");
``````

Best,
Stefan