本文介绍了使用Imagemagick将图像处理为“默认调色板”。 (例如16或256色)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在处理图像以从中提取主要颜色,例如:

  -resize'50x50'-colors' 8'-colorspace'RGB'-量化'RGB''/tmp/downsampled20190502-27373-iqgqom.png'

但是,它给我返回了很多颜色,因此我必须将它们限制在主调色板(例如白色/黑色/红色/等)中,所以我想8或16种颜色对我来说就足够了。



我认为 -colors'8'应该对其进行处理,但是,它仅从图像返回8种原色。 / p>

您对我如何提取颜色并将其转换为3位(8色调色板)有任何想法



我虽然将其转换为GIF,但是GIF包含256个调色板。

解决方案

I认为您要将所有颜色映射到8个原色 之一。因此,让我们制作一个可接受的颜色调色板:

 转换xc:red xc:lime xc:blue xc:cyan xc:magenta xc:黄色xc:白色xc:黑色+附加上的palette.gif 

并放大并查看(因为目前只有8x1像素):





现在使用这个色轮





并将所有颜色重新映射到可接受 调色板,而无需抖动:

 转换colorwheel.png +抖动-remap Palette.gif result.png 


现在使用抖动重新映射

 转换colorwheel.png-重新映射palette.gif结果。 png 





您可以制作自己的调色板-您不必使用我的颜色,也可以制作您喜欢的任何RGB / HSL,十六进制颜色,例如:

 转换xc: rgb(10,20,200) xc:#ff7832 xc: hsl(10,40 ,90) + append Palette.gif 






如果您想要结果图像中颜色的名称和十六进制值:

  convert result.png-唯一颜色txt:

样本输出

 #ImageMagick像素枚举:7,1,65535,srgb 
0,0:(65535,0,0)#FF0000红色
1,0:(0,65535,0)#00FF00青柠
2 ,0:(65535,65535,0)#FFFF00黄色
3,0:(0,0,65535)#0000FF蓝色
4,0:(65535,0,65535)#FF00FF洋红色
5,0:(0,65535,65535)#00FFFF青色
6,0:(65535,65535,65535)#FFFFFF白色


Currently I'm processing image to extract main colors from it with such:

-resize '50x50' -colors '8' -colorspace 'RGB' -quantize 'RGB' '/tmp/downsampled20190502-27373-iqgqom.png'

However, it returns me a lot of colours, so I have to limit them to the main palette (like white/black/red/etc), so I guess 8 or 16 colours would be enough for me.

I thought that -colors '8' should process it, however, it only returns primary 8 colours from the image.

Do you have any ideas about how I could extract colours and convert them to 3-bit (8-color palette)

I though convert it to GIF, however GIF contains 256 colour palette.

解决方案

I think you want to map all colours to one of 8 "primaries". So, let's make a palette of acceptable colours:

convert xc:red xc:lime xc:blue xc:cyan xc:magenta xc:yellow xc:white xc:black +append palette.gif

And enlarge it and look at it (because at the moment it is only 8x1 pixels):

Now take this colorwheel:

and remap all the colours to your "acceptable" palette without dithering:

convert colorwheel.png +dither -remap palette.gif result.png

and now remap with dithering:

convert colorwheel.png -remap palette.gif result.png

You can make your own palette - you don't have to use my colours, and you can make any RGB/HSL, hex colour you like, e.g.:

convert xc:"rgb(10,20,200)" xc:"#ff7832" xc:"hsl(10,40,90)" +append palette.gif


If you want the names and hex values of the colours in the resulting images:

convert result.png -unique-colors txt:

Sample Output

# ImageMagick pixel enumeration: 7,1,65535,srgb
0,0: (65535,0,0)  #FF0000  red
1,0: (0,65535,0)  #00FF00  lime
2,0: (65535,65535,0)  #FFFF00  yellow
3,0: (0,0,65535)  #0000FF  blue
4,0: (65535,0,65535)  #FF00FF  magenta
5,0: (0,65535,65535)  #00FFFF  cyan
6,0: (65535,65535,65535)  #FFFFFF  white

这篇关于使用Imagemagick将图像处理为“默认调色板”。 (例如16或256色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 13:38