Is fitted ellipse in analyze->set measurements circumscribed or inscribed?

I need to know whether fitted ellipse in analyze->set measurements is circumscribed or inscribed.

1 Like


Neither, it finds minor/major axis directions and radii. Details here:

Consider some arbitrarily shaped closed profile, which we wish to
characterize in a quantitative manner by a series of terms, each
term providing a better approximation to the shape of the profile.
Assume also that we wish to include the orientation of the profile
(i.e. which way is up) in our characterization.
One approach is to view the profile as formed by a series harmonic
components, much in the same way that one can decompose a waveform
over a fixed interval into a series of Fourier harmonics over that
interval. From this perspective the first term is the mean radius,
or some related value (i.e. the area). The second term is the
magnitude and phase of the first harmonic, which is equivalent to the
best-fitting ellipse.
What constitutes the best-fitting ellipse? First, it should have the
same area. In statistics, the measure that attempts to characterize some
two-dimensional distribution of data points is the ‘ellipse of
concentration’ (see Cramer, Mathematical Methods of Statistics,
Princeton Univ. Press, 945, page 283). This measure equates the second
order central moments of the ellipse to those of the distribution,
and thereby effectively defines both the shape and size of the ellipse.
This technique can be applied to a profile by assuming that it constitutes
a uniform distribution of points bounded by the perimeter of the profile.
For most ‘blob-like’ shapes the area of the ellipse is close to that
of the profile, differing by no more than about 4%. We can then make
a small adjustment to the size of the ellipse, so as to give it the
same area as that of the profile. This is what is done here, and
therefore this is what we mean by ‘best-fitting’.
For a real pathologic case, consider a dumbell shape formed by two small
circles separated by a thin line. Changing the distance between the
circles alters the second order moments, and thus the size of the ellipse
of concentration, without altering the area of the profile.


1 Like

@bogovicj Does not make sense. You mentioned it finds the major/minor axis and radii of ellipse. so which ellipse? The ellipse should have relation with the object. It should either be circumscribed or inscribed.


There are other ways to choose an ellipse to fit a shape beside circumscribed and inscribed.
The method in Fiji tries to get the area of the shape correct. Circumscribed will over estimate area,
inscribed will underestimate area.

You can see that the result is neither circumscribed nor inscribed:

Does that image help?


@bogovicj Yes. It helped to understand what you mean.
I appreciate if you could give me your feedback regarding this question: How can I circumscribe an ellipse to an image by imagej macro?

Here is a macro that can be usefull for you

