matlab中real函数,Matlab中del2()函数学习笔记

在L=del2(U)表达式中,Matlab帮助文件的解释是:li,j=(ui+1,j+ui-1,j+ui,j+1+ui,j-1)/4 - ui,j

但帮助文件没有解释边缘点如何处理。根据数学中的原理,在程序中做适当变化处理:

1. 数组左上角角点的公式应为:li,j=(ui+2,j+ui+2,j+2ui,j)/4 - (ui+1,j+ui,j+1)/2

2. 数组左边边点公式应为:li,j=(ui+1,j+ui-1,j+ui,j+2+ui,j)/4 - (ui,j+ui,j+1)/2

依这两个公式类推,可以得到其他角点和其他边点的计算公式,从而得到计算结果。用C编程实现del2时需要注意这些点的计算。

在OpenCV中,cvLaplace的功能能够实现del2。但不知道为什么使用的时候会出现问题,通不过。所以自己写了一个cvDel2。可能是画蛇添足,不过自己写的能用就可以了,写起来也不是太麻烦。

void cvDel2(IplImage *src,IplImage *dst){ for(i=0;iheight;i++) {  for(j=0;jwidth;j++)  {   if(i==0 && j==0)   {    cvSetReal1D(dst,i*src->width+j,(2*cvGetReal1D(src,i*src->width+j)+cvGetReal1D(src,(i+2)*src->width+j)+cvGetReal1D(src,i*src->width+j+2))/4-(cvGetReal1D(src,(i+1)*src->width+j)+cvGetReal1D(src,i*src->width+j+1))/2);   }   else if(i==0 && j!=0 && j!=src->width-1)   {    cvSetReal1D(dst,i*src->width+j,(cvGetReal1D(src,i*src->width+j)+cvGetReal1D(src,(i+2)*src->width+j)+cvGetReal1D(src,i*src->width+j+1)+cvGetReal1D(src,i*src->width+j-1))/4-(cvGetReal1D(src,(i+1)*src->width+j)+cvGetReal1D(src,i*src->width+j))/2);   }   else if(i==0 && j==src->width-1)   {    cvSetReal1D(dst,i*src->width+j,(2*cvGetReal1D(src,i*src->width+j)+cvGetReal1D(src,(i+2)*src->width+j)+cvGetReal1D(src,i*src->width+j-2))/4-(cvGetReal1D(src,(i+1)*src->width+j)+cvGetReal1D(src,i*src->width+j-1))/2);   }   else if(i!=0 && i!=src->height-1 && j==src->width-1)   {    cvSetReal1D(dst,i*src->width+j,(cvGetReal1D(src,i*src->width+j)+cvGetReal1D(src,i*src->width+j-2)+cvGetReal1D(src,(i+1)*src->width+j)+cvGetReal1D(src,(i-1)*src->width+j))/4-(cvGetReal1D(src,i*src->width+j-1)+cvGetReal1D(src,i*src->width+j))/2);   }   else if(i==src->height-1 && j==src->width-1)   {    cvSetReal1D(dst,i*src->width+j,(2*cvGetReal1D(src,i*src->width+j)+cvGetReal1D(src,(i-2)*src->width+j)+cvGetReal1D(src,i*src->width+j-2))/4-(cvGetReal1D(src,(i-1)*src->width+j)+cvGetReal1D(src,i*src->width+j-1))/2);   }   else if(i==src->height-1 && j!=0 && j!=src->width-1)   {    cvSetReal1D(dst,i*src->width+j,(cvGetReal1D(src,i*src->width+j)+cvGetReal1D(src,(i-2)*src->width+j)+cvGetReal1D(src,i*src->width+j+1)+cvGetReal1D(src,i*src->width+j-1))/4-(cvGetReal1D(src,(i-1)*src->width+j)+cvGetReal1D(src,i*src->width+j))/2);   }   else if(i==src->height-1 && j==0)   {    cvSetReal1D(dst,i*src->width+j,(2*cvGetReal1D(src,i*src->width+j)+cvGetReal1D(src,(i-2)*src->width+j)+cvGetReal1D(src,i*src->width+j+2))/4-(cvGetReal1D(src,(i-1)*src->width+j)+cvGetReal1D(src,i*src->width+j+1))/2);   }   else if(i!=src->height-1 && i!=0 && j==0)   {    cvSetReal1D(dst,i*src->width+j,(cvGetReal1D(src,(i-1)*src->width+j)+cvGetReal1D(src,(i+1)*src->width+j)+cvGetReal1D(src,i*src->width+j)+cvGetReal1D(src,i*src->width+j+2))/4-(cvGetReal1D(src,i*src->width+j)+cvGetReal1D(src,i*src->width+j+1))/2);   }   else   {    cvSetReal1D(dst,i*src->width+j,(cvGetReal1D(src,(i-1)*src->width+j)+cvGetReal1D(src,(i+1)*src->width+j)+cvGetReal1D(src,i*src->width+j-1)+cvGetReal1D(src,i*src->width+j+1))/4-cvGetReal1D(src,i*src->width+j));   }  } }}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值