Ejemplo n.º 1
0
/**
 * Function for thinning the given binary image
 *
 * @param  im  Binary image with range = 0-255
 */
void thinningGuoHall(cv::Mat& im)
{
    im /= 255;
    
    cv::Mat prev = cv::Mat::zeros(im.size(), CV_8UC1);
    cv::Mat diff;
    
    do {
        thinningGuoHallIteration(im, 0);
        thinningGuoHallIteration(im, 1);
        cv::absdiff(im, prev, diff);
        im.copyTo(prev);
    }
    while (cv::countNonZero(diff) > 0);
    
    im *= 255;
}
/**
* Function for thinning the given binary image
*
* @param  im  Binary image with range = 0-255
* @param  useGuoHall Use Guo-Hall or Zhang-Suen algorithm
*/
void thinning(cv::Mat& im, bool useGuoHall = false)
{
	im /= 255;

	if (useGuoHall)
	{
		cv::Mat diff;
		cv::Mat prev = cv::Mat::zeros(im.size(), CV_8UC1);
		do {
			thinningGuoHallIteration(im, 0);
			thinningGuoHallIteration(im, 1);
			cv::absdiff(im, prev, diff);
			im.copyTo(prev);
		} while (cv::countNonZero(diff) > 0);
	}
	else
	{
		cv::Mat marker = cv::Mat::ones(im.size(), CV_8UC1);
		while (thinningIteration(im, marker) > 0);
	}

	im *= 255;
}