我試圖從圖像中提取RGB分量並使用matplotlib繪製3D RGB histogrma。但我不知道我該怎麼做。如何從圖像中提取RGB並僅將RG繪製爲圖形? R爲X和G爲Y
這裏是我當前的代碼:
import cv2
import numpy as np
from scipy import ndimage
from matplotlib import pyplot as plt
img_file = 'Paw03.png'
img = cv2.imread(img_file, cv2.IMREAD_COLOR) # rgb
#hsv_img = cv2.cvtColor(img,cv2.COLOR_BGR2HSV) # hsv
rows, cols, ch = img.shape
for x in range(rows):
for y in range(cols):
if (img[x, y, 1] == img[0, 255, 0]):
break;
else:
print "Pixel:", x, y
print "R:", R
print "G:", g
print "B:", b
print "\n"
plt.plot(r, 'ro', b, 'b^')
plt.xlim([0, 255])
plt.xlabel('Pixel')
plt.ylabel('Quantity')
plt.title('Distribution of RGB in the image')
plt.show()
但它不工作!
所以,我想有三個爲:
import cv2
import numpy as np
from scipy import ndimage
from matplotlib import pyplot as plt
img_file = 'Paw03.png'
img = cv2.imread(img_file, cv2.IMREAD_COLOR) # rgb
#hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # hsv
rows, cols, ch = img.shape
for x in range(rows):
for y in range(cols):
for z in range(ch)
if (img[x, y, z] == img[0, 255, 0]):
break;
else:
print "Pixel:", x, y
print "R:", R
print "G:", g
print "B:", b
print "\n"
plt.plot(r, 'ro', b, 'b^')
plt.xlim([0, 255])
plt.xlabel('Pixel')
plt.ylabel('Quantity')
plt.title('Distribution of RGB in the image')
plt.show()
它僅適用於打印成的,也保存三次,每次像素,併爲matplotlib這是行不通的。
任何人都可以幫到我嗎?
我試過了,它像柱狀圖一樣返回給我一個輸出。但我想打印像這樣的圖像:http://machinethatsees.blogspot.com.br/2012/07/how-to-plot-color-in-3d-rgb-color-space.html,但在二維。因此,R代表X軸,G代表Y軸。你明白我了嗎?如果你能幫忙,我的電子郵件是:[email protected]。我們可以在這裏比這裏更容易溝通。謝謝你的幫助! – Lucas