//the main functions : struct vector *img_to_blocks(struct matrix *img) { struct coords init; struct vector *output; //all the text is within the square ((w1,h1),(w2,h2)) size_t i = 0; for(; i < img->height - 1 && line_is_empty(img, i, 0, img->width - 1); i++){} init.h1 = i; for(i = img->height - 1; i > 0 && line_is_empty(img, i, 0, img->width - 1); i--){} init.h2 = i; for(i = 0; i < img->width - 1 && column_is_empty(img, i, init.h1, init.h2); i++){} init.w1 = i; for(i = img->width - 1; i > 0 && column_is_empty(img, i, init.h1, init.h2); i--){} init.w2 = i; //we create a matrix with appearant blocks struct matrix *M = malloc(sizeof(struct matrix)); M->data = malloc(sizeof(double) * img->width * img->height); M->width = img->width, M->height = img->height; for(size_t i = 0; i < img->width * img->height; i++) { M->data[i] = img->data[i]; } for(size_t i = 0; i < 5; i++) { filter_noise(M); if(i % 2) filter_contrast(M); } //we launch the block detection in that original block if(init.w1 < init.w2 && init.h1 < init.h2) output = vertical_rec(M, init, 1); else output = NULL; //invalid image. free(M->data); free(M); return output; }
int filter_oldtv(int color) { return (filter_grey(filter_line_h(filter_noise(filter_canal(color))))); }