当前位置:网站首页>OpenCV image transformation - histogram equalization
OpenCV image transformation - histogram equalization
2022-08-09 18:26:00 【why why】
本文摘录 OpenCV Image transformation related operations in ,重点介绍 Opencv 中的直方图均衡化操作.
直方图均衡
Cameras and image sensors don’t just adapt to the naturally occurring contrast in a scene,It is also possible to manage the exposure of the image sensor to the available light levels.in a standard camera,Set the shutter and lens aperture to make sure the sensor is neither too much nor too little.然而,Usable dynamic range for the sensor,The range of contrast in a particular image tends to be too large.因此,Capture dark areas that require longer exposure times(例如阴影)There is a trade-off between bright areas that require shorter exposures,以避免饱和“白化”.在许多情况下,You can't have both in the same image.
- Histogram equalization mathematical background is to combine a distribution(The given histogram of intensity values)映射到另一个分布(A wider and ideally uniform distribution of intensity values).也就是说,We want to distribute the original distribution as evenly as possible in the new distributiony值.事实证明,A good way to solve the problem of spreading distributed values is :The remapping function should be a cumulative distribution function.如图所示,An example of a cumulative distribution function is shown,A somewhat idealized case for the original pure Gaussian density distribution.然而,Cumulative density can be applied to any distribution,The running sum of the original distribution ranges from negative to positive.
- We can use the cumulative distribution function to remap the original distribution to a uniform distribution,Just look at each in the original distributiony值,And see where in the balanced distribution it should go.For a continuous distribution the result will be an exact equilibrium,But for numeric discrete distributions,Results can be quite inconsistent.
cv2.calcHist()
直方图统计 官方文档
cv2.calcHist(
images, # 源图像
channels, # List of channels used for statistical histograms
mask, # Optional mask.if the matrix is not empty,It must be the same size as the image8位数组.
histSize, # An array of histogram sizes for each dimension.
ranges[, # Integer array of histogram bin boundaries in each dimension.
hist[, # 输出直方图
accumulate]]) # accumulation mark.如果被设置,then the histogram will not be cleared at the beginning.
# This feature enables you to compute a single histogram for several groups of arrays,或者及时更新直方图.
-> hist- 示例代码
img = mt.cv_rgb_imread('img2_gray.jpg', gray=True)
hist = cv2.calcHist([img], [0], None, [256], [0,255])
PIS(img, hist[:, 0])numpyThis histogram function can also be implemented
hist_cv = cv2.calcHist([img],[0],None,[256],[0,256])
hist_np,bins = np.histogram(img.ravel(),256,[0,256])
hist_np2 = np.bincount(img.ravel(),minlength=256)cv2.equalizeHist()
灰度图的直方图均衡化 官方文档
- 函数使用
cv2.equalizeHist(
src[, # 源图像
dst]) -> dst- 示例代码
img = mt.cv_rgb_imread('img2_gray.jpg', gray=True)
hist = cv2.calcHist(img, [0], None, [256], [0,255])
res = cv2.equalizeHist(img)
res_hist = cv2.calcHist(res, [0], None, [256], [0,255])
PIS(img, hist[:, 0], res, res_hist[:, 0], cmap='gray')参考资料
- 《学习 OpenCV3》 第十一章
- https://blog.csdn.net/qq_41895190/article/details/89646787
边栏推荐
猜你喜欢
随机推荐
Numpy数组索引/切片 多维度索引
【MySQL】源码编译MySQL8.x+升级gcc+升级cmake(亲测完整版)
SQL trill interview: send you a universal template, to?(key, each user to log on to the maximum number of consecutive monthly)
计组——大端方式和小端方式相关题目
qiucode.cn网站之文章详情实现代码块可点击按钮进行复制
No need to pay for the 688 Apple developer account, xcode13 packaged and exported ipa, and provided others for internal testing
初识C语言(1)
Nacos Jaspyt配置加密设置
Super hot summer air conditioner
Chapter 2: Creating Interactive Maps (2.4-2.6)
Qt学习第二天
ECCV 2022 | BMD: 面向无源领域自适应的类平衡多中心动态原型策略
想通这点,治好 AI 打工人的精神内耗
August 9, 2022: Build .NET apps in C# -- use the Visual Studio Code debugger to interactively debug .NET apps (won't, fail)
二.sizeof和strlen的区别
MySQL 5.5 series installation steps tutorial (graphical version)
PHP completes missing dates in date ranges/returns missing dates
Heap series_0x0A: 3 methods to solve the heap overflow problem at once
MySQL 5.5系列安装步骤教程(图解版)
3种特征分箱方法!








