2D Histogram
One dimensional histogram only needs to consider gray value, but 2D histogram needs to consider hue and saturation.
2D histogram in OpenCV
The parameters of cv2.calcHist() method are different between one-dimensional histogram and 2D histogram,parameters should be modified as follows:
- channels = [0, 1] :We need to deal with both H and S channels at the same time
- bins = [180, 256]: 180 for H channel and 256 for S channel
- range = [0, 180, 0, 256]: The value range of H is 0 to 180, and the value range of S is 0 to 256
import cv2
import numpy
本文介绍了如何使用OpenCV和Numpy进行2D直方图的计算与绘制。2D直方图不同于一维直方图,它需要考虑色调(Hue)和饱和度(Saturation)。在OpenCV中,通过cv2.calcHist()方法处理H和S通道,设置相应参数。而在Numpy中,可以使用np.histogram2d()函数。最后,利用matplotlib.pyplot.imshow()以不同颜色映射绘制2D直方图,以便更直观地理解每个点所代表的数值,x轴表示S值,y轴表示H值。
订阅专栏 解锁全文
1万+

被折叠的 条评论
为什么被折叠?



