当前位置:网站首页>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边栏推荐
- Drive and control program of Dianchuan charging board for charging pile design
- 使用sed替换文件夹下文件
- There is no specific definition of embedded system
- 学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
- 2.Elment Ui 日期选择器 格式化问题
- JS foundation - prototype prototype chain and macro task / micro task / event mechanism
- Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
- Sending and interrupt receiving of STM32 serial port
- It is difficult to quantify the extent to which a single-chip computer can find a job
- Google browser plug-in recommendation
猜你喜欢

JS基础-原型原型链和宏任务/微任务/事件机制

Working mode of 80C51 Serial Port

JS foundation - prototype prototype chain and macro task / micro task / event mechanism
![[untitled] proteus simulation of traffic lights based on 89C51 Single Chip Microcomputer](/img/90/4de927e797ec9c2bb70e507392bed0.jpg)
[untitled] proteus simulation of traffic lights based on 89C51 Single Chip Microcomputer

There is no shortcut to learning and development, and there is almost no situation that you can learn faster by leading the way

I think all friends should know that the basic law of learning is: from easy to difficult

单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了

LeetCode - 673. 最长递增子序列的个数

没有多少人能够最终把自己的兴趣带到大学毕业上

Opencv note 21 frequency domain filtering
随机推荐
Vscode markdown export PDF error
Circular queue related design and implementation reference 1
El table X-axis direction (horizontal) scroll bar slides to the right by default
01 business structure of imitation station B project
The data read by pandas is saved to the MySQL database
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
Opencv note 21 frequency domain filtering
My notes on the development of intelligent charging pile (III): overview of the overall design of the system software
Modelcheckpoint auto save model
Dynamic layout management
ADS simulation design of class AB RF power amplifier
Screen display of charging pile design -- led driver ta6932
Uniapp realizes global sharing of wechat applet and custom sharing button style
单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了
There is no specific definition of embedded system
QT setting suspension button
Which language should I choose to program for single chip microcomputer
Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
[keil5 debugging] warning:enumerated type mixed with other type
LeetCode - 919. 完全二叉树插入器 (数组)