Mat image = imread("../lic_image/lic_image/20140209220432703.png", 1);
if (image.empty())
{
std::cout << "打开图片失败,请检查" << std::endl;
return -1;
}
imwrite("../lic_image/output/origin.png",image);
imshow("原图像", image);
Mat imageEnhance;
// cv::blur(image,image,cv::Size(5,5));
//cv::Laplacian(image,imageEnhance,CV_8U,1,1,128);
cv::Laplacian(image,imageEnhance,CV_8U,7,0.01,128);
imwrite("../lic_image/output/lapulasi.png",imageEnhance);
imshow("拉普拉斯算子图像增强效果", imageEnhance);
image=imageEnhance;
Mat imageRGB[3];
split(image, imageRGB);
for (int i = 0; i < 3; i++)
{
equalizeHist(imageRGB[i], imageRGB[i]);
}
Mat equalizeHistDist;
merge(imageRGB, 3, equalizeHistDist);
imwrite("../lic_image/output/equalizeHistDist.png",equalizeHistDist);
imshow("直方图均衡化图像增强效果", equalizeHistDist);
Mat imageLog(image.size(), CV_32FC3);
for (int i = 0; i < image.rows; i++)
{
for (int j = 0; j < image.cols; j++)
{
imageLog.at(i, j)[0] = log(1 + image.at(i, j)[0]);
imageLog.at(i, j)[1] = log(1 + image.at(i, j)[1]);
imageLog.at(i, j)[2] = log(1 + image.at(i, j)[2]);
}
}
//归一化到0~255
normalize(imageLog, imageLog, 0, 255, NORM_MINMAX);
//转换成8bit图像显示
convertScaleAbs(imageLog, imageLog);
imwrite("../lic_image/output/imageLog.png",imageLog);
imshow("imageLog图像增强效果", imageLog);
Mat imageGamma(image.size(), CV_32FC3);
for (int i = 0; i < image.rows; i++)
{
for (int j = 0; j < image.cols; j++)
{
imageGamma.at(i, j)[0] = (image.at(i, j)[0])*(image.at(i, j)[0])*(image.at(i, j)[0]);
imageGamma.at(i, j)[1] = (image.at(i, j)[1])*(image.at(i, j)[1])*(image.at(i, j)[1]);
imageGamma.at(i, j)[2] = (image.at(i, j)[2])*(image.at(i, j)[2])*(image.at(i, j)[2]);
}
}
//归一化到0~255
normalize(imageGamma, imageGamma, 0, 255, NORM_MINMAX);
//转换成8bit图像显示
convertScaleAbs(imageGamma, imageGamma);
imwrite("../lic_image/output/imageGamma.png",imageGamma);
imshow("imageGamma图像增强效果", imageGamma);
Mat new_image = Mat::zeros( image.size(), image.type() );
double alpha = 0.6; /*< Simple contrast control */
int beta = 20; /*< Simple brightness control */
for( int y = 0; y < image.rows; y++ ) {
for( int x = 0; x < image.cols; x++ ) {
for( int c = 0; c < image.channels(); c++ ) {
new_image.at(y,x)[c] =
saturate_cast( alpha*image.at(y,x)[c] + beta );
}
}
}
imwrite("../lic_image/output/imageab.png",new_image);
imshow("imageab图像增强效果", new_image);
图像模糊:image_smooth.py
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread("./lic_image/lic_image/lic_enhance/20140209215818359.png")
path="4"
kernel = np.ones((5,5),np.float32)/25
filter2D = cv.filter2D(img,-1,kernel)
blur = cv.blur(img,(5,5))
gaussianblur = cv.GaussianBlur(img,(5,5),0)
medianblur = cv.medianBlur(img,5)
bilateralblur = cv.bilateralFilter(img,9,75,75)
plt.subplot(231),plt.imshow(img),plt.title('Original')
plt.xticks([]), plt.yticks([])
cv.imwrite("./lic_image/output/"+path+"/Original.png",img)
plt.subplot(232),plt.imshow(filter2D),plt.title('filter2D')
plt.xticks([]), plt.yticks([])
cv.imwrite("./lic_image/output/"+path+"/filter2D.png",filter2D)
plt.subplot(233),plt.imshow(blur),plt.title('blur')
plt.xticks([]), plt.yticks([])
cv.imwrite("./lic_image/output/"+path+"/blur.png",blur)
plt.subplot(234),plt.imshow(gaussianblur),plt.title('gaussianblur')
plt.xticks([]), plt.yticks([])
cv.imwrite("./lic_image/output/"+path+"/gaussianblur.png",gaussianblur)
plt.subplot(235),plt.imshow(medianblur),plt.title('medianblur')
plt.xticks([]), plt.yticks([])
cv.imwrite("./lic_image/output/"+path+"/medianblur.png",medianblur)
plt.subplot(236),plt.imshow(bilateralblur),plt.title('bilateralblur')
plt.xticks([]), plt.yticks([])
cv.imwrite("./lic_image/output/"+path+"/bilateralblur.png",bilateralblur)
plt.show()