当前位置:网站首页>Cases of OpenCV image enhancement
Cases of OpenCV image enhancement
2022-07-03 10:04:00 【Σίσυφος one thousand and nine hundred】
One 、 brief introduction
Image enhancement algorithm is a process of image distortion , To highlight some of the characteristics of the response , It is convenient for us to process the region of interest , There are generally four ways Histogram equalization 、Laplace、Log、Gamma
Two 、 Histogram equalization
The methods of image contrast enhancement can be divided into two categories : One is Direct contrast enhancement method ; The other is Indirect contrast enhancement method .
Histogram stretching and Histogram equalization Two of the most common indirect contrast enhancement methods .
Histogram stretching It is to adjust the histogram through contrast stretching , thus “ expand ” The difference between foreground and background gray , To enhance contrast , This method can be realized by linear or nonlinear methods .
Histogram equalization Then, the gray value is calculated by using the accumulation function “ adjustment ” To achieve contrast enhancement .
- advantage : This method is very useful for both background and foreground images that are too bright or too dark , This method, in particular, can bring about X Better display of bone structure in light images and better details in overexposed or underexposed photos . One of the main advantages of this method is that it is a fairly intuitive technology and reversible operation , If the equalization function is known , Then we can restore the original histogram , And the amount of calculation is not big .
- shortcoming : The disadvantage is that it doesn't choose to process the data , It may increase the contrast of background noise and reduce the contrast of useful signals ; The gray level of the transformed image is reduced , Some details disappear ; Some images , If the histogram has a peak , After treatment, the contrast is unnaturally enhanced .
Realization of color image histogram equalization :
#if 1 // Image enhancement algorithm -- Histogram equalization image enhancement
int main(int args, char* arg)
{
Mat src = imread("C:\\Users\\19473\\Desktop\\opencv_images\\88.jpg");
if (!src.data)
{
printf("could not load image....\n");
}
imshow("input_demo", src);
Mat stc_bgr[3];
Mat dst;// Enhanced image
split(src, stc_bgr); //
for (int i=0;i<3;i++)
{
equalizeHist(stc_bgr[i], stc_bgr[i]);
}
merge(stc_bgr,3,dst); // Merge
imshow(" Enhanced image ", dst);
waitKey(0);
return -1;
}
#endif
3、 ... and 、Laplace Image enhancement
Laplace operator can enhance the local image contrast .
Laplace 8 Neighborhood convolution kernel :
0 -1 0
-1 5 -1
0 -1 0
use filter2D Function to convolute the image :
#if 1 // Image enhancement algorithm -- Laplace uses convolution kernel to enhance
int main(int args, char* arg)
{
Mat src = imread("C:\\Users\\19473\\Desktop\\opencv_images\\88.jpg");
if (!src.data)
{
printf("could not load image....\n");
}
imshow("input_demo", src);
Mat dst;
Mat kernel = (Mat_<int>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
filter2D(src, dst, src.depth(), kernel);
imshow(" Enhanced image ", dst);
waitKey(0);
return -1;
}
#endif
Four 、 logarithm Log Transform image enhancement
Logarithmic transformation can expand the low gray value part of the image , Show more details in the low gray part , Compress its high gray value part , Reduce the details of high gray value parts , So as to emphasize the low gray part of the image . Change the way :
For different bases , The larger the base , The lower the gray scale, the stronger the gray scale , The stronger the compression of the high gray part .
#if 1 // Image enhancement algorithm --log Transform enhancement
int main(int args, char* arg)
{
Mat src = imread("C:\\Users\\19473\\Desktop\\opencv_images\\613.png");
if (!src.data)
{
printf("could not load image....\n");
}
imshow(" Original image ", src);
// Be careful : CV_32FC3
Mat dst(src.size(), CV_32FC3);
for (int i = 0; i < src.rows; i++)
{
for (int j = 0; j < src.cols; j++)
{
// Yes bgr Each channel of is calculated
dst.at<Vec3f>(i, j)[0] = log(1 + src.at<Vec3b>(i, j)[0]);
dst.at<Vec3f>(i, j)[1] = log(1 + src.at<Vec3b>(i, j)[1]);
dst.at<Vec3f>(i, j)[2] = log(1 + src.at<Vec3b>(i, j)[2]);
}
}
// normalization
normalize(dst, dst, 0, 255, CV_MINMAX);
convertScaleAbs(dst, dst);
imshow(" Enhanced image ", dst);
waitKey(0);
return -1;
}
#endif
5、 ... and 、 Image enhancement of gamma transform
Gamma transform is mainly used for image correction , Correct the image with too high or too low gray level , Enhance contrast . The transformation formula is to multiply each pixel value on the original image :
Gamma transform is low for image contrast , And the overall brightness value is high ( For camera overexposure ) In this case, the image enhancement effect is obvious .
#if 1 // Image enhancement algorithm --gamma
int Gamma = 2;
int main(int args, char* arg)
{
Mat src = imread("C:\\Users\\19473\\Desktop\\opencv_images\\88.jpg");
if (!src.data)
{
printf("could not load image....\n");
}
imshow(" Original image ", src);
// Be careful : CV_32FC3
Mat dst(src.size(), CV_32FC3);
for (int i = 0; i < src.rows; i++)
{
for (int j = 0; j < src.cols; j++)
{
// Yes bgr Each channel of is calculated
dst.at<Vec3f>(i, j)[0] = pow(src.at<Vec3b>(i, j)[0], Gamma);
dst.at<Vec3f>(i, j)[1] = pow(src.at<Vec3b>(i, j)[1], Gamma);
dst.at<Vec3f>(i, j)[2] = pow(src.at<Vec3b>(i, j)[2], Gamma);
}
}
// normalization
normalize(dst, dst, 0, 255, CV_MINMAX);
convertScaleAbs(dst, dst);
imshow(" Enhanced image ", dst);
waitKey(0);
return -1;
}
#endif
边栏推荐
- 2312、卖木头块 | 面试官与狂徒张三的那些事(leetcode,附思维导图 + 全部解法)
- Design of charging pile mqtt transplantation based on 4G EC20 module
- Yocto technology sharing phase IV: customize and add software package support
- My 4G smart charging pile gateway design and development related articles
- Crash工具基本使用及实战分享
- [untitled] proteus simulation of traffic lights based on 89C51 Single Chip Microcomputer
- 03 FastJson 解决循环引用
- 在三线城市、在县城,很难毕业就拿到10K
- JS foundation - prototype prototype chain and macro task / micro task / event mechanism
- LeetCode - 508. 出现次数最多的子树元素和 (二叉树的遍历)
猜你喜欢
STM32 interrupt switch
Embedded systems are inherently flawed. Compared with the Internet, there are so many holes that it is simply difficult to walk away from
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
Timer and counter of 51 single chip microcomputer
Oracle database SQL statement execution plan, statement tracking and optimization instance
[untitled] proteus simulation of traffic lights based on 89C51 Single Chip Microcomputer
Education is a pass and ticket. With it, you can step into a higher-level environment
Idea remote breakpoint debugging jar package project
Quelle langue choisir pour programmer un micro - ordinateur à puce unique
2021-10-28
随机推荐
(1) 什么是Lambda表达式
MySQL 数据库基础知识(系统化一篇入门)
一个可执行的二进制文件包含的不仅仅是机器指令
openEuler kernel 技术分享 - 第1期 - kdump 基本原理、使用及案例介绍
I think all friends should know that the basic law of learning is: from easy to difficult
Tensorflow built-in evaluation
Mysql database underlying foundation column
新系列单片机还延续了STM32产品家族的低电压和节能两大优势
在三线城市、在县城,很难毕业就拿到10K
Stm32f04 clock configuration
4G module designed by charging pile obtains signal strength and quality
编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解
01仿B站项目业务架构
STM32 general timer output PWM control steering gear
On the problem of reference assignment to reference
Opencv notes 17 template matching
Of course, the most widely used 8-bit single chip microcomputer is also the single chip microcomputer that beginners are most easy to learn
Leetcode 300 最长上升子序列
2020-08-23
Happy Dragon Boat Festival—— Zongzi written by canvas~~~~~