gpt4 book ai didi

ImageMagick kmeans with alpha transparency(带Alpha透明度的ImageMagick KMeans)

转载 作者:bug小助手 更新时间:2023-10-25 18:10:37 25 4
gpt4 key购买 nike



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蒙版的图像。它应该只对可见的颜色起作用。我希望能写成一行。起始图:


SpaceshipTransparency.png


Naively apply kmeans (whoops, all one color):

天真地使用KMeans(哎呀,都是一种颜色):


convert SpaceshipTransparency.png -kmeans 12x20 KmeansOnly.png

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

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。


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com