当前位置:网站首页>Opencv gray histogram, histogram specification
Opencv gray histogram, histogram specification
2022-07-03 10:05:00 【Σίσυφος one thousand and nine hundred】
This paper mainly introduces the processing of gray histogram correlation , It includes the following aspects :
- utilize OpenCV Calculate the gray histogram of the image , And draw histogram curve
- Principle and implementation of histogram equalization
- Histogram specification ( matching ) Principle and implementation of
Gray histogram of the image
Implementation of histogram specification
The implementation of histogram specification can be divided into the following three steps :
- Calculate the cumulative histogram of the original image
- Calculate the cumulative histogram of the specified histogram
- Calculate the absolute value of the difference between the two cumulative histograms
- The gray level mapping is established according to the cumulative histogram difference
void HistSpecify(const Mat& src, const Mat& ref, Mat& result)
{
Histogram1D hist1D;
Mat src_hist = hist1D.getHistogram(src);
Mat dst_hist = hist1D.getHistogram(ref);
float src_cdf[256] = { 0 };
float dst_cdf[256] = { 0 };
// Normalize the histogram
src_hist /= (src.rows * src.cols);
dst_hist /= (ref.rows * ref.cols);
// Calculate the cumulative probability of the original histogram and the specified histogram
for (int i = 0; i < 256; i++)
{
if (i == 0)
{
src_cdf[i] = src_hist.at<float>(i);
dst_cdf[i] = dst_hist.at<float>(i);
}
else
{
src_cdf[i] = src_cdf[i - 1] + src_hist.at<float>(i);
dst_cdf[i] = dst_cdf[i - 1] + dst_hist.at<float>(i);
}
}
// The difference of cumulative probability
float diff_cdf[256][256];
for (int i = 0; i < 256; i++)
for (int j = 0; j < 256; j++)
diff_cdf[i][j] = fabs(src_cdf[i] - dst_cdf[j]);
// Build a gray level mapping table
Mat lut(1, 256, CV_8U);
for (int i = 0; i < 256; i++)
{
// The gray level of the search source is i Mapped grayscale
// and i The specified gray scale with the minimum cumulative probability difference
float min = diff_cdf[i][0];
int index = 0;
for (int j = 1; j < 256; j++)
{
if (min > diff_cdf[i][j])
{
min = diff_cdf[i][j];
index = j;
}
}
lut.at<uchar>(i) = static_cast<uchar>(index);
}
// Apply lookup table , Make histogram specification
LUT(src, lut, result);
}
summary
The gray histogram of the image can intuitively show the overall distribution of gray levels in the image , It has a good guiding role for the subsequent image processing .- Histogram equalization is to flatten the histogram of an image , Make each gray level tend to be evenly distributed , This can enhance the image contrast very well . Histogram equalization is an automatic transformation , Just input the image , The transformation function of the image can be determined . But the equalization operation of histogram is also certain , In the process of equalization, the data in the image is not selected , This may enhance the background of the image ; The gray level of the transformed image is reduced , It may cause some details to disappear ; It will compress the peak in the image histogram , Cause the unnatural contrast of the processed image .- Histogram specification , Also known as histogram matching , After specified processing, the histogram of the original image is transformed into a histogram of a specific shape ( Example in above , It is to transform the histogram of an image into the histogram of another image ). It can adjust the histogram of the image according to a preset shape , Based on the principle of equalization , By establishing the relationship between the original image and the desired image , Selectively control the histogram , Make the histogram of the original image into a specified shape. It can adjust the histogram of the image according to a preset shape . Histogram specification is based on the principle of equalization , By establishing the relationship between the original image and the desired image , Selectively control the histogram , Make the histogram of the original image into a specified shape , So as to make up for some shortcomings of histogram equalization .
边栏推荐
- Vgg16 migration learning source code
- 01仿B站项目业务架构
- Problems encountered when MySQL saves CSV files
- yocto 技術分享第四期:自定義增加軟件包支持
- 一个可执行的二进制文件包含的不仅仅是机器指令
- In third tier cities and counties, it is difficult to get 10K after graduation
- RESNET code details
- The new series of MCU also continues the two advantages of STM32 product family: low voltage and energy saving
- LeetCode - 508. 出现次数最多的子树元素和 (二叉树的遍历)
- LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)
猜你喜欢

Uniapp realizes global sharing of wechat applet and custom sharing button style

编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解

03 fastjason solves circular references

Yocto Technology Sharing Phase 4: Custom add package support

Not many people can finally bring their interests to college graduation

Basic knowledge of communication interface

Yocto technology sharing phase IV: customize and add software package support

Windows下MySQL的安装和删除

openEuler kernel 技術分享 - 第1期 - kdump 基本原理、使用及案例介紹

In third tier cities and counties, it is difficult to get 10K after graduation
随机推荐
JS基础-原型原型链和宏任务/微任务/事件机制
getopt_ Typical use of long function
LeetCode - 460 LFU 缓存(设计 - 哈希表+双向链表 哈希表+平衡二叉树(TreeSet))*
新系列单片机还延续了STM32产品家族的低电压和节能两大优势
Retinaface: single stage dense face localization in the wild
2312、卖木头块 | 面试官与狂徒张三的那些事(leetcode,附思维导图 + 全部解法)
Circular queue related design and implementation reference 1
el-table X轴方向(横向)滚动条默认滑到右边
The data read by pandas is saved to the MySQL database
(2)接口中新增的方法
After clicking the Save button, you can only click it once
Vgg16 migration learning source code
Exception handling of arm
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
自動裝箱與拆箱了解嗎?原理是什麼?
QT self drawing button with bubbles
Swing transformer details-2
El table X-axis direction (horizontal) scroll bar slides to the right by default
Swing transformer details-1
使用sed替换文件夹下文件