(10)实现减色函数---实现输入和输出参数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cup160828/article/details/81044811
#include<opencv2/opencv.hpp>
#include<iostream>
#include<random>


using namespace std;
using namespace cv;


//const表明image不会在函数中被修改
void colorReduce(const Mat &image, Mat &result, int div = 64)
{
int nl = image.rows;
int nc = image.cols;
int nchannels = image.channels();
result.create(image.rows, image.cols, image.type());
for (int j = 0; j < nl; j++)
{
//获得第j行的输入和输出的地址
const uchar* data_in = image.ptr<uchar>(j);
uchar* data_out = result.ptr<uchar>(j);
for (int i = 0; i < nc*nchannels; i++)
{
//处理每个像素
data_out[i] = data_in[i] / div * div + div / 2;
//像素处理结束
}  //一行结束
}
}
int main()
{
//读入图像
Mat image = imread("C:\\Users\\Administrator\\Desktop\\1.jpg");
Mat result;
colorReduce(image,result);


//显示结果
namedWindow("Image Result");
imshow("Image Result", result);
waitKey(0);
return 0;
}

猜你喜欢

转载自blog.csdn.net/cup160828/article/details/81044811