当前位置:网站首页>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
边栏推荐
- 无需支付688苹果开发者账号,xcode13打包导出ipa,提供他人进行内测
- 我的第一篇博客
- ECCV 2022 | BMD: 面向无源领域自适应的类平衡多中心动态原型策略
- Leading practice | How the world's largest wine app uses design sprint to innovate the vivino model
- ESP8266-Arduino编程实例-MQ-6异丁烷丙烷传感器驱动
- Heap series_0x09: Example of heap corruption (illegal access + uninitialized + heap handle mismatch)
- How to create DataFrame with feature importance from XGBClassifier made by GridSearchCV?
- 【嵌入式入门篇】嵌入式0基础沉浸式刷题篇1
- No need to pay for the 688 Apple developer account, xcode13 packaged and exported ipa, and provided others for internal testing
- 2022年华数杯C题插层熔喷完整解题思路(附代码+详细讲解视频)
猜你喜欢
开源星「001 号」落地 FlyFish,欢迎登陆赢神秘大礼包!
uni-app中websocket的使用 断开重连、心跳机制
图像几何校正
Detailed explanation of three pieces in C language
[Server data recovery] Data recovery case of file system data loss caused by SAN LUN mapping error
MySQL 5.5系列安装步骤教程(图解版)
Optimization of a piece of JDBC code (Part 1)
想通这点,治好 AI 打工人的精神内耗
网络——介质访问控制
如何让button中的内容分两行显示
随机推荐
Chapter 2: Creating Interactive Maps (2.4-2.6)
五.初始指针
分布式恢复【进阶篇】
网络——IPV4地址(二)
map和set容器
【Web渗透】信息收集篇——Google搜索引擎(一)
苹果开发者账号 申请 D-U-N-S 编号
ESP8266-Arduino编程实例-MQ-5液化天然气传感器驱动
2022年深圳杯数学建模A题代码思路-- 破除“尖叫效应”与“回声室效应”,走出“信息茧房”
【科普】关于平板电脑的那些事
The Chinese Academy of Sciences slaps Google in the face: ordinary computers catch up with quantum superiority, and can solve calculations that would have taken 10,000 years in a few hours...
ESP8266-Arduino编程实例-MQ-6异丁烷丙烷传感器驱动
Became CTO, was killed by my boss in 6 months, I lost 10 million
小心使用C语言realloc()函数!!!
MySQL索引的B+树到底有多高?
5G NR Paging 寻呼
Numpy数组索引/切片 多维度索引
uniapp 项目搭建
2019强网杯高明的黑客
2.1、基于并行上下文注意网络的场景文本图像超分辨率