PS: I am not the author of this macro.
I can’t find the origin.
My apologies to the author.

  run("Blobs (25K)");
  run("Set Measurements...", " area mean centroid fit ");
  run("Analyze Particles...", "size=0 circularity=0 show=Ellipses display exclude clear ");
  run("RGB Color");
  for(i=0; i<nResults; i++) {
      a = getResult('Angle',i)*PI/180;
1 Like

This is the best I could get. It’s a circle, but it includes all the target with a minimal surround.

//Circumscribed Ellipse
oit = getTitle();
run(“Set Measurements…”, “area mean standard modal min centroid center perimeter bounding fit shape feret’s integrated median skewness kurtosis area_fraction stack redirect=None decimal=3”);

//run("Rotate… ", “angle=164.44 grid=1 interpolation=Bicubic”);
setOption(“BlackBackground”, true);
run(“Make Binary”);
run(“Analyze Particles…”, “display exclude clear include”);
run(“Select None”);
fangle = getResult(“Angle”, 0);
run("Rotate… ", “angle=&fangle grid=1 interpolation=Bicubic”);

setOption(“BlackBackground”, true);
run(“Make Binary”);
run(“Analyze Particles…”, “display exclude clear include add”);
roiManager(“rename”,“Target i0”);
roiManager(“Show None”);
roiManager(“Rename”, “Fit”);
//run(“Select None”);


function makeFeretsDiameter()
run(“Line Width…”, “line=1”);
diameter = 0.0;
getSelectionCoordinates(xCoordinates, yCoordinates);
n = xCoordinates.length;
dmax = 0;
for (i=0; i<n; i++) {
for (j=i; j<n; j++) {
dx = xCoordinates[i] - xCoordinates[j];
dy = yCoordinates[i] - yCoordinates[j];
d = sqrt(dxdx + dydy);
if (d>diameter) {
diameter = d;
if (d >= dmax) dmax = d;
i1 = i;
i2 = j;
makeLine(xCoordinates[i1], yCoordinates[i1],xCoordinates[i2],yCoordinates[i2],dmax);
roiManager(“rename”,“Feret Line i1”);
run(“Rotate…”, " angle=90");
roiManager(“Select”, 2);
roiManager(“Rename”, “Rotated i2”);
roiManager(“Select”, newArray(1,2));
roiManager(“Select”, 3);
roiManager(“Rename”, “Xboxes i3”);
run(“Enlarge…”, 1)
run(“Fit Circle”);
roiManager(“Select”, 4);
roiManager(“Rename”, “Circle i4”);
roiManager(“show none”);

 axminor = getResult("Height", 0);
 axmajor = getResult("Width", 0);
 ar = axminor/axmajor;

makeEllipse(xCoordinates[i1], yCoordinates[i1],xCoordinates[i2],yCoordinates[i2],1);
roiManager("Select", 5);
roiManager("Rename", "Ellipse i5");
run("Select None");

rfangle = -fangle;

run("Rotate... ", "angle=&rfangle grid=1 interpolation=Bicubic");
roiManager("Select", 5);
run("Rotate...", "rotate angle=&rfangle");
roiManager("show none");
roiManager("Select", newArray(0,1,2,3,4));
roiManager("Select", 0);
roiManager("Rename", "Fit");



Ron DeSpain

p.s. It looks like the plugin at this link provides inscribed circles.

1 Like

@Mathew Thanks for sharing I tried that but did not work for my images.

@rondespain Thanks so much for your time. I need to be ellipse. In fact circle is a special case for ellipse but I need to fit ellipse and then find the ratio of larger diameter to smaller one.

Check out this link

**and scroll down to **

30.7 Set Measurements…

Fit ellipse Fits an ellipse to the selection. Uses the headings Major, Minor and Angle. Major and Minor are the primary and secondary axis of the best fitting ellipse. Angle is the angle between the primary axis and a line parallel to the X-axis of the image. The coordinates of the center of the ellipse are displayed as X and Y if Centroid is checked. Note that ImageJ cannot calculate the major and minor axis lengths if Pixel Aspect Ratio in the Analyze▷Set Scale…↓ dialog is not 1.0. There are several ways to view the fitted ellipse:

I checked to see if the eccentricity changes when an ellipse is scaled in ImageJ

The center ellipse below is the Selection>Fit Ellipse. The next one out is a scaled and translated version of that ellipse using Selection>Scale…and manual dragging. They both have the same ratio of major to minor axes’ (eccentricity) to the third decimal place. So if all you need is the eccentricity you can use the built in elliptical fit in Analyze Particles, since the enclosing ellipse has approximately the same eccentricity.



I have an idea for fitting an ellipse directly to an arbitrary shape. If I’m successful, I’ll share.

Ron DeSpain

1 Like

I think you will have to describe your data and your process of analysis as there an infinite number of ellipses that circumscribe the data.


Can you describe how you would pick between the three solutions above? What about your data would allow that choice to be made in code?



If it were me, I’d aim for the smallest circumscribing ellipse - since that will have an area closest to the shape, but it’s not clear to me what the best approach would be to find it.

1 Like


I was asking Zeynab_Mousavi what her constraints would be for the ellipse in order to pick one of the many (possibly infinite) ellipses that can circumscribe any shape. Her data should have some features specific to it (concave, convex, tendrils, holes…etc.), and the solution sought (why is the ecentricity important?) that would guide an algorithm in picking which ellipse is best, or even if an ellipse is needed (maybe a convex hull, or bounding box…etc.). For instance…should the major axis lie along or parallel to the Feret line, or should it be a scaled and translated version of the built in Selection>Fit Ellipse maintaining the ecentricity, or as you advise the smallest in area of all the ellipses that can be circumscribed (I looked online and this option takes a lot of time e.g. The Elliptical Hough transform is proposed here)? Her goal and the data should advise the constraints to be used.

It looks to me like the we need to define the Zeynab_Mousavi problem better, but it’s a great general problem for investigation.

I don’t see a plugin for the Elliptical Hough transform…do you know of one bogovicj? Please share if you do.



Hi Ron (@rondespain),

Good idea, thanks for pointing that out. The closest thing I’m aware of is this Hough circle transform implementation. So not quite what’s needed here.



1 Like

you want use the small ellipse’s centried, and scale the small ellipse as a same ration in X and Y to contain the mask fully, right? It is not a image question: It is a computation geometry question:

  1. treat the contours as a polygon
  2. find convex hull, and extract every convex point
  3. count the ratio every convex point need to contain
  4. scale using the max ratio
1 Like

function roiadd(name) //Helps organize the roi’s
roiindex = roiManager(“count”) -1;
roiManager(“select”, roiindex);
roiManager(“rename”, name+" - “+roiindex);
//Detect the target
setAutoThreshold(“IsoData dark”);
setOption(“BlackBackground”, true);
run(“Convert to Mask”);
run(“Set Measurements…”, “area mean standard modal min centroid center perimeter bounding fit shape feret’s integrated median skewness kurtosis area_fraction stack redirect=None decimal=2”);
run(“Analyze Particles…”, " display exclude clear include add");
roiManager(“Select”, 0);
roiManager(“Rename”, “Orig. Target - 0”);

//Get Salient variables
fa = getResult(“FeretAngle”,0);
cx = getResult(“X”,0);
cy = getResult(“Y”,0);
ta = getResult(“Area”,0);
bx = getResult(“BX”,0);
by = getResult(“BY”,0);
bw = getResult(“Width”,0);
bh = getResult(“Height”,0);
bcx = bx + bw/2;
bcy = by + bh/2;
run(“Select All”);
icx = iw/2;
icy = ih/2;
dx = (icx - bcx);
dy = (icy - bcy);

//Translate and rotate the image to align x with the Feret max caliper line
run(“Translate…”, “x=&dx y=&dy interpolation=None”);
roiManager(“Show None”);
run(“Select None”);
run("Rotate… ", “angle=&fa grid=0 interpolation=Bicubic enlarge”);

//re-acquire the image and get it’s bounding box
doWand(icx, icy);
roiadd(“Centered Target”);
roiManager(“Select”, roiManager(“count”)-1);
Roi.getBounds(x, y, width, height);
makeRectangle(x, y, width, height);

//Fit the ellipse to the bounding box
roiManager(“Select”, 2);
run(“Fit Ellipse”);

//waitForUser(“Prior to expand”);

//Expand ellipse to contain the entire target
aa = 0;
while(targetarea > aa) {
roiManager(“Select”, newArray(1,3));
run(“Clear Results”);
aa = getResult(“Area”,0);
//print("Target Area = “+targetarea+” Anded Area = “+aa+” ta-aa = "+ targetarea-aa);
roiManager(“Select”, 3);
run(“Enlarge…”, “enlarge=1”);
roiManager(“Select”, roiManager(“count”)-2);
roiManager(“Select”, roiManager(“count”)-1);
roiManager(“Rename”,“Fit - 3”);
close(“ROI Manager”);
//End the program

//Left for the student…the following should rotate and translage the image and ellipse back



1 Like

@rondespain I would say the ellipse that has least difference with the boundaries of the image. If xi and yi are the x and y of all the points of boundary, the best ellipse would be the one that has: min(sigmasqrt((xi-xellipse)^2+(yi-yellipse)^2))) sth like this formula.

what is Elliptical Hough transform?
I read here : "image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. " is not clear. What is the main goal of hough transform?