我正在进行图像处理,以识别图像的颜色变化,并能够在直方图中绘制该数据。为此,我使用RGB颜色空间中的皮肤斑点图像。下面的代码可以获取每个像素的颜色并使用color.rgb2lab转换为HSV。但是,由于我想将其转换为L*a*b*,因为它更接近人类视觉,在Python库中没有转换为L*a*b*。因此,通过RGB的分离像素,如何将这些像素转换为LAB颜色?
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("IMD006.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
skimage http://scikit-image.org/docs/0.14.x/api/skimage.color.html#rgb2lab
或者opencv https://docs.opencv.org/3.4.3/d7/d1b/group__imgproc__misc.html#ga397ae87e1288a81d2363b61574eb8cab - deadvoid