将 AxesImage 直方图转换为数组直方图
Convert AxesImage Histogram to Arrays Histogram
大家好,我的代码在下面。
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()
我得到了作为 AxesImage 的 hs 直方图,但我想转换为数组以应用于机器学习模型训练输入。你能帮我吗?
为什么我不使用 hist1c 和 hist2c 是模型的输入,因为它不是单独的 H-S 每个维度,它只保留在 H 箱中。
非常感谢你 :)
大
修改直方图数据:
np.array(hist1c).reshape(-1, yourDataSize)
大家好,我的代码在下面。
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()
我得到了作为 AxesImage 的 hs 直方图,但我想转换为数组以应用于机器学习模型训练输入。你能帮我吗? 为什么我不使用 hist1c 和 hist2c 是模型的输入,因为它不是单独的 H-S 每个维度,它只保留在 H 箱中。 非常感谢你 :) 大
修改直方图数据:
np.array(hist1c).reshape(-1, yourDataSize)