python颜色代码表_python-如何使用opencv创建LAB颜色图表?

我正在开发一个项目,该项目以识别某些斑点的颜色为起点,为此,我正在绘制具有这些图像RGB颜色的3D图形.由此,我确定了这些斑点的一些醒目的颜色,如下所示.

ucnt1.png

颜色是理解的主观性和解释性的问题.此步骤的目的是进行识别,以便您可以找到颜色的图案而不会造成差异.有了这个,我一直在搜索互联网,为此,建议使用color space L * a * b *.

有了这个,有人可以帮我获得带有LAB颜色的图表,还是指出另一种更好地对这些斑点的颜色进行分类的方法?

用于绘制3D图形的代码

import numpy as np

import mpl_toolkits.mplot3d.axes3d as p3

import matplotlib.pyplot as plt

import colorsys

from PIL import Image

# (1) Import the file to be analyzed!

img_file = Image.open("IMD405.png")

img = img_file.load()

# (2) Get image width & height in pixels

[xs, ys] = img_file.size

max_intensity = 100

hues = {}

# (3) Examine each pixel in the image file

for x in xrange(0, xs):

for y in xrange(0, ys):

# (4) Get the RGB color of the pixel

[r, g, b] = img[x, y]

# (5) Normalize pixel color values

r /= 255.0

g /= 255.0

b /= 255.0

# (6) Convert RGB color to HSV

[h, s, v] = colorsys.rgb_to_hsv(r, g, b)

# (7) Marginalize s; count how many pixels have matching (h, v)

if h not in hues:

hues[h] = {}

if v not in hues[h]:

hues[h][v] = 1

else:

if hues[h][v] < max_intensity:

hues[h][v] += 1

# (8) Decompose the hues object into a set of one dimensional arrays we can use with matplotlib

h_ = []

v_ = []

i = []

colours = []

for h in hues:

for v in hues[h]:

h_.append(h)

v_.append(v)

i.append(hues[h][v])

[r, g, b] = colorsys.hsv_to_rgb(h, 1, v)

colours.append([r, g, b])

# (9) Plot the graph!

fig = plt.figure()

ax = p3.Axes3D(fig)

ax.scatter(h_, v_, i, s=5, c=colours, lw=0)

ax.set_xlabel('Hue')

ax.set_ylabel('Value')

ax.set_zlabel('Intensity')

fig.add_axes(ax)

plt.savefig('plot-IMD405.png')

plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值