问题描述
我有一个黑白面具图像使用以下 ImageMagick 命令生成:
I have a black and white mask image produced with this ImageMagick command:
convert in.jpg -threshold 85% out.png
给我这个结果:
我想减小每片的大小,就像我用 Gimp 那样,通过选择白色背景,将选择内容反转并通过X缩小 来减小尺寸像素.
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.
是否可以使用 ImageMagick 做到这一点,如果可以,怎么办?
Is it possible to do it with ImageMagick and if yes, how ?
推荐答案
在Imagemagick中,可以使用-morphology close减少黑色中的白洞.但是,如果您使用太大的内核,它将开始将黑色区域合并在一起.
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
在这里您可以看到尺寸为4的产品,它去除了除一个白洞之外的所有白洞,但已开始连接两个黑色区域.
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.
这篇关于ImageMagick:是否有相当于Gimp的工具来“缩小"图像?和“成长"一个选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!