有没有办法只计算一个数字来表示图像中像素的rgb值?我试图将我的ROI颜色变化随着时间的推移可视化。我的时间函数和y作为我的rgb值。最初,我平均得到的像素rgb值。例如[84 90 135] = 103并将其绘制为我的第一个点,但我意识到这可能是错误的表示?[135 90 84]也给出了相同的平均值,但它们实际上代表了不同的颜色?这意味着我会得到错误的图表。
编辑:很抱歉,最近的更新试图修复我的图表。 我不知道为什么但是我无法绘制数据的折线图,只适用于点标记或圆形标记
这样的白色时我期待当它接近白色时该值会继续增加,因为白色的十进制代码是255 255 255,所以趋势应该向上倾斜?但是我得到了结果,否则,这是我在绘制图像的b,g,r值时得到的结果,它并没有真正向我显示很多信息。
import cv2
import numpy as np
import matplotlib.pyplot as plt
path = 'R:\\xx\\'
path1 = 'R:\\xx\\'
def BlueComponent(im_file):
im = cv2.imread(im_file) #return blue value
im1 = im[788, 526]
b = im1[0]
return b
def GreenComponent(im_file):
im = cv2.imread(im_file) #return green value
im1 = im[788, 526]
g = im1[1]
return g
def RedComponent(im_file): #return red value
im = cv2.imread(im_file)
im1 = im[788, 526]
r = im1[2]
return r
myBlueList = []
myGreenList = []
myRedList = []
myList = []
num_images = 99 # number of images
dotPos = 0
for i in range(1770, 1869): # loop to auto-generate image names and run prior function
image_name = path + 'Cropped_Aligned_IMG_' + str(i) + '.png' # for loop runs from image number 1770 to 1868
myBlueList.append(BlueComponent(image_name))
myGreenList.append(GreenComponent(image_name))
myRedList.append(RedComponent(image_name))
myList.append(dotPos)
dotPos = dotPos + 0.5
print(myList)
print(myBlueList)
print(myGreenList)
print(myRedList)
for k in range(1770,1869):
a = 'Cropped_Aligned_IMG_' + str(k)
image_name = path + a + '.png'
img_file = cv2.imread(image_name)
y = [myGreenList]
x = [myList]
y1 = [myBlueList]
y2 = [myRedList]
plt.xticks(np.arange(0.0 ,50.0, 0.5), rotation='vertical' )
plt.plot(x, y, 'g.-')
plt.plot(x, y1, 'b.-')
plt.plot(x, y2, 'r.-')
plt.title('Color Decimal Code Against Time')
plt.xlabel('Time(Hours)', labelpad=10)
plt.ylabel('Colour Code')
plt.show()
答案 0 :(得分:1)
如果您只对颜色感兴趣,可以将RGB效果转换为Hue值。如果饱和度和强度也很重要,这当然是不够的。
对于中性值,这当然会失败。
请在网上搜索详细信息。
MIN = min(r,g,b)
MAX = max(r,g,b)
Hue =
如果您只对变化感兴趣,而不是对颜色感兴趣,例如使用RGB色彩之间的距离。
评论中已经提出的另一个选项是组成一个3字节的值。
您无法以直观的方式完全显示1d中的3d变化。