如何在 ImageMagick 上过滤 4 种不同的颜色?
How to filter 4 different colours on ImageMagick?
我正在使用 ImageMagick 将图像转换为 x 和 y 笛卡尔坐标。我在命令行中使用的代码可以很好地使所有行显示为全黑,而空格显示为全白。有没有办法过滤更多颜色?例如,如果图像由多种颜色组成,有没有办法让所有红色系的颜色都变成红色,所有的蓝色系颜色变成蓝色,其他非白色的颜色变成黑色?然后背景将被视为全白(我将大多数图像用作白色背景上的图片)。命令行文本为:
转换 "imagename".png -white-threshold 50% -black-threshold 50% txt:
使用下面的 Mark Setchell 代码,我尝试转换我使用绘画创建的这个基本图像以测试 IM 的能力。
我稍微编辑了代码,使背景填充为白色而不是黑色;
convert q.png -write MPR:orig -delete 0 -compose lighten ^ ( MPR:orig -fuzz 10% -fill red -opaque red -fill white +opaque red ) ^ ( MPR:orig -fuzz 10% -fill blue -opaque blue -fill white +opaque blue ) -composite ^ ( MPR:orig -fuzz 10% -fill lime -opaque lime -fill white +opaque lime ) -composite ^ f.png
然而,整个图像只是显示白色。有什么建议吗?
不太确定你想要什么,但也许这会让我们更接近。所以,我们从这个开始:
然后我们这样做,它说 "make anything within 10% of red into solid red, anything within 25% of blue into solid blue, and so on":
convert start.png -fuzz 10% \
-fill red -opaque red \
-fuzz 25% \
-fill blue -opaque blue \
-fill lime -opaque lime \
-fill white -opaque white result.png
或者更像这样:
convert start.png -write MPR:orig -delete 0 -compose lighten \
\( MPR:orig -fuzz 10% -fill red -opaque red -fill black +opaque red \) \
\( MPR:orig -fuzz 20% -fill blue -opaque blue -fill black +opaque blue \) -composite \
\( MPR:orig -fuzz 30% -fill lime -opaque lime -fill black +opaque lime \) -composite \
result.png
也就是说... "Take the original image and make a copy in the Magick Persistent Register called orig
then delete the original. Set the blending mode to select the lightest pixel at each location for any future composite
commands. Now make a new layer, fill it with the original image, make anything within 10% of red into solid red and make anything else black. Now do the same for colours within 20% of blue and blend taking the lighter layer - so the blues and reds show instead of the blacks which will always be darkest. Do the same again for lime - which is how ImageMagick refers to pure green.""
请注意绿色比蓝色大,而蓝色又比红色大,因为我应用了不同数量的绒毛 - 即 30%、20% 10%。
我 认为 看起来像这样 Windows-style 引用:
convert start.png -write MPR:orig -delete 0 -compose lighten ^
( MPR:orig -fuzz 10% -fill red -opaque red -fill black +opaque red ) ^
( MPR:orig -fuzz 20% -fill blue -opaque blue -fill black +opaque blue ) -composite ^
( MPR:orig -fuzz 30% -fill lime -opaque lime -fill black +opaque lime ) -composite ^
result.png
我正在使用 ImageMagick 将图像转换为 x 和 y 笛卡尔坐标。我在命令行中使用的代码可以很好地使所有行显示为全黑,而空格显示为全白。有没有办法过滤更多颜色?例如,如果图像由多种颜色组成,有没有办法让所有红色系的颜色都变成红色,所有的蓝色系颜色变成蓝色,其他非白色的颜色变成黑色?然后背景将被视为全白(我将大多数图像用作白色背景上的图片)。命令行文本为:
转换 "imagename".png -white-threshold 50% -black-threshold 50% txt:
使用下面的 Mark Setchell 代码,我尝试转换我使用绘画创建的这个基本图像以测试 IM 的能力。
我稍微编辑了代码,使背景填充为白色而不是黑色;
convert q.png -write MPR:orig -delete 0 -compose lighten ^ ( MPR:orig -fuzz 10% -fill red -opaque red -fill white +opaque red ) ^ ( MPR:orig -fuzz 10% -fill blue -opaque blue -fill white +opaque blue ) -composite ^ ( MPR:orig -fuzz 10% -fill lime -opaque lime -fill white +opaque lime ) -composite ^ f.png
然而,整个图像只是显示白色。有什么建议吗?
不太确定你想要什么,但也许这会让我们更接近。所以,我们从这个开始:
然后我们这样做,它说 "make anything within 10% of red into solid red, anything within 25% of blue into solid blue, and so on":
convert start.png -fuzz 10% \
-fill red -opaque red \
-fuzz 25% \
-fill blue -opaque blue \
-fill lime -opaque lime \
-fill white -opaque white result.png
或者更像这样:
convert start.png -write MPR:orig -delete 0 -compose lighten \
\( MPR:orig -fuzz 10% -fill red -opaque red -fill black +opaque red \) \
\( MPR:orig -fuzz 20% -fill blue -opaque blue -fill black +opaque blue \) -composite \
\( MPR:orig -fuzz 30% -fill lime -opaque lime -fill black +opaque lime \) -composite \
result.png
也就是说... "Take the original image and make a copy in the Magick Persistent Register called orig
then delete the original. Set the blending mode to select the lightest pixel at each location for any future composite
commands. Now make a new layer, fill it with the original image, make anything within 10% of red into solid red and make anything else black. Now do the same for colours within 20% of blue and blend taking the lighter layer - so the blues and reds show instead of the blacks which will always be darkest. Do the same again for lime - which is how ImageMagick refers to pure green.""
请注意绿色比蓝色大,而蓝色又比红色大,因为我应用了不同数量的绒毛 - 即 30%、20% 10%。
我 认为 看起来像这样 Windows-style 引用:
convert start.png -write MPR:orig -delete 0 -compose lighten ^
( MPR:orig -fuzz 10% -fill red -opaque red -fill black +opaque red ) ^
( MPR:orig -fuzz 20% -fill blue -opaque blue -fill black +opaque blue ) -composite ^
( MPR:orig -fuzz 30% -fill lime -opaque lime -fill black +opaque lime ) -composite ^
result.png