How to create a binary mask of an image
img2 = FillingTransform@
GeodesicClosing[MorphologicalBinarize[img, {.1, .5}, CornerNeighbors -> False], 10]
A smoothed outline (thanks to Rahul):
Binarize@CurvatureFlowFilter[img2, 3]
This approach uses ImageData
to work on the lines, rather than the whole image. After a few manipulations, it detects the first and last white pixel on each line and turn the whole segment to 1
(i.e. white).
img = Import["https://i.stack.imgur.com/Mw1iJ.png"]
edges = EdgeDetect[img, 2]
data = ImageData@edges;
Table[line = data[[j]]; pos = Flatten@Position[line, 1];
If[Length[pos] > 1, data[[j, pos[[1]] ;; pos[[-1]]]] = 1];
, {j, Length@data}];
Image@data
With GrowCutComponents[]
, one can obtain this :
A little bit lifting with Dilation/Erosion will probably improve the result.
How to use GrowCutComponents[]
?
you have to create the 2 masks and evaluate the following :
One can create the masks with Drawing Tools see here