c++拉普拉斯锐化

项目地址:https://github.com/Sherryhaha/Laplace

 "laplace.h"文件

// Created by sunguoyan on 16/4/5.

//

 

#ifndef LAPLACE_LAPLACE_H

#define LAPLACE_LAPLACE_H

#include<iostream>

#include<opencv2/highgui.hpp>

#include<cv.h>

using namespacestd;

using namespacecv;

typedef uchar ty;

 

class Laplace{

public:

    intX_image,Y_image;

    intTempltExcute(Mat &src,int *tmplt,inttw,int x,inty);

    voidSharpLaplace(Mat &src,Mat&dst);

};

 

#endif //LAPLACE_LAPLACE_H

 

laplace.cpp文件:


//

// Created by sunguoyan on 16/4/5.

//

 

#include "laplace.h"

 

/**

 * 功能:使用模板对灰度图像邻域进行处理

 * 参数:src为目标图像,tmplt为模板,tw为邻域大小,x,y为要取得像素的坐标

 */

int Laplace::TempltExcute(Mat &src,int*tmplt,int tw,intx,int y){

    inti,j,py,px;

    intsum = 0;

    for(i=0;i<tw;i++){

        for(j=0;j<tw;j++){

           py = y-tw/2+i;

           px = x-tw/2+j;

            sum+=src.at<ty>(py,px)*tmplt[i*tw+j];

        }

    }

    returnsum;

}

 

/*

 * 功能:灰度图像的拉普拉斯锐化处理

 * 参数:src为原始图像,dst为锐化结果

 */

void Laplace::SharpLaplace(Mat&src,Mat&dst){

    inttmplt[9] = {-1,-1,-1,-1,8,-1,-1,-1,-1};

    inth,w;

    intscale;

    inttmp;

    scale =3;

    for(h= 1;h < Y_image-1;h++){

        for(w= 1;w < X_image - 1;w++){

           tmp = TempltExcute(src,tmplt,3,w,h);

           tmp = tmp/scale;

           tmp = tmp +src.at<ty>(h,w);

           tmp = tmp > 255?255:tmp;

            tmp = tmp < 0?0:tmp;

           dst.at<ty>(h,w)=tmp;

        }

    }

}

 

int main(){

    Matsrc,dst;

    stringfilename = "/Users/sunguoyan/Downloads/picture/heben.jpg";

    src =imread(filename,CV_LOAD_IMAGE_GRAYSCALE);

   dst.create(src.size(),src.type());

    Laplacep;

    p.X_image= src.cols;

    p.Y_image= src.rows;

 

   p.SharpLaplace(src,dst);

 

   namedWindow("origin");

   namedWindow("result");

    imshow("origin",src);

    imshow("result",dst);

   waitKey(0);

    return0;

}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值