当前位置:网站首页>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 .
边栏推荐
- 要选择那种语言为单片机编写程序呢
- Screen display of charging pile design -- led driver ta6932
- Application of external interrupts
- Opencv note 21 frequency domain filtering
- Stm32f407 key interrupt
- YOLO_ V1 summary
- 03 FastJson 解决循环引用
- RESNET code details
- 学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
- 2312、卖木头块 | 面试官与狂徒张三的那些事(leetcode,附思维导图 + 全部解法)
猜你喜欢
QT is a method of batch modifying the style of a certain type of control after naming the control
Windows下MySQL的安装和删除
单片机学到什么程度能找到工作,这个标准不好量化
03 FastJson 解决循环引用
When you need to use some functions of STM32, but 51 can't realize them, 32 naturally doesn't need to learn
单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇
没有多少人能够最终把自己的兴趣带到大学毕业上
Retinaface: single stage dense face localization in the wild
Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program
应用最广泛的8位单片机当然也是初学者们最容易上手学习的单片机
随机推荐
Development of intelligent charging pile (I): overview of the overall design of the system
QT detection card reader analog keyboard input
MySQL root user needs sudo login
Getting started with JMX, MBean, mxbean, mbeanserver
I didn't think so much when I was in the field of single chip microcomputer. I just wanted to earn money to support myself first
Simple use of MySQL (addition, deletion, modification and query)
Vgg16 migration learning source code
Education is a pass and ticket. With it, you can step into a higher-level environment
There is no specific definition of embedded system
Exception handling of arm
Yocto Technology Sharing Phase 4: Custom add package support
没有多少人能够最终把自己的兴趣带到大学毕业上
Installation and removal of MySQL under Windows
Swing transformer details-2
03 fastjason solves circular references
4G module initialization of charge point design
编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解
Screen display of charging pile design -- led driver ta6932
LeetCode - 919. 完全二叉树插入器 (数组)
Sending and interrupt receiving of STM32 serial port