图像处理——锐化

图像锐化


代码展示

#include<opencv2\opencv.hpp>
using namespace cv;




Mat& imgSharpen(const Mat& img, char* arith)       //arith为3*3模板算子
{
    int rows = img.rows;        //原图的行
    int cols = img.cols * img.channels();   //原图的列
    int offsetx = img.channels();       //像素点的偏移量

    static Mat dst = Mat::ones(img.rows - 2, img.cols - 2, img.type());

    for (int i = 1; i < rows - 1; i++)
    {
        const uchar* previous = img.ptr<uchar>(i - 1);
        const uchar* current = img.ptr<uchar>(i);
        const uchar* next = img.ptr<uchar>(i + 1);
        uchar* output = dst.ptr<uchar>(i - 1);
        for (int j = offsetx; j < cols - offsetx; j++)
        {
            output[j - offsetx] =
                saturate_cast<uchar>(previous[j - offsetx] * arith[0] + previous[j] * arith[1] + previous[j + offsetx] * arith[2] +
                    current[j - offsetx] * arith[3] + current[j] * arith[4] + current[j + offsetx] * arith[5] +
                    next[j - offsetx] * arith[6] + next[j] * arith[7] + next[j - offsetx] * arith[8]);
        }
    }
    return dst;
}
int main()
{
    Mat img = imread("D:\\Images\\test2.png");
    namedWindow("原图像", WINDOW_NORMAL);
    imshow("原图像", img);



    char arith[9] = { 0, -1, 0, -1, 5, -1, 0, -1, 0 };       //使用拉普拉斯算子

    Mat dst1 = imgSharpen(img, arith);

    namedWindow("锐化图像", WINDOW_NORMAL);
    imshow("锐化图像", dst1);

    waitKey(0);

    return 0;
}

效果展示

请添加图片描述
请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值