使用rmagick像Photoshop一样给图像上色

4

我有这样一个基础图像:

enter image description here

在 Photoshop 中,我使用基本的图层颜色叠加,RGB 颜色值为:

r: 244, g: 93, b: 0

这给了我非常鲜艳的结果:

enter image description here

我试图做的是在 rmagick 中给同一张图片上色,所以如果我使用以下代码进行着色:

  img = Magick::Image.read('brush.png').first
  img = img.colorize(100, 100, 100, Magick::Pixel.new(244, 93, 0, 1))
  img.format = 'png'
  img.to_blob

它给了我这个非常清淡的橙色图像:

enter image description here

我的问题是,如何使用imagemagick / rmagick中的rgb参数给这个图像上色,以获得与我在photoshop中获得的同样鲜艳的颜色。

谢谢。

2个回答

3
在命令行中,我认为您需要这样做:
convert brush.png \( +clone -fill "rgb(244,93,0)" -colorize 100% \) -compose colorize  -composite out.png

这里输入图片描述

使用+clone选项,创建与图像大小相同的另一层,并将它完全填充为橙色。然后使用-composite合成操作将它与原始图像混合,以使透明度和颜色融合。

我不太熟悉Ruby语言,但大致上应该是这样的:

#!/usr/bin/ruby

require 'RMagick'
include Magick
infile=ARGV[0]
img=Magick::Image.read(infile).first
w=img.columns
h=img.rows
ovl=Image.new(w,h){self.background_color=Magick::Pixel.new(244*256,93*256,0)}
img.composite!(ovl,0,0,Magick::ColorizeCompositeOp)
img.write('result.png')

非常感谢这个!但是我想用 rmagick 来完成它,不太确定如何在 Ruby 中进行转换。而且这个还不太对,你能看到边缘周围的“污点”不是白色而是暗淡和灰色的。这里的明亮白色也非常重要。我真的很感激你的帮助。 - CafeHey
你安装的ImageMagick版本是什么?这可能会有所不同。 - CafeHey

2

Mark Setchell的命令行对我(Windows)有效,稍作修改即可...

convert greyscale.png +clone -fill "rgb(244,93,0)" -colorize 100% -compose colorize -composite colour.png

在rmagick中发现了这个重新上色的链接... ftp://belagro.com/Redmine/ruby/lib/ruby/gems/1.8/gems/rmagick-2.12.0/doc/colorize.rb.html

以上面链接中的代码为基础,去掉灰度转换后,下面的示例是否可以正常工作(我没有Ruby)?

# load the greyscale image
img = Magick::Image.read('greyscale.png').first
# Colorize with a 100% blend of the orange color
colorized = img.colorize(1, 1, 1, '#A50026')
# save the colour image
colorized.write('colour.png')

使用颜色选择器获取您的橙色颜色的十六进制值 - rgb(244,93,0) = #A50026


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接