# Morphological extension of an image mask

The following image is a mask derived from an imaged feature which extends to the top of the frame, but due to some lighting effects the top portion doesn't come in. Bear in mind that this is one example, and the feature moves around to some degree in each measurement.

I've been dealing with this by combining this mask with it's vertically reflected cousin:

mask = ImageAdd[mask,ImageReflect[FillingTransform@Erosion[mask, DiskMatrix[2]], Top]]


But often this feature isn't quite so symmetric in the x-direction, and sometimes appears skewed from the vertical, so this solution isn't very robust.

Is there a good way to morphologically extend the mask to the top of the image?

• Your code has a typo and does not run. The brackets are not balanced. – yohbs May 12 '16 at 19:48
• @yohbs Thanks. Should work now. – dionys May 12 '16 at 20:01
• I have addressed issues like this by Hough line/edge finding (this case L/R near vertical edges) and extending these to the top of the image and then using a measure of the edge variation to synthesize the edge "noise". This does assume that the L/R edge are supposed to be staright. – John Morganthau May 12 '16 at 20:19
• You could use ComponentMeasurements to get the centroid, angle and caliper width and simply draw a line with the same location, angle and thickness. – Niki Estner May 13 '16 at 9:07
• @nikie That's a clever approach. One could probably use the major axis of the best-fit ellipse for the component and draw a line from the center to the upper edge. – dionys May 13 '16 at 9:45

mask = Import["http://i.stack.imgur.com/L60Yd.png"]