类似于Imagemagick Spotify的双色调叠加

时间:2018-10-17 15:35:34

标签: image-processing imagemagick

是否可以使用纯imagemagick命令达到这种程度的色彩操纵?

enter image description here

我想可以用library(ggplot2)和用于形状的特殊透明png来完成。
还需要在对颜色级别进行任何操作之前将原始颜色更改为黑白吗?

1 个答案:

答案 0 :(得分:2)

这是在Imagemagick中执行此操作的一种方法。是的,您需要遮罩图像。您可能会或可能不想将输入转换为灰度。但是在这种情况下,我怀疑您想从灰度开始。

这是我的输入内容:

enter image description here

在这里,我创建了4个简单的不重叠的矩形区域二进制掩码。但是在您的示例中,看起来黄色的一部分与绿色重叠而变成了橙色

-


enter image description here

enter image description here

enter image description here

enter image description here

然后,我创建了4个与输入大小相同的不同彩色图像,并依次将它们与每个蒙版进行合成,以保存从灰度图像创建的内存图像(mpr:img)。

合成方法:混合(50%-50%) (请注意,如果需要,可以通过更改两个数字使用-define compose:args = 50,50来应用其他混合比例,但将总数保持为100)

convert -size 100x299 xc:white -size 300x299 xc:black +append mask1.png
convert -size 100x299 xc:black -size 100x299 xc:white -size 200x299 xc:black +append mask2.png
convert -size 200x299 xc:black -size 100x299 xc:white -size 100x299 xc:black +append mask3.png
convert -size 300x299 xc:black -size 100x299 xc:white +append mask4.png


enter image description here

撰写方法:相乘

convert barn.jpg -colorspace gray -write mpr:img +delete \
mpr:img \( mpr:img -fill red -colorize 100 \) mask1.png -compose blend -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill green1 -colorize 100 \) mask2.png -compose blend -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill blue -colorize 100 \) mask3.png -compose blend -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill yellow -colorize 100 \) mask4.png -compose blend -composite \
result1.jpg


enter image description here

撰写方法:叠加

convert barn.jpg -colorspace gray -write mpr:img +delete \
mpr:img \( mpr:img -fill red -colorize 100 \) mask1.png -compose multiply -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill green1 -colorize 100 \) mask2.png -compose multiply -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill blue -colorize 100 \) mask3.png -compose multiply -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill yellow -colorize 100 \) mask4.png -compose multiply -composite \
result2.jpg


enter image description here

撰写方法:着色

convert barn.jpg -colorspace gray -write mpr:img +delete \
mpr:img \( mpr:img -fill red -colorize 100 \) mask1.png -compose overlay -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill green1 -colorize 100 \) mask2.png -compose overlay -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill blue -colorize 100 \) mask3.png -compose overlay -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill yellow -colorize 100 \) mask4.png -compose overlay -composite \
result3.jpg


enter image description here

您可以尝试其他许多撰写方法。参见https://imagemagick.org/Usage/compose/

您也可以使用+ level-colors(第二种颜色是黑色或白色)来做同样的事情。

convert barn.jpg -colorspace gray -write mpr:img +delete \
mpr:img \( mpr:img -fill red -colorize 100 \) mask1.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill green1 -colorize 100 \) mask2.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill blue -colorize 100 \) mask3.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill yellow -colorize 100 \) mask4.png -compose colorize -composite \
result4.jpg


enter image description here

convert barn.jpg -colorspace gray -write mpr:img +delete \
mpr:img \( mpr:img +level-colors black,red \) mask1.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors black,green1 \) mask2.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors black,blue \) mask3.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors black,yellow \) mask4.png -compose colorize -composite \
result5.jpg


enter image description here

您也可以使用-tint。

convert barn.jpg -colorspace gray -write mpr:img +delete \
mpr:img \( mpr:img +level-colors red,white \) mask1.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors green1,white \) mask2.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors blue,white \) mask3.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors yellow,white \) mask4.png -compose colorize -composite \
result6.jpg


enter image description here

使用不同的撰写方法,结果会有所不同。这是最后3个带有compose而不是compose color的

convert barn.jpg -colorspace gray -write mpr:img +delete \
mpr:img \( mpr:img -fill red -tint 100 \) mask1.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill green1 -tint 100 \) mask2.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill blue -tint 100 \) mask3.png -compose colorize -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill yellow -tint 100 \) mask4.png -compose colorize -composite \
result7.jpg


enter image description here

convert barn.jpg -colorspace gray -write mpr:img +delete \
mpr:img \( mpr:img +level-colors black,red \) mask1.png -compose over -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors black,green1 \) mask2.png -compose over -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors black,blue \) mask3.png -compose over -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors black,yellow \) mask4.png -compose over -composite \
result5b.jpg


enter image description here

convert barn.jpg -colorspace gray -write mpr:img +delete \
mpr:img \( mpr:img +level-colors red,white \) mask1.png -compose over -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors green1,white \) mask2.png -compose over -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors blue,white \) mask3.png -compose over -composite -write mpr:img +delete \
mpr:img \( mpr:img +level-colors yellow,white \) mask4.png -compose over -composite \
result6b.jpg


enter image description here

有关使用带有-clut函数的自定义彩色查找表图像的方法,另请参见https://imagemagick.org/Usage/color_mods/#duotone。这是该方法:

convert barn.jpg -colorspace gray -write mpr:img +delete \
mpr:img \( mpr:img -fill red -tint 100 \) mask1.png -compose over -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill green1 -tint 100 \) mask2.png -compose over -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill blue -tint 100 \) mask3.png -compose over -composite -write mpr:img +delete \
mpr:img \( mpr:img -fill yellow -tint 100 \) mask4.png -compose over -composite \
result7b.jpg


enter image description here

在我看来,这是与原始示例中使用的最接近的着色结果。