Divide ROI into 3 equal parts - align using ferets angle first

Hello all,

I have made a macro script that takes an ROI and splits it into 3 parts and calculates the mean grey value per section. It also works through all the sub-directories in a folder. - macro attached. mean_grey_wing_thirds_multiFile.ijm (2.7 KB)

This is great but I has realised a potential issue. The photos I am using are of butterfly wings. AS the ROI is divided into 3 sections using a vertical line - this may result in different areas being selected if the wing is at a different angle.

For example compare the two images below.

The area selected in second image here represents more of the area I am looking for. However, as you can see the first image, due to the positioning of the wing is selecting a larger area.

Is there a way to either: 1) make the line used to divide the area follow the angle of the edge of the wing? Not the photo? OR 2) adapt my code so it is done on actual area of the wing?

I hope I have explained my problem in enough detail - let me know if I have missed anything. I attach the two original images to help in any problem solving.

Thank you so much for your help.

I have worked out a method! It may be rather clunky but seems to do the job!

I rotate each wing using the ferets' angle to make it straight in the photo (although it goes upside-down it doesnt matter as long as the mean grey values dont change)! This then means the vertical lines are ok to use to select the thirds of the wings.

I attach my script if anyone comes across a similar issue mean_grey_wing_thirds_multiFile.ijm (4.2 KB)


Is there a way to rotate the outline of the ROI with the object? This would save me having to re-select the wing once it has been rotated, which the macro I wrote seems to struggle to do for some wings.

I have started a new issue here in case others are interested in only this problem : Rotate ROI outline with selected object