Replace a color in image with hatchfilling
Using an input example from the documentation page for ImageGraphics
:
hilbert = Import["https://i.stack.imgur.com/F9aZB.png"]
smoothHilbert = CurvatureFlowFilter[MeanShiftFilter[hilbert, 8, 1/16], 2];
ig = ImageGraphics[smoothHilbert, 3]
colors = Cases[ig, {a_, _FilledCurve} :> a, All]
ig /. colors[[1]] -> HatchFilling[]
ig /. {colors[[1]] -> HatchFilling[],
colors[[2]] -> PatternFilling["Checkerboard", {10, 10}],
colors[[3]] -> HatchFilling[-45 Degree, 5, 10]}
Here's a way to do it without converting the image into vectorized graphics.
hilbert = Import["https://i.stack.imgur.com/F9aZB.png"];
smoothHilbert = CurvatureFlowFilter[MeanShiftFilter[hilbert, 12, 1/16], 2];
quantizedHilbert = ColorQuantize[smoothHilbert, {Black, White, Gray}, Dithering -> False];
whiteMask = ColorReplace[quantizedHilbert, Gray -> Black]
{width, height} = ImageDimensions[whiteMask];
filling = Rasterize@Graphics[{
HatchFilling[],
Rectangle[{0, 0}, {width, height}]
}, ImageSize -> {width, height}, PlotRangePadding -> None];
filling whiteMask + ColorNegate[whiteMask] quantizedHilbert