python - 将 AxesImage 直方图转换为数组直方图
问题描述
大家好,我的代码如下。
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 是模型的输入,因为它不是单独的 HS 每个维度,它只保留在 H 箱中。非常感谢:) 大
解决方案
Rehsape 您的直方图数据:
np.array(hist1c).reshape(-1, yourDataSize)
推荐阅读
- python - Python Selenium - 文本中的文本,按顺序搜索网站
- javascript - The Modal do not display after pressing twice in the same row
- javascript - 我想将填充表格从另一个站点嵌入到我的 wix 站点
- assembly - 引导加载程序不工作,错误:“int13_harddisk:功能 42。LBA 超出范围”
- robotframework - 单击地图中的标记
- python - 无法在pycharm中安装cvxpy
- java - 如何使用 SearchView 过滤列表视图
- javascript - 如何访问 ECS 托管的应用程序?
- c# - 如何在 c# MEF 插件中对空洞进行分组
- java - 使用 poi 进行 Excel 渲染,一列被缩小