当前位置:网站首页>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;
}
#endif3、 ... 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;
}
#endifFour 、 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边栏推荐
- Basic knowledge of MySQL database (an introduction to systematization)
- ADS simulation design of class AB RF power amplifier
- 03 fastjason solves circular references
- Application of external interrupts
- Application of 51 single chip microcomputer timer
- The 4G module designed by the charging pile obtains NTP time through mqtt based on 4G network
- Serial communication based on 51 single chip microcomputer
- After clicking the Save button, you can only click it once
- Of course, the most widely used 8-bit single chip microcomputer is also the single chip microcomputer that beginners are most easy to learn
- [keil5 debugging] warning:enumerated type mixed with other type
猜你喜欢

嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走

Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program

单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇

In third tier cities and counties, it is difficult to get 10K after graduation

Not many people can finally bring their interests to college graduation

Leetcode 300 最长上升子序列

51 MCU tmod and timer configuration

Getting started with JMX, MBean, mxbean, mbeanserver

LeetCode - 460 LFU 缓存(设计 - 哈希表+双向链表 哈希表+平衡二叉树(TreeSet))*

For new students, if you have no contact with single-chip microcomputer, it is recommended to get started with 51 single-chip microcomputer
随机推荐
Synchronization control between tasks
Gif image analysis drawing RGB to YUV table lookup method to reduce CPU occupancy
Open Euler Kernel Technology Sharing - Issue 1 - kdump Basic Principles, use and Case Introduction
Opencv notes 20 PCA
STM32 running lantern experiment - library function version
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
openEuler kernel 技术分享 - 第1期 - kdump 基本原理、使用及案例介绍
When you need to use some functions of STM32, but 51 can't realize them, 32 naturally doesn't need to learn
学习开发没有捷径,也几乎不存在带路会学的快一些的情况
单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了
Problems encountered when MySQL saves CSV files
01 business structure of imitation station B project
STM32 general timer 1s delay to realize LED flashing
ADS simulation design of class AB RF power amplifier
一个可执行的二进制文件包含的不仅仅是机器指令
4G module IMEI of charging pile design
Pymssql controls SQL for Chinese queries
2020-08-23
Emballage automatique et déballage compris? Quel est le principe?