img = cv2.imread('img/dream.jpg')
(b,g,r)=cv2.split(img)
color = ('b','g','r')
b = cv2.calcHist([img],[0],None,[256],[0, 256])
g = cv2.calcHist([img],[1],None,[256],[0, 256])
r = cv2.calcHist([img],[2],None,[256],[0, 256])
for i, col in enumerate(color):
histr = cv2.calcHist([img],[i],None,[256],[0, 256])
plt.plot(histr, color = col)
plt.xlim([0, 256])
with open('output.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow('BGR')
for row in rows:
writer.writerow(row)
I am trying to read in a picture and show its RGB counts of each pixel. It's all cool until I tried to write my data into a csv file. Here is what it look like:
B,G,R
[0.],[0.],[631788.]
[0.],[0.],[418355.]
[0.],[0.],[105815.]
All I need is to remove the '[' and ']' from my array.
I am new to python I am not sure whether the array is tuple dictionary or something else.
I have tried the replace() method however it appear an error message 'numpy.ndarray' object has no attribute 'replace'