其他分享
首页 > 其他分享> > 连通域降噪(转载)

连通域降噪(转载)

作者:互联网

原文链接:https://blog.csdn.net/ysc6688

void ContoursRemoveNoise(cv::Mat & srcImage)

{

    int i, j;

    int color = 1;

    int nRows = srcImage.rows;

    int nCols = srcImage.cols;

 

    for (i = 0; i < nRows; ++i)

    {

        for (j = 0; j < nCols; ++j)

        {

            if (!srcImage.at<uchar>(i,j))

            {

                floodFill(srcImage, cv::Point(j, i), cv::Scalar(color));

                color++;

            }

        }

    }

 

    int ColorCount[255] = { 0 };

 

    for (i = 0; i < nRows; ++i)

    {

        for (j = 0; j < nCols; ++j)

        {

            if (srcImage.at<uchar>(i, j) != 255)

            {

                ColorCount[srcImage.at<uchar>(i, j)]++;

            }

        }

    }

 

    for (i = 0; i < nRows; ++i)

    {

        for (j = 0; j < nCols; ++j)

        {

            if (ColorCount[srcImage.at<uchar>(i, j)] <= 20)

            {

                srcImage.at<uchar>(i, j) = 255;

            }

            else

            {

                srcImage.at<uchar>(i, j) = 0;

            }

        }

    }

}

 

标签:srcImage,连通,nCols,++,降噪,nRows,int,ColorCount,转载
来源: https://blog.csdn.net/kenfan1647/article/details/99737353