当前位置:网站首页>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
边栏推荐
- 使用sed替换文件夹下文件
- Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
- Stm32 NVIC interrupt priority management
- YOLO_ V1 summary
- QT self drawing button with bubbles
- 03 FastJson 解决循环引用
- 单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇
- 手机都算是单片机的一种,只不过它用的硬件不是51的芯片
- Development of intelligent charging pile (I): overview of the overall design of the system
- Qcombox style settings
猜你喜欢
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
Leetcode 300 最长上升子序列
Uniapp realizes global sharing of wechat applet and custom sharing button style
在三线城市、在县城,很难毕业就拿到10K
RESNET code details
Oracle database SQL statement execution plan, statement tracking and optimization instance
Exception handling of arm
An executable binary file contains more than machine instructions
Idea remote breakpoint debugging jar package project
随机推荐
QT setting suspension button
STM32 general timer 1s delay to realize LED flashing
Positive and negative sample division and architecture understanding in image classification and target detection
Mobile phones are a kind of MCU, but the hardware it uses is not 51 chip
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
MySQL root user needs sudo login
Emballage automatique et déballage compris? Quel est le principe?
[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)
QT self drawing button with bubbles
01 business structure of imitation station B project
LeetCode - 673. 最长递增子序列的个数
Embedded systems are inherently flawed. Compared with the Internet, there are so many holes that it is simply difficult to walk away from
2.Elment Ui 日期选择器 格式化问题
Modelcheckpoint auto save model
使用密钥对的形式连接阿里云服务器
Drive and control program of Dianchuan charging board for charging pile design
Which language should I choose to program for single chip microcomputer
LeetCode - 919. 完全二叉树插入器 (数组)
Getting started with JMX, MBean, mxbean, mbeanserver
Vscode markdown export PDF error