X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=images%2Fsig-txt.c;h=2e20f0710352592fcda24e62d68bb5c99904f018;hb=c8c688e0b06fdacb20b28b66b9b0608dae8ca0dc;hp=3673c118703a6223107e4f41622880afbbd4df31;hpb=e93b0de38ac8b8d9e15d7af5594b1286a81a2c65;p=libucw.git diff --git a/images/sig-txt.c b/images/sig-txt.c index 3673c118..2e20f071 100644 --- a/images/sig-txt.c +++ b/images/sig-txt.c @@ -7,9 +7,9 @@ * of the GNU Lesser General Public License. */ -#define LOCAL_DEBUG +#undef LOCAL_DEBUG -#include "sherlock/sherlock.h" +#include "ucw/lib.h" #include "images/images.h" #include "images/signature.h" #include "images/math.h" @@ -22,17 +22,29 @@ void image_sig_detect_textured(struct image_sig_data *data) { + if (image_sig_textured_threshold <= 0) + { + DBG("Zero textured threshold."); + return; + } + uns cols = data->cols; uns rows = data->rows; - uns cell_cols = MIN(cols, MAX_CELLS_COLS); - uns cell_rows = MIN(rows, MAX_CELLS_ROWS); + uns cell_cols = MIN((cols + 1) / 2, MAX_CELLS_COLS); + uns cell_rows = MIN((rows + 1) / 2, MAX_CELLS_ROWS); uns cell_x[MAX_CELLS_COLS + 1]; uns cell_y[MAX_CELLS_ROWS + 1]; uns i, j; u32 cnt[IMAGE_REG_MAX]; + if (cell_cols * cell_rows < 4) + { + DBG("Image is not textured."); + return; + } + DBG("Detecting textured image... cols=%u rows=%u cell_cols=%u cell_rows=%u", cols, rows, cell_cols, cell_rows); - + /* Compute cells boundaries */ for (i = 1, j = 0; i < cell_cols; i++) cell_x[i] = fast_div_u32_u8(j += cols, cell_cols); @@ -47,7 +59,7 @@ image_sig_detect_textured(struct image_sig_data *data) for (uns i = 0; i < data->regions_count; i++) for (struct image_sig_block *block = data->regions[i].blocks; block; block = block->next) block->region = i; - + /* Process cells */ double e = 0; for (uns j = 0; j < cell_rows; j++) @@ -55,7 +67,7 @@ image_sig_detect_textured(struct image_sig_data *data) { uns cell_area = 0; bzero(cnt, data->regions_count * sizeof(u32)); - struct image_sig_block *b1 = data->blocks + cell_x[i] + cell_y[i] * cols, *b2; + struct image_sig_block *b1 = data->blocks + cell_x[i] + cell_y[j] * cols, *b2; for (uns y = cell_y[j]; y < cell_y[j + 1]; y++, b1 += cols) { b2 = b1; @@ -67,7 +79,7 @@ image_sig_detect_textured(struct image_sig_data *data) } for (uns k = 0; k < data->regions_count; k++) { - int a = data->blocks_count * cnt[k] - cell_area * data->regions[k].count; + int a = data->blocks_count * cnt[k] - cell_area * data->regions[k].count; e += (double)a * a / ((double)isqr(data->regions[k].count) * cell_area); } } @@ -75,7 +87,7 @@ image_sig_detect_textured(struct image_sig_data *data) DBG("Coefficient=%g", (double)e / (data->regions_count * data->blocks_count)); /* Threshold */ - if (e <= image_sig_textured_threshold * data->regions_count * data->blocks_count) + if (e < image_sig_textured_threshold * data->regions_count * data->blocks_count) { data->flags |= IMAGE_SIG_TEXTURED; DBG("Image is textured.");