【问题标题】:How to fade images to blue with image magic?如何使用图像魔术将图像淡化为蓝色?
【发布时间】:2019-03-19 23:29:57
【问题描述】:

很像这个问题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,结果在我的矩形图像上产生了非常拉伸的椭圆,使它们没有吸引力,因此我需要保持淡入黑色矩形,如果我可以使用这种淡化来产生淡入黑色就够了。

使用第一个命令我得到了这个,之前和之后: , 第二个命令出错并出现此错误:

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

【问题讨论】:

  • 前后图像会有所帮助。
  • @MarkSetchell 你去吧
  • 我以为你想淡出蓝色?
  • 是的,问题就在这里,它不是变蓝,而是变透明!我如何使图像魔术淡化为颜色而不是透明

标签: image-processing imagemagick png imagemagick-convert


【解决方案1】:

您可以通过 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


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

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


这是一个较小的模糊距离:

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


如果你想要更深的蓝色,那么你可以使用 -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


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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      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
      


      【讨论】:

        【解决方案4】:

        您在 Alpha 通道上进行形态学,但仅在红色和绿色通道上呢。

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-07-06
          • 2018-01-25
          • 1970-01-01
          • 1970-01-01
          • 2017-02-07
          相关资源
          最近更新 更多