I want to apply kmeans to an image with an alpha mask. It should only work on the colors that are visible. I'm hoping to one-line it. Starting image:
我想将KMeans应用于具有Alpha蒙版的图像。它应该只对可见的颜色起作用。我希望能写成一行。起始图:
Naively apply kmeans (whoops, all one color):
天真地使用KMeans(哎呀,都是一种颜色):
convert SpaceshipTransparency.png -kmeans 12x20 KmeansOnly.png
Experiment. Run through all alpha choices. -alpha remove
seems to work somehow but it has a white background? Need to remove this and I found a three step process on ImageMagick docs by outputting a mask as a middle step:
做实验。浏览所有Alpha选项。-Alpha Remove似乎有某种效果,但它的背景是白色的?需要删除它,我在ImageMagick文档上找到了一个三步过程,输出一个面具作为中间步骤:
convert SpaceshipTransparency.png -alpha Remove -kmeans 12x20 AlphaRemove.png
convert SpaceshipTransparency.png -alpha extract mask.png
convert AlphaRemove.png mask.png -alpha Off -compose CopyOpacity -composite ThreeStepProcess.png
更多回答
优秀答案推荐
You can combine commands by chaining using parenthesis processing and in-memory (MPR:) images in Imagemagick.
您可以通过在Imagemagick中使用括号处理和内存(MPR:)图像链接来组合命令。
Try:
尝试:
convert SpaceshipTransparency.png -write mpr:img +delete \
\( mpr:img -alpha Remove -kmeans 12x20 \) \
\( mpr:img -alpha extract \) \
-alpha Off -compose CopyOpacity -composite OneStepProcess.png
Note: -kmeans is only available on Imagemagick 7. So I recommend using magick rather than convert.
注意:-kMeans仅在Imagemagick7上可用。所以我建议使用Magick而不是Convert。
更多回答
我是一名优秀的程序员,十分优秀!