掩膜:根据掩模版尺寸重新计算每个像素点灰度值,用于提高图片对比度
公式:,
矩阵形式:
其中,红色像素是中心像素,根据掩模版尺寸,对图像中每个像素点进行相同处理,得到地结果就是对比度提高之后的。
C++实现
int cols = (src.cols-1) * src.channels();
int offsetx = src.channels();
int rows = src.rows;
dst = Mat::zeros(src.size(), src.type());
for (int row = 1; row < (rows - 1); row++) {
const uchar* previous = src.ptr<uchar>(row - 1);
const uchar* current = src.ptr<uchar>(row);
const uchar* next = src.ptr<uchar>(row + 1);
uchar* output = dst.ptr<uchar>(row);
for (int col = offsetx; col < cols; col++) {
output[col] = saturate_cast<uchar>(3* current[col] - (current[col- offsetx] + current[col+ offsetx] + previous[col] + next[col]));
}
}
实验结果如下:
原图
处理后