# How can one get the axis of symmetry of the following egg profile [closed]

This is the binary version of the profile of an egg. Would you be so kind and let me know how to get the axis of symmetry of this profile. Thank you!

## closed as unclear what you're asking by Bob Hanlon, m_goldberg, LCarvalho, anderstood, José Antonio Díaz NavasJan 8 at 22:01

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• I see no egg in your post. – Szabolcs Jan 3 at 11:33
• Thank you for replying. The jpg is now attached. I am looking forward to your advices. – Florin Jan 3 at 17:16
• How do you define "axis of symmetry" for something that is not rigorously symmetric? You could use ImageCrop and choose the middle vertical line, among many other possibilities... – anderstood Jan 4 at 14:21

ComponentMeasurements can measure the orientation, i.e. the angle of the best-fit ellipse for you. There are cases when this doesn't work (e.g. for a square, where the best-fit ellipse is a circle and the orientation is undefined), but for an egg, that orientation should be the axis of symmetry:

img = Import["https://i.stack.imgur.com/cKk5D.jpg"];


I'll fill the egg, so the best-fit-ellipse is fit to all points in the egg, not just the contour. That way, it's less sensitive to noise (e.g. if one side of the contour contains more points than the other):

img = FillingTransform[Closing[img, 2]]


Then just measure the centroid, orientation and diameter of the best fit ellipse:

comp = ComponentMeasurements[
img, {"Centroid", "Orientation", "Length"}]


This should be what you want:

HighlightImage[img,
comp /. (index_ -> {centroid_, orientation_, length_}) :> {
Rotate[Line[{centroid - {length/2, 0}, centroid + {length/2, 0}}],
orientation]
}]


It even works if there are multiple eggs in the image, so for:

img2 = ImageAssemble[
Table[ImageRotate[ImageResize[img, 200], u*.2 + v*π/3,
Full], {u, 3}, {v, 3}]]


you get:

• Heartfelt thanks Niki! – Florin Jan 3 at 18:28
• @Florin If this answer works for you, you can accept it by clicking the checkmark sign. – Chris K Jan 4 at 19:49