Ich versuche, die RGB-Komponenten aus einem Bild zu extrahieren und die 3D-RGB-Histogrma mit Matplotlib zu plotten. Aber ich weiß nicht, wie ich es tun kann.Wie kann man RGB aus einem Bild extrahieren und nur RG als Graph darstellen? R für X und G für Y
Hier ist mein aktueller Code:
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()
Aber es funktioniert nicht!
Also habe ich versucht, mit drei für:
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()
Es funktioniert nur für den Druck in die für und auch dreimal für jedes Pixel speichern, und für matplotlib funktioniert es nicht.
Jeder kann mir helfen?
Ich habe versucht, es gab mir eine Ausgabe wie ein Histogramm zurück. Aber ich möchte wie dieses Bild drucken: http://machinethatsees.blogspot.com.br/2012/07/how-to-plot-color-in-3d-rgb-color-space.html aber in 2D. Daher gilt R für die X-Achse und G für die Y-Achse. Hast du mich verstanden? Wenn Sie mir helfen können, lautet meine E-Mail-Adresse: [email protected] Wir können dort leichter kommunizieren als hier. Danke für deine Hilfe! – Lucas