I have an outline which I have extracted from an image, which may well not entirely closed, for instance:
I now want to fill the inside of this, as another image, using the convex hull if it is not closed.
For instance:
img = Import["https://i.stack.imgur.com/yC9ym.png"];
ConvexHullMesh[PixelValuePositions[img, 1]]
is the right shape, but is a mesh rather than an image and now in a different coordinate system.
FillingTransform
doesn't seem to work, presumably because the outline is not complete. ComponentMeasurements[img, "ConvexVertices"]
gives me the points that make up the convex hull, but I can't manage to fill in the middle in an easy (and ideally fast way).
Rasterizing the ConvexHullMesh
has been suggested in the comments, but that doesn't appear to work for me, as the ConvexHullMesh
zooms into the image.
HighlightImage[Rasterize[ConvexHullMesh[PixelValuePositions[img, 1]],
RasterSize -> ImageDimensions[img]], img]
$Version
(* "11.3.0 for Mac OS X x86 (64-bit) (March 7, 2018)" *)
ConvexHullMesh
works as desired, what aboutRasterize[ConvexHullMesh[PixelValuePositions[img, 1]], RasterSize -> ImageDimensions[img]]
? $\endgroup$HighlightImage[ ColorNegate@ Binarize[Rasterize[ConvexHullMesh[PixelValuePositions[img, 1]], RasterSize -> ImageDimensions[img]]], img]
- the rasterized image is now zoomed in. $\endgroup$11.3
btw. Can you add an image of yourHighlightImage
to the question? $\endgroup$ConvextHullMesh
is just slightly larger, which seems logical since it needs to contain all the points. $\endgroup$