【发布时间】:2017-08-14 16:36:57
【问题描述】:
有没有办法只计算一个数字来表示图像中像素的 rgb 值?我试图将我的 ROI 颜色随 time.x 的变化可视化为我的时间函数和 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()
【问题讨论】:
-
r*(256^2) + g*256 + b? -
另外,为什么不为每个组件绘制一条线?
-
@asongtoruin 任何我可以参考这个公式的来源?
-
它只是一个基本的 256 编码。
-
@asongtoruin 我有一个图表应该是什么样子的趋势,因为颜色从淡黄色(最初的图像)变为最后图像的白色......我不确定是否在绘制每个组件将代表任何东西。
标签: python opencv image-processing matplotlib colors