# 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]]];

(*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]]

• 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

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