-->

ImageMagick: Is there an equivalent of Gimp's

2019-08-29 22:59发布

问题:

I have a black and white mask image produced with this ImageMagick command:

convert in.jpg -threshold 85% out.png

Giving me this result:

I'd like to reduce the size of each piece like if I was doing it with Gimp by selecting the white background, inverting the selection and shrink it by X pixels.

Is it possible to do it with ImageMagick and if yes, how ?

回答1:

In Imagemagick, you can use -morphology close to reduce the white holes in the black. But if you use too large a kernel size, it will start to merge the black regions together.

convert image.png -morphology open octagon:4 result.png


Here you can see with size 4, it has removed all but one white hole, but has started to connect two of the black areas.