img = cv.imread('test.jpg')
# displays the image
cv2_imshow(img)
# initialize the array to store histogram
h = np.zeros(256, np.int32)
print(h)
# get the row and column of the image
row, col = img.shape[0], img.shape[1]
# creates the histogram of the image
for i in range(0, row):
for j in range(0, col):
h[img[i, j]] += 1
plt.figure()
plt.plot(h)
plt.show()
第一张图片是我使用 for 循环得到的直方图,第二张是我使用 numpy histogram 函数得到的,这是应该得到的。 我的问题是,代码有什么问题。有关如何解决此问题的任何提示? 提前致谢