当前位置:网站首页>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
- Google browser plug-in recommendation
- Leetcode 300 最长上升子序列
- A lottery like scissors, stone and cloth (C language)
- Which language should I choose to program for single chip microcomputer
- QT detection card reader analog keyboard input
- LeetCode - 895 最大频率栈(设计- 哈希表+优先队列 哈希表 + 栈) *
- I think all friends should know that the basic law of learning is: from easy to difficult
- Opencv note 21 frequency domain filtering
猜你喜欢
Education is a pass and ticket. With it, you can step into a higher-level environment
SCM career development: those who can continue to do it have become great people. If they can't endure it, they will resign or change their careers
QT self drawing button with bubbles
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
SCM is now overwhelming, a wide variety, so that developers are overwhelmed
嵌入式系统没有特别明确的定义
LeetCode - 919. 完全二叉树插入器 (数组)
Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
Yocto Technology Sharing Phase 4: Custom add package support
随机推荐
There is no shortcut to learning and development, and there is almost no situation that you can learn faster by leading the way
手机都算是单片机的一种,只不过它用的硬件不是51的芯片
[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)
学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
单片机学到什么程度能找到工作,这个标准不好量化
01 business structure of imitation station B project
要选择那种语言为单片机编写程序呢
LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)
LeetCode - 919. 完全二叉树插入器 (数组)
03 FastJson 解决循环引用
Windows下MySQL的安装和删除
03 FastJson 解决循环引用
Vscode markdown export PDF error
干单片机这一行的时候根本没想过这么多,只想着先挣钱养活自己
Which language should I choose to program for single chip microcomputer
要選擇那種語言為單片機編寫程序呢
STM32 interrupt switch
Synchronization control between tasks
Gif image analysis drawing RGB to YUV table lookup method to reduce CPU occupancy
Opencv notes 20 PCA