Imagemagick如何在黑白图像上合成彩色png而不丢失颜色?

Imagemagick如何在黑白图像上合成彩色png而不丢失颜色?,imagemagick,composite,grayscale,compose,Imagemagick,Composite,Grayscale,Compose,我试图用Imagemagick在灰度图像上用红点合成彩色png,但得到的结果是带有白点的黑白图像 我正在使用以下命令行: composite -tile -compose Hardlight red-dots.png image.jpg result.jpg 结果是: 在Photoshop中,我可以通过将image.jpg模式更改为RVB颜色来获得所需的内容,我可以获得: 以下是我正在使用的示例: 在ImageMagick中,有一种方法可以做到这一点 输入: 瓷砖: 结果: 另一种

我试图用Imagemagick在灰度图像上用红点合成彩色png,但得到的结果是带有白点的黑白图像

我正在使用以下命令行:

composite -tile -compose Hardlight red-dots.png image.jpg result.jpg
结果是:

在Photoshop中,我可以通过将image.jpg模式更改为RVB颜色来获得所需的内容,我可以获得:

以下是我正在使用的示例:


在ImageMagick中,有一种方法可以做到这一点

输入:

瓷砖:

结果:

另一种方法如下:

Line 1: convert command
Line 2: read the face image
Line 3: set the distort viewport to the size of the image
Line 4: read the dots image
Line 5: do a distort with no change of the image orientation or size to tile it out to the size of the face image
Line 6: do hard light composite
Line 7: save the result


convert \
man_face.jpg \
-set option:distort:viewport '%g' \
\( red_dots.png \
-virtual-pixel tile -filter point -distort SRT 0 \) \
-compose hardlight -composite \
result2.png

我几年前也有过类似的问题,不记得是怎么克服的。由于基础图像为灰度,最终图像将为灰度。我会尝试在合成前更改输入图像的颜色空间。我还将使用convert方法而不是composite方法,因为它有更多的选项。输入-颜色空间RGB
Line 1: convert command
Line 2: read the face image
Line 3: set the distort viewport to the size of the image
Line 4: read the dots image
Line 5: do a distort with no change of the image orientation or size to tile it out to the size of the face image
Line 6: do hard light composite
Line 7: save the result


convert \
man_face.jpg \
-set option:distort:viewport '%g' \
\( red_dots.png \
-virtual-pixel tile -filter point -distort SRT 0 \) \
-compose hardlight -composite \
result2.png