ImageMagick: Is there an equivalent of Gimp's tool to “shrink” and “grow” a selection?

狂风中的少年 提交于 2019-12-25 03:44:46

问题


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.



来源:https://stackoverflow.com/questions/54312877/imagemagick-is-there-an-equivalent-of-gimps-tool-to-shrink-and-grow-a-sele

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!