测地腐蚀和腐蚀重建—lhMorpRErode

函数:lhMorpRErode

说明:形态学测地腐蚀和腐蚀重建运算

参数:

src 输入图像

msk 掩模图像

dst 输出图像

se  结构元素

iterations测地腐蚀的次数,当默认为-1时,为腐蚀重建运算

源码:

void lhMorpRErode(const IplImage* src,  const IplImage* msk, IplImage* dst, IplConvKernel* se = NULL, int iterations=-1)

{

       assert(src != NULL  && msk != NULL && dst != NULL && src != dst );

       if(iterations < 0)

       {

              //腐蚀重建

              cvMax(src, msk, dst);

              cvErode(dst, dst, se);

              cvMax(dst, msk, dst);

              IplImage*  temp1 = cvCreateImage(cvGetSize(src), 8, 1);

              IplImage*  temp2 = cvCreateImage(cvGetSize(src), 8, 1);

              do

              {

                     cvCopy(dst, temp1);

                     cvErode(dst, dst, se);

                     cvMax(dst, msk, dst);

                     cvCmp(temp1, dst, temp2, CV_CMP_NE);

              }

              while(cvSum(temp2).val[0] != 0);

              cvReleaseImage(&temp1);

              cvReleaseImage(&temp2);

              return;    

       }

       else if (iterations == 0)

       {

              cvCopy(src, dst);

       }

       else

       {

              //普通测地腐蚀 p137(6.2)

              cvMax(src, msk, dst);

              cvErode(dst, dst, se);

              cvMax(dst, msk, dst);

              for(int i=1; i<iterations; i++)

              {

                     cvErode(dst, dst, se);

                     cvMax(dst, msk, dst);

              }

       }

}

你可能感兴趣的:(null,DST)