图像处理算法基础(五)---拉普拉斯变换自实现与opencv对比

最近做了几个平滑锐化的程序效果都是比opencv差一些,猜测opencv应该加了一些效果优化。

拉普拉斯算子是 n欧几里德空间中的一个二阶微分算子,定义为 梯度(▽f)的 散度(▽·f)。因此如果 f是二阶可微的实函数,则 f的拉普拉斯算子定义为:
f的拉普拉斯算子也是 笛卡儿坐标系 xi中的所有 非混合二阶 偏导数
作为一个二阶微分算子,拉普拉斯算子把 C函数映射到 C函数,对于 k≥ 2。表达式(1)(或(2))定义了一个算子Δ : C( R) → C( R),或更一般地,定义了一个算子Δ : C(Ω) → C(Ω),对于任何 开集Ω。
函数的拉普拉斯算子也是该函数的 黑塞矩阵的迹
另外, 满足▽·▽f=0 的函数f, 称为 调和函数.

在二维空间坐标系中 xy代表 x-y 平面上的 笛卡儿坐标

在数字图像中离散表达式 :△f(x,y)=f(x+1,y)+f(x-1,y)+f(x,y+1)+f(x,y-1)-4*f(x,y)

代码实现为:
int  picProcessBasics::IMGLaplace(IplImage* pImg,IplImage* pDestImg)
{
 int FilterW=0;
 int FilterH=0;
 int FilterCenterX=0;
 int FilterCenterY=0;
 int aValue[64]={0};//滤波掩模
 int tempV=0;

 FilterW=3;
 FilterH=3;
 FilterCenterX=1;
 FilterCenterY=1;
 cvCopy(pImg,pDestImg,0);

 for(int i = FilterCenterY; i < pImg->height-FilterH+FilterCenterY+1; i++){ 
  for(int j = FilterCenterX; j < pImg->width-FilterW+FilterCenterX+1; j++){ 
 
   // 读取滤波器数组 
            for (int k = 0; k < FilterH; k++) 
            { 
                for (int l = 0; l < FilterW; l++) 
                { 
                    // 指向DIB第i - iFilterMY + k行,第j - iFilterMX + l个象素的指针 
                
                    aValue[k * FilterW + l] = pImg->imageData[pImg->widthStep * (i - FilterCenterY + k) + (j - FilterCenterX + l) ]; 
                } 
            } 

   //tempV= aValue[0]+aValue[1]+aValue[2]+aValue[3]+aValue[5]+aValue[6]+aValue[7]+aValue[8]-8*aValue[4];
   tempV= aValue[1]+aValue[3]+aValue[5]+aValue[7]-4*aValue[4];

if(tempV>255)
    tempV=255;
   else if(tempV<0)
    tempV=0;
   pDestImg->imageData[pDestImg->widthStep * i + j ]= tempV; //pImg->imageData[pImg->widthStep * i + j ] - tempV;
        } 
    }

 return 0;
}

效果图:


opencv函数 void cvLaplace( const CvArr* src, CvArr* dst, int aperture_size=3 );  效果图:



  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值