二值图像区域增长

/第一次发微博,贴上闲时写的小程序大笑

二值图像区域增长

/背景为黑色0,前景为白色255
 void GrowR(IplImage* src,IplImage* src1,int flag)
 {
int w=src->width ;
int h=src->height ;
int step=src->widthStep ;
/8邻域
if(flag==1)
{
int nDx1[]={-1,0,1,-1,1,-1,0,1};
int nDy1[]={-1,-1,-1,0,0,1,1,1};
for(int j=1;j<w-1;j++)
    {
    for(int i=1;i<h-1;i++)
    {
    int gg;
    gg=(int)CV_IMAGE_ELEM(src,uchar,i,j); 
    if(gg>200)
    {
    int xx,yy;
    CV_IMAGE_ELEM(src1,uchar,i,j)=gg;

    for(int k=0;k<8;k++)
    {
 
   xx=j+nDx1[k];
   yy=i+nDy1[k];
 
   if(CV_IMAGE_ELEM(src,uchar,yy,xx)<10)
   {
  CV_IMAGE_ELEM(src1,uchar,yy,xx)=255;
    }

      } 
 
       }


       }
      }
}
///4领域
if(flag==2)
{
int nDx2[]={-1,0,1,0};
int nDy2[]={0,1,0,-1};
for(int j=1;j<w-1;j++)
    {
    for(int i=1;i<h-1;i++)
    {
    int gg;
    gg=(int)CV_IMAGE_ELEM(src,uchar,i,j); 
    if(gg>200)
    {
    int xx,yy;
    CV_IMAGE_ELEM(src1,uchar,i,j)=gg;

    for(int k=0;k<4;k++)
    {
 
   xx=j+nDx2[k];
   yy=i+nDy2[k];
 
   if(CV_IMAGE_ELEM(src,uchar,yy,xx)<10)
   {
  CV_IMAGE_ELEM(src1,uchar,yy,xx)=255;
    }

      } 
 
       }


       }
      }

}
 }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值