Adaptive Thresholding Using the Integral Image ( Derek Bradley* Gerhard Roth)



论文给的伪代码 (论文作者 Derek Bradley*   Gerhard Roth)

Adaptive Thresholding Using the Integral Image ( Derek Bradley* Gerhard Roth)_第1张图片

Adaptive Thresholding Using the Integral Image ( Derek Bradley* Gerhard Roth)_第2张图片


void AdaptiveThreshold( IplImage* inImg, IplImage* outImg)
{
	int S = inImg->width >> 3;
	int T = 15;
	unsigned char *input, *bin;
	input = (unsigned char *)inImg->imageData;
	bin = (unsigned char *)outImg->imageData;

	int width = inImg->widthStep;
	int height = inImg->height;

	unsigned long* integralImg = 0;
	int i, j;
	long sum=0;
	int count=0;
	int index;
	int x1, y1, x2, y2;
	int s2 = S/2;

	//bin = new unsigned char[width*height];
	// create the integral image
	integralImg = (unsigned long*)malloc(width*height*sizeof(unsigned long*));
	for (i=0; i= width) x2 = width-1;
			if (y1 < 0) y1 = 0;
			if (y2 >= height) y2 = height-1;
			count = (x2-x1)*(y2-y1);
			// I(x,y)=s(x2,y2)-s(x1,y2)-s(x2,y1)+s(x1,x1)
			sum = integralImg[y2*width+x2] - integralImg[y1*width+x2] 
				 -integralImg[y2*width+x1] + integralImg[y1*width+x1];

			if ((long)(input[index]*count) < (long)(sum*(100-T)/100))
				bin[index] = 0;
			else
				bin[index] = 255;
		}
	}
	free (integralImg);
}


论文效果

Adaptive Thresholding Using the Integral Image ( Derek Bradley* Gerhard Roth)_第3张图片


你可能感兴趣的:(OpenCV)