#include<iostream>
#include<opencv2/opencv.hpp>
#include<math.h>
using namespace cv;
int main()
{
Mat example = imread("D:\\VC项目\\img1.jpg");
if (!example.data)
{
printf("无法打开图像!!!");
return -1;
}
imshow("example", example);
Mat outexample;
// "********方式一(源码对图像进行掩膜操作)*********************"
example.copyTo(outexample);//把原图片拷贝给outexample
int example_c = example.channels();//获取图片的通道数
int height = example.rows;//得到图片的高度
int width = example.cols;//得到图片的宽度
int cols = example.cols * example_c;//利用通道数*图片的宽度
for (int row = 1; row < height - 1; row++)
{
const uchar* previous = example.ptr<uchar>(row - 1); //获取前一行的指针
const uchar* current = example.ptr<uchar>(row);//获取当前行的指针
const uchar* next = example.ptr<uchar>(row +1);// 获取下一行的指针
uchar* output = outexample.ptr<uchar>(row);
for (int col = example_c; col < example_c * (example.cols - 1); col++)
{
*output = saturate_cast<uchar>(5 * current[col] - previous[col] - next[col] - current[col - example_c] - current[col + example_c]);
output++;
}
}
printf("输入图片的信息:\n");
std::cout << "通道数:"<<example_c<<"\n";
std::cout << "图片的大小:" << width << "*" << height;
// "********方式二(直接利用cv种的filter2D对图像进行掩膜操作)*********************"
Mat kernel = (Mat_<char>(3, 3) << 0, -1, 0, -1, 10, -1, 0, -1, 0);
filter2D(example, outexample, example.depth(), kernel);
imshow("outexample", outexample);
waitKey(0);
return 0;
}
c++ opencv实现图像对比度增强
最新推荐文章于 2024-07-25 14:04:18 发布