|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "edge_common.h" |
|
|
|
|
|
static int get_rounded_direction(int gx, int gy) |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (gx) { |
|
int tanpi8gx, tan3pi8gx; |
|
|
|
if (gx < 0) |
|
gx = -gx, gy = -gy; |
|
gy *= (1 << 16); |
|
tanpi8gx = 27146 * gx; |
|
tan3pi8gx = 158218 * gx; |
|
if (gy > -tan3pi8gx && gy < -tanpi8gx) return DIRECTION_45UP; |
|
if (gy > -tanpi8gx && gy < tanpi8gx) return DIRECTION_HORIZONTAL; |
|
if (gy > tanpi8gx && gy < tan3pi8gx) return DIRECTION_45DOWN; |
|
} |
|
return DIRECTION_VERTICAL; |
|
} |
|
|
|
#undef DEPTH |
|
#define DEPTH 8 |
|
#include "edge_template.c" |
|
|
|
#undef DEPTH |
|
#define DEPTH 16 |
|
#include "edge_template.c" |
|
|
|
|
|
|
|
|
|
void ff_non_maximum_suppression(int w, int h, |
|
uint8_t *dst, int dst_linesize, |
|
const int8_t *dir, int dir_linesize, |
|
const uint16_t *src, int src_linesize) |
|
{ |
|
int i, j; |
|
|
|
#define COPY_MAXIMA(ay, ax, by, bx) do { \ |
|
if (src[i] > src[(ay)*src_linesize + i+(ax)] && \ |
|
src[i] > src[(by)*src_linesize + i+(bx)]) \ |
|
dst[i] = av_clip_uint8(src[i]); \ |
|
} while (0) |
|
|
|
for (j = 1; j < h - 1; j++) { |
|
dst += dst_linesize; |
|
dir += dir_linesize; |
|
src += src_linesize; |
|
for (i = 1; i < w - 1; i++) { |
|
switch (dir[i]) { |
|
case DIRECTION_45UP: COPY_MAXIMA( 1, -1, -1, 1); break; |
|
case DIRECTION_45DOWN: COPY_MAXIMA(-1, -1, 1, 1); break; |
|
case DIRECTION_HORIZONTAL: COPY_MAXIMA( 0, -1, 0, 1); break; |
|
case DIRECTION_VERTICAL: COPY_MAXIMA(-1, 0, 1, 0); break; |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
void ff_double_threshold(int low, int high, int w, int h, |
|
uint8_t *dst, int dst_linesize, |
|
const uint8_t *src, int src_linesize) |
|
{ |
|
int i, j; |
|
|
|
for (j = 0; j < h; j++) { |
|
for (i = 0; i < w; i++) { |
|
if (src[i] > high) { |
|
dst[i] = src[i]; |
|
continue; |
|
} |
|
|
|
if (!(!i || i == w - 1 || !j || j == h - 1) && |
|
src[i] > low && |
|
(src[-src_linesize + i-1] > high || |
|
src[-src_linesize + i ] > high || |
|
src[-src_linesize + i+1] > high || |
|
src[ i-1] > high || |
|
src[ i+1] > high || |
|
src[ src_linesize + i-1] > high || |
|
src[ src_linesize + i ] > high || |
|
src[ src_linesize + i+1] > high)) |
|
dst[i] = src[i]; |
|
else |
|
dst[i] = 0; |
|
} |
|
dst += dst_linesize; |
|
src += src_linesize; |
|
} |
|
} |
|
|