矩阵的掩码操作很简单。其思想是:根据掩码矩阵(也称作核)重新计算图像中每个像素的值。掩码矩阵中的值表示近邻像素值(包括该像素自身的值)对新像素值有多大影响。从数学观点看,我们用自己设置的权值,对像素邻域内的值做了个加权平均。
实现掩码操作的两种方法
- 基本的像素访问方法
void Sharpen(const Mat& myImage,Mat& Result){
CV_Assert(myImage.depth()== CV_8U); // 仅接受uchar图像
Result.create(myImage.size(),myImage.type());
const intnChannels = myImage.channels();
for(int j =1 ; j < myImage.rows-1; ++j)
{
constuchar* previous = myImage.ptr<uchar>(j - 1);
constuchar* current =myImage.ptr<uchar>(j );
constuchar* next =myImage.ptr<uchar>(j + 1);
uchar*output = Result.ptr<uchar>(j);
for(inti= nChannels;i < nChannel