aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/edge_common.h
blob: 87c143f2b8032ddf521b63675aee2b38a71966b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/**
 * @file
 * common functions for edge detection
 */

#ifndef AVFILTER_EDGE_COMMON_H
#define AVFILTER_EDGE_COMMON_H

#include "avfilter.h"

/**
 * @brief Rounded directions used in av_image_sobel()
 */
enum AVRoundedDirection {
    DIRECTION_45UP,
    DIRECTION_45DOWN,
    DIRECTION_HORIZONTAL,
    DIRECTION_VERTICAL,
};

/**
 * Simple sobel operator to get rounded gradients
 *
 * @param w             the width of the image in pixels
 * @param h             the height of the image in pixels
 * @param dst           data pointers to magnitude image
 * @param dst_linesize  linesizes for the magnitude image
 * @param dir           data pointers to direction image
 * @param dir_linesize  linesizes for the direction image
 * @param src           data pointers to source image
 * @param src_linesize  linesizes for the source image
 */
void ff_sobel(int w, int h,
              uint16_t *dst, int dst_linesize,
              int8_t *dir, int dir_linesize,
              const uint8_t *src, int src_linesize);

/**
 * Filters rounded gradients to drop all non-maxima pixels in the magnitude image
 * Expects gradients generated by av_image_sobel()
 * Expects zero's in the destination buffer dst
 *
 * @param w             the width of the image in pixels
 * @param h             the height of the image in pixels
 * @param dst           data pointers to magnitude image
 * @param dst_linesize  linesizes for the magnitude image
 * @param dir           data pointers to direction image
 * @param dir_linesize  linesizes for the direction image
 * @param src           data pointers to source image
 * @param src_linesize  linesizes for the source image
 */
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);

/**
 * Filters all pixels in src to keep all pixels > high,
 * and keep all pixels > low where all surrounding pixels > high
 *
 * @param low           the low threshold value
 * @param high          the hegh threshold value
 * @param w             the width of the image in pixels
 * @param h             the height of the image in pixels
 * @param dst           data pointers to destination image
 * @param dst_linesize  linesizes for the destination image
 * @param src           data pointers to source image
 * @param src_linesize  linesizes for the source image
 */
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);

/**
 * Applies gaussian blur.
 * 5x5 kernels, sigma = 1.4
 *
 * @param w             the width of the image in pixels
 * @param h             the height of the image in pixels
 * @param dst           data pointers to destination image
 * @param dst_linesize  linesizes for the destination image
 * @param src           data pointers to source image
 * @param src_linesize  linesizes for the source image
 */
void ff_gaussian_blur(int w, int h,
                      uint8_t *dst, int dst_linesize,
                      const uint8_t *src, int src_linesize);

#endif