2
$\begingroup$

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!

enter image description here

$\endgroup$

closed as unclear what you're asking by Bob Hanlon, m_goldberg, LCarvalho, anderstood, José Antonio Díaz Navas Jan 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.

  • 7
    $\begingroup$ I see no egg in your post. $\endgroup$ – Szabolcs Jan 3 at 11:33
  • $\begingroup$ Thank you for replying. The jpg is now attached. I am looking forward to your advices. $\endgroup$ – Florin Jan 3 at 17:16
  • $\begingroup$ 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... $\endgroup$ – anderstood Jan 4 at 14:21
9
$\begingroup$

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]
    }]

enter image description here

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:

enter image description here

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.