Exemplo n.º 1
0
Image       *get_threshold_image(Image *img, c_threshold *c)
{
    Image       *threshold_img;
    int         size_x, size_y;
    int         i = 0;
    int         j = 0;
    char        *string_img = malloc(img->rows * img->columns * sizeof(*string_img));
    char        *temp_string_img;
    PixelPacket	*px;
    ExceptionInfo	exception;
    
    GetExceptionInfo(&exception);

    px = GetImagePixels(img, 0, 0, img->columns, img->rows);
    size_x = (int)img->columns;
    size_y = (int)img->rows;
    
    while (i < size_y) {
        j=0;
        while (j < size_x) {
            string_img[(size_x * i) + j] = (char)px[(size_x * i) + j].green;
            j++;
        }
        i++;
    }
    temp_string_img = otsu_th(size_x, size_y, string_img, c);
    
    threshold_img = ConstituteImage(size_x, size_y, "I", CharPixel, temp_string_img, &exception);
    free(temp_string_img);
    free(string_img);

    DestroyImage(img);
    SyncImagePixels(threshold_img);
    return (threshold_img);
}
Exemplo n.º 2
0
/**
 *  Generate a binarized image in black & white
 *
 *  @param im_in Imagen to which apply binarization
 *
 *  @return im_b Return a new binarized image
 */
Mat binarizar (const Mat& im_in){
	Size s = im_in.size();
	int xmax = s.height;
	int ymax = s.width;

	Mat im_b(MAX_IMAGESIZE, MAX_IMAGESIZE, CV_8UC1, Scalar(0));

	int threshold = otsu_th(im_in,xmax,ymax);
	//int threshold = 15000;

	cout << "Threshold: " << threshold << endl;

	/* Binarization output into image */
	for (int y = 0; y < ymax; y++){
		for (int x = 0; x < xmax; x++){
			if (im_in.at<uchar>(y,x) > threshold){
				im_b.at<uchar>(y,x) = MAX_BRIGHTNESS_8;
			}
		}
	}
	return im_b;
}