参考博客:

OpenCV图像增强算法实现(直方图均衡化、拉普拉斯、Log、Gamma)_opencv 图像增强-CSDN博客1、//基于拉普拉斯算子的图像增强

#include <opencv2/highgui/highgui.hpp>    
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;

int main()
{
    Mat image = imread("C:/Users/roots/Desktop/1.tif", 1);
	if (image.empty())
	{
		std::cout << "打开图片失败,请检查" << std::endl;
		return -1;
	}
	cv::namedWindow("src", cv::WINDOW_NORMAL);
	imshow("src", image);
	Mat imageEnhance;
	Mat kernel = (Mat_<float>(3, 3) << 0, -1, 0, 0, 5, 0, 0, -1, 0);
	filter2D(image, imageEnhance, CV_8UC3, kernel);
	cv::namedWindow("after", cv::WINDOW_NORMAL);
	imshow("after", imageEnhance);
	waitKey();
	return 0;



}

效果:

2、//基于对数Log变换的图像增强方式

#include <opencv2/highgui/highgui.hpp>    
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;

int main(int argc, char *argv[])
{
    Mat image = imread("C:/Users/roots/Desktop/1.tif");
	Mat imageLog(image.size(), CV_32FC3);
	for (int i = 0; i < image.rows; i++)
	{
		for (int j = 0; j < image.cols; j++)
		{
			imageLog.at<Vec3f>(i, j)[0] = log(1 + image.at<Vec3b>(i, j)[0]);
			imageLog.at<Vec3f>(i, j)[1] = log(1 + image.at<Vec3b>(i, j)[1]);
			imageLog.at<Vec3f>(i, j)[2] = log(1 + image.at<Vec3b>(i, j)[2]);
		}
	}
	//归一化到0~255  
	normalize(imageLog, imageLog, 0, 255, NORM_MINMAX);
	//转换成8bit图像显示  
	
	convertScaleAbs(imageLog, imageLog);
	cv::namedWindow("Soure", cv::WINDOW_NORMAL);
	imshow("Soure", image);
	cv::namedWindow("after", cv::WINDOW_NORMAL);
	imshow("after", imageLog);
	waitKey();
	return 0;
}

效果:

3、彩色直方图

Mat image = imread("C:/Users/roots/Desktop/1.tif", 1);
	if (image.empty())
	{
		std::cout << "打开图片失败,请检查" << std::endl;
		return -1;
	}
	cv::namedWindow("src", cv::WINDOW_NORMAL);
	imshow("src", image);
	Mat imageRGB[3];
	split(image, imageRGB);
	for (int i = 0; i < 3; i++)
	{
		equalizeHist(imageRGB[i], imageRGB[i]);
	}
	merge(imageRGB, 3, image);
	cv::namedWindow("after", cv::WINDOW_NORMAL);
	imshow("after", image);
	waitKey();
	return 0;

4、//基于伽马变换的图像增强

Mat image = imread("C:/Users/roots/Desktop/1.tif");
	Mat imageGamma(image.size(), CV_32FC3);
	
	for (int i = 0; i < image.rows; i++)
	{
		for (int j = 0; j < image.cols; j++)
		{
			imageGamma.at<Vec3f>(i, j)[0] = (image.at<Vec3b>(i, j)[0])*(image.at<Vec3b>(i, j)[0])*(image.at<Vec3b>(i, j)[0]);
			imageGamma.at<Vec3f>(i, j)[1] = (image.at<Vec3b>(i, j)[1])*(image.at<Vec3b>(i, j)[1])*(image.at<Vec3b>(i, j)[1]);
			imageGamma.at<Vec3f>(i, j)[2] = (image.at<Vec3b>(i, j)[2])*(image.at<Vec3b>(i, j)[2])*(image.at<Vec3b>(i, j)[2]);
		}
	}

	//归一化到0~255  
	normalize(imageGamma, imageGamma, 0, 255, NORM_MINMAX);
	//转换成8bit图像显示  
	convertScaleAbs(imageGamma, imageGamma);
	cv::namedWindow("src", cv::WINDOW_NORMAL);
	imshow("src", image);
	cv::namedWindow("after", cv::WINDOW_NORMAL);
	imshow("after", imageGamma);
	waitKey();
	return 0;

GitHub 加速计划 / opencv31 / opencv
77.38 K
55.71 K
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:2 个月前 )
48668119 dnn: use dispatching for Winograd optimizations 4 天前
3dace76c flann: remove unused hdf5 header 4 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