将轴图像直方图转换为数组直方图



大家好,我的代码在这里。

import cv2
import numpy as np
import PIL
from matplotlib import pyplot
img1 = cv2.imread('D:/MyProject/SeniorProject/Mushroom Pictures/train/Class A/IMG_9604.jpg')
img2 = cv2.imread('D:/MyProject/SeniorProject/Mushroom Pictures/train/Class A/IMG_9605.jpg')
img1_hsv = cv2.cvtColor(img1,cv2.COLOR_BGR2HSV)
img2_hsv = cv2.cvtColor(img2,cv2.COLOR_BGR2HSV)
h_bins = 18
s_bins = 32
histSize = [h_bins, s_bins]
h_ranges = [0,180]
s_ranges = [0,256]
ranges = h_ranges + s_ranges
channels = [0,1]
hist1c = cv2.calcHist([img1_hsv],channels,None,histSize,ranges,accumulate=False)
hist2c = cv2.calcHist([img2_hsv],[0],None,[180],[0,180],accumulate=False)
pyplot.imshow(hist1c,interpolation = 'nearest')
pyplot.show()

我得到了 hs 直方图作为 AxesImage,但我想转换为数组以应用于机器学习模型训练输入。你能帮我吗? 为什么我没有使用 hist1c 和 hist2c 是模型的输入,因为它不是单独的 H-S 每个变音符,它只保存在 H 箱中。 非常感谢:) 大

Rehsape 您的直方图数据:

np.array(hist1c(.reshape(-1, yourDataSize(

最新更新