# How to get a full closed contour image [closed]

In this program, I need to select the point on the contour image that has the same abscissa as the center of the contour and has the highest ordinate. However, since the contour is not full closed, the last line does not return any thing. How can I fix this problem.

edge = MorphologicalPerimeter[ColorNegate@img] // DeleteSmallComponents

coordinatescontour = PixelValuePositions[edge, 1] ;

center = Round[ComponentMeasurements[edge, "BoundingDiskCenter"][[1, 2]]];

radius = Round[ComponentMeasurements[edge, "BoundingDiskRadius"][[1, 2]]];

Show[edge,Graphics[{{Red, Circle[center, radius]}, {Green, Point[center]}}]]

(*I need to select the point on the contour which has the same abscissa as the center point and has the highest ordinate *)

Sort[Select[coordinatescontour, #[[1]] == center[[1]]&]][[1]]


## closed as off-topic by Niki Estner, user9660, m_goldberg, MarcoB, Bob HanlonJan 25 '16 at 4:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Niki Estner, Community, m_goldberg, MarcoB, Bob Hanlon
If this question can be reworded to fit the rules in the help center, please edit the question.

• After the Show command, I see the contour, a green dot, and a red circle. Can you draw a picture of the point you want returned? – bill s Jan 23 '16 at 21:39
• In coordinatescontour = [...] // DeleteSmallComponents the DeleteSmallComponents is probably a mistake. Other than that, your code seems to do what you want already. – Niki Estner Jan 24 '16 at 10:16
• @nikie, Yes! it was the mistakes that caused the problem. – BetterEnglish Jan 24 '16 at 13:31

## 1 Answer

I changed your image processing code a bit, by removing the unnecessary DeleteSmallComponents and removing the white lines using Closing. I also added a line to detect the pixel above the center.

img = Import["http://i.stack.imgur.com/nQmQI.png"];

edge = MorphologicalPerimeter[Closing[ColorNegate@img, DiskMatrix[1]]];
coordinatescontour = PixelValuePositions[edge, 1];
center = Round[ComponentMeasurements[edge, "BoundingDiskCenter"][[1, 2]]];
radius = Round[ComponentMeasurements[edge, "BoundingDiskRadius"][[1, 2]]];

top = SortBy[Select[coordinatescontour, #[[1]] == center[[1]] &], Last] // Last;

Show[
edge,
Graphics[{{Red, Circle[center, radius]},
{Green, Point[center]},
{Blue, PointSize[0.03], Point[top]}
}]
]