Is it possible to minimise Feret Angle automatically?

Dear all,

I’m writing a script on Fiji. One of the intermediate steps is to minimise the Feret Angle of a single object in a 8-bits figure. I’d like to know if it possible to get the Feret Angle value and then apply this value to align the object in the figure (i.e. minimise the Feret Angle) automatically with commands.

Thank you for your attention!


1 Like

Welcome to the forum, @Cristina_Llopis!

I do not know a built-in way to do this—although I am far from knowledgeable about all of the available plugins and functions of ImageJ. Someone else might know one.

I think you could write a script to do this. But the question is: “align” in what sense? What sorts of mutation of the ROI do you want to allow? Translation? Rotation? Changing boundaries? The space of all possible discrete ROIs over an image is 2^{wh} where where w is the width of the image in pixels, and h is its height. Very computationally expensive to try all. I assume you want to do some local optimization of the ROI. Could you post a sample image illustrating what you want?

Dear @ctrueden

first of all thank you very much for your post!

My proposal is to rotate the object within the the margins of the image; and, If the object exced those margins, “enlarge the image to fit the result”.

Align, I mean orient the object parallel to the image margins.

Attached you can find a slide explaining mi proposal.
Thank you very much!

Best wishes


I do this in one of my scripts. It is fairly straightforward if you are writing an ImageJ1-style script:

First you need to get an ROI for the object.
After that you can get the Feret values of the object (e.g. myRoi.getFeretValues() )
Then rotate by the angle

I do this within the Funimage package for ImageJ, so my case probably looks a bit different from yours but for reference:

(require '[funimage.imp :as imp]
         '[funimage.imp.roi :as roi])

(def my-roi (roi/open-roi my-roi-filename))
(def my-imp (imp/open-imp my-image-filename))

(let [angle (second (seq (.getFeretValues my-roi)))]
  (imp/rotate my-imp angle))
1 Like

Dear @kephale thank your for your script, it helped me to continue with mine.
However, I couldn’t solve the problem by the moment.
Below you will find my script.
I define the Feret Angle as a varible (alpha).
Then, I rotate the image, being: angle = alpha. However, it doesn’t recognise the Feret Angle value of the object, and it rotates for a different angle value.

Thank you very much!

setAutoThreshold("Default dark");
//setOption("BlackBackground", true);
run("Convert to Mask");
run("Analyze Particles...", "display");
var alpha = getResult("FeretAngle");
run("Rotate... ", "rotate angle = alpha grid=1 interpolation=None  fill enlarge");
1 Like

I believe that the issue is that angle is within the double quotes of your rotate command, try swapping that last line with:

run("Rotate... ", "rotate angle="+alpha+" grid=1 interpolation=None fill enlarge");

Hello, this was very helpful for me - thank you @Cristina_Llopis and @kephale

Is there a way to rotate the ROI outline with the object you are rotating? TO save having to automatically select the object again?