当前位置:网站首页>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])
numpy
This 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
边栏推荐
猜你喜欢
2022年华数杯C题插层熔喷完整解题思路(附代码+详细讲解视频)
Selenium的安装
测试工作管理与规范
网络——局域网和广域网
推荐一些面向 Web 开发者的杀手级网站
Leetcode 算法面试冲刺 热题 HOT 100 刷题(406 416 437 438 448)(六十九)
网络——路由器
Heap series_0x09: Example of heap corruption (illegal access + uninitialized + heap handle mismatch)
【服务器数据恢复】SAN LUN映射出错导致文件系统数据丢失的数据恢复案例
二.sizeof和strlen的区别
随机推荐
转行做程序员,从月薪5k到30k,45岁测试员道出了一路的心酸
一个程序员的水平能差到什么程度?
开源星「001 号」落地 FlyFish,欢迎登陆赢神秘大礼包!
CocosCreator接入微信小游戏
【燃】是时候展现真正的实力了!一文看懂2022华为开发者大赛技术亮点
Insert a number and sort "Suggested Favorites"
TMin - TMin是否产生溢出
ECCV 2022 | BMD: 面向无源领域自适应的类平衡多中心动态原型策略
Super hot summer air conditioner
网络——虚拟专用网和地址转换NAT
网络——IPV4地址(三)
巧用Prometheus来扩展kubernetes调度器
5G NR Paging 寻呼
网络——2021年大题解析
成为CTO,6个月被老板干死,我损失了1000万
初识C语言(1)
网络——ARP、DHCP、ICMP协议
网络——数据交换方式
三.两数交换 空指针 && 野指针 解引用问题
无需支付688苹果开发者账号,xcode13打包导出ipa,提供他人进行内测