获取图像像素指针
Mat.ptr<uchar>(int i=0) /*获取像素矩阵的指针,索引i表示第几行,从0开始计行数。*/
const uchar* current = myImage.ptr<uchar>(row );/*获得当前行指针*/
p(row, col) = current[col] /*获取当前像素点P(row, col)的像素值*/
像素范围处理saturate_cast<uchar>,防止溢出
saturate_cast<uchar> (x<0),返回0;
saturate_cast<uchar> (x>255),返回255;
saturate_cast<uchar> (x>=0 && x<=255),返回x;
该函数的功能:确保RGB值的范围在0~255之间
掩膜操作实现图像对比度的调整
红色是中心像素,从上到下,从左到右对每个像素做同样的处理操作,得到最终结果就是对比度提高之后的输出图像Mat对象。示例:
#include <opencv2\opencv.hpp>
#include <iostream>
#include <cmath>
using namespace cv;