当前位置:网站首页>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
边栏推荐
- is_ power_ of_ 2 judge whether it is a multiple of 2
- 我想各位朋友都应该知道学习的基本规律就是:从易到难
- Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
- The 4G module designed by the charging pile obtains NTP time through mqtt based on 4G network
- Stm32f407 key interrupt
- 干单片机这一行的时候根本没想过这么多,只想着先挣钱养活自己
- byte alignment
- 嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
- 2. Elment UI date selector formatting problem
- 学习开发没有捷径,也几乎不存在带路会学的快一些的情况
猜你喜欢
LeetCode - 673. 最长递增子序列的个数
Basic knowledge of communication interface
一个可执行的二进制文件包含的不仅仅是机器指令
Development of intelligent charging pile (I): overview of the overall design of the system
Open Euler Kernel Technology Sharing - Issue 1 - kdump Basic Principles, use and Case Introduction
QT self drawing button with bubbles
Opencv notes 20 PCA
JS foundation - prototype prototype chain and macro task / micro task / event mechanism
Embedded systems are inherently flawed. Compared with the Internet, there are so many holes that it is simply difficult to walk away from
在三线城市、在县城,很难毕业就拿到10K
随机推荐
MySQL root user needs sudo login
YOLO_ V1 summary
Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program
QT qcombobox QSS style settings
A lottery like scissors, stone and cloth (C language)
Modelcheckpoint auto save model
STM32 general timer output PWM control steering gear
03 FastJson 解决循环引用
Drive and control program of Dianchuan charging board for charging pile design
byte alignment
Getting started with JMX, MBean, mxbean, mbeanserver
JS foundation - prototype prototype chain and macro task / micro task / event mechanism
CEF download, compile project
Uniapp realizes global sharing of wechat applet and custom sharing button style
01仿B站项目业务架构
LeetCode - 460 LFU 缓存(设计 - 哈希表+双向链表 哈希表+平衡二叉树(TreeSet))*
嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
Mysql database underlying foundation column
Serial communication based on 51 single chip microcomputer
LeetCode - 508. 出现次数最多的子树元素和 (二叉树的遍历)