void BINARIZATION(IplImage * in, IplImage * result)
{
char red;
char green;
char blue;
int x, y;
CvSeq * contour = 0;
int threshold_max = 256, threshold_min = 140, GB_threshold = 60, GB_diff = 20;
for (y = 0; y < in->height; y++)
{
for (x = 0; x < in->width; x++)
{
red = in->imageData[(y * in->widthStep) + x * 3 + 2];
green = in->imageData[(y * in->widthStep) + x * 3 + 1];
blue = in->imageData[(y * in->widthStep) + x * 3 + 0];
if ((red > threshold_min && red < threshold_max) && (green < GB_threshold) && (blue < GB_threshold) && (abs(green - blue) < GB_diff))
{
result->imageData[(y * in->widthStep) + x * 3 + 0] = 255;
result->imageData[(y * in->widthStep) + x * 3 + 1] = 255;
result->imageData[(y * in->widthStep) + x * 3 + 2] = 255;
}
else
{
result->imageData[(y * in->widthStep) + x * 3 + 0] = 0;
result->imageData[(y * in->widthStep) + x * 3 + 1] = 0;
result->imageData[(y * in->widthStep) + x * 3 + 2] = 0;
}
}
}
}