遍历图像和领域操作

2018年4月23日10:50:50
总结:
1. 再将图像的未处理点进行置零操作的时候,忘记 -1 了,原来图像的行也是按照数组的排列来算的啊
 
2. 注意了:在进行循环的时候,我们要注意 j和i 是从 1 开始的,也就是说,我们不处理图像的边界

#include "mainwindow.h"
#include <QApplication>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
 
 
void sharpen(const Mat & image, Mat & result)
{
    result.create(image.size(), image.type());
    int i = image.rows;
    int j = image.cols * image.channels();
    for(int x=1; x<i-1; x++)//第一行,和最后一行无需处理
    {
        const uchar * previous = image.ptr<uchar>(x-1);
        const uchar * current = image.ptr<uchar>(x);
        const uchar * next = image.ptr<uchar>(x+1);
        uchar * data_out = result.ptr<uchar>(x);
        for(int y=3; y<j-3; y++)
        {
            data_out[y] = static_cast<uchar>(5 * current[y] - previous[y] - next[y] - current[y-3] - current[y+3]);
        }
    }
 
 
    //将未处理过的像素设为零
    result.row(0).setTo(Scalar(0,0,0));
    result.row(result.rows-1).setTo(Scalar(0,0,0));
    result.col(0).setTo(Scalar(0,0,0));
    result.col(result.cols-1).setTo(Scalar(0,0,0));
}

 
 
int main(int argc, char *argv[])
{
    Mat image = imread("a.jpg");
    Mat result;
    sharpen(image, result);
    namedWindow("原图像");
    imshow("原图像", image);
    namedWindow("锐化后图像");
    imshow("锐化后图像", result);
 
 
    waitKey();
    return 0;
 
 
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值