如何使用图像魔术将图像淡化为蓝色?

时间:2018-10-15 13:56:14

标签: image-processing imagemagick png imagemagick-convert

很像这个问题3,我试图实现一种淡入淡出但保持恒定的颜色,而不是淡入透明,如何在所有边缘淡入淡出而不是变成透明? 我尝试了以下方法:

convert doge.png -alpha set -virtual-pixel transparent -background blue  -channel A -morphology Distance Euclidean:1,20\! +channel _doge.png
convert doge.png -alpha set -virtual-pixel Blue  -channel A -morphology Distance Euclidean:1,20\! +channel _doge.png

失败。我还考虑过小插图4,它在我的非常矩形的图像上会产生非常拉伸的椭圆,使它们没有吸引力,因此,如果我可以使用此渐隐来产生渐隐,则需要将渐隐保持为黑色矩形。涂黑就足够了。

在第一个命令之前和之后,我都会得到它: BeforeAfter 第二个命令因以下错误而出错:

convert: unrecognized virtual pixel method `Blue' @ error/convert.c/ConvertImageCommand/3177.

4 个答案:

答案 0 :(得分:2)

您在Alpha通道上进行形态处理,但是红色和绿色通道呢?

startActivity(new Intent(context, YourActivity.class).putExtra("key","value"));

doge

答案 1 :(得分:2)

您可以通过Imagemagick 6中的以下操作来实现。我创建了一个黑色图像并线性地模糊了边缘,而不是通过高斯模糊。然后,我将其用作蒙版,将图像与蓝色图像混合在一起以得到结果。

convert doge.png \
\( -clone 0 -fill blue -colorize 100 \) \
\( -clone 0 -fill black -colorize 100 -virtual-pixel white -blur 100x65000 \) \
-compose over -composite \
result.png


enter image description here

您还可以使用类似高斯的模糊效果,如下所示:

convert doge.png \
\( -clone 0 -fill blue -colorize 100 \) \
\( -clone 0 -fill black -colorize 100 -virtual-pixel white -blur 0x50 \) \
-compose over -composite \
result2.png


enter image description here

这里的模糊距离较小:

convert doge.png \
\( -clone 0 -fill blue -colorize 100 \) \
\( -clone 0 -fill black -colorize 100 -virtual-pixel white -blur 20x65000 \) \
-compose over -composite \
result3.png


enter image description here

如果您想要更深的蓝色,则可以使用-level运算符进行控制:

convert doge.png \
\( -clone 0 -fill blue -colorize 100 \) \
\( -clone 0 -fill black -colorize 100 -virtual-pixel white -blur 20x65000 -level 0x50% \) \
-compose over -composite \
result4.png


enter image description here

对于Imagemagick 7,请使用magick而不是进行转换。

答案 2 :(得分:2)

emcconville出色的Imagemagick答案的一个细微变化是保持透明性,并且只对蓝色变平。

convert doge.png \
-alpha set -virtual-pixel transparent -channel A -morphology Distance Euclidean:1,20\! +channel  \
-background blue -compose over -flatten \
result.png


enter image description here

答案 3 :(得分:2)

上面已经提供了几个很好的答案,但这是一个稍微不同的方法。读取输入图像,对其进行克隆,将其着色为黑色,将其剃光一些并添加蓝色边框,使黑色透明,模糊蓝色边框,然后将其合成到原始输入上。命令可能看起来像这样...

convert input.png -bordercolor blue -fill black \
   \( +clone -colorize 100 -shave 10 -border 10 \
   -transparent black -blur 0x10 \) -composite result.png