Debian Codegraph @

src/thirdparty/VLFeat/quickshift.h

raw
1 /** @file quickshift.h
2 ** @brief Quick shift (@ref quickshift)
3 ** @author Andrea Vedaldi
4 ** @author Brian Fulkerson
5 **/
6
7 /*
8 Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
9 All rights reserved.
10
11 This file is part of the VLFeat library and is made available under
12 the terms of the BSD license (see the COPYING file).
13 */
14
15 #ifndef VL_QUICKSHIFT_H
16 #define VL_QUICKSHIFT_H
17
18 #include "generic.h"
19 #include "mathop.h"
20
21 /** @brief quick shift datatype */
22 typedef double vl_qs_type ;
23
24 /** @brief quick shift infinity constant */
25 #define VL_QS_INF VL_INFINITY_D /* Change to _F for float math */
26
27 /** ------------------------------------------------------------------
28 ** @brief quick shift results
29 **
30 ** This implements quick shift mode seeking.
31 **/
32
33 typedef struct _VlQS
34 {
35 vl_qs_type *image ; /**< height x width x channels feature image */
36 int height; /**< height of the image */
37 int width; /**< width of the image */
38 int channels; /**< number of channels in the image */
39
40 vl_bool medoid;
41 vl_qs_type sigma;
42 vl_qs_type tau;
43
44 int *parents ;
45 vl_qs_type *dists ;
46 vl_qs_type *density ;
47 } VlQS ;
48
49 /** @name Create and destroy
50 ** @{
51 **/
52 VL_EXPORT
53 VlQS* vl_quickshift_new (vl_qs_type const * im, int height, int width,
54 int channels);
55
56 VL_EXPORT
57 void vl_quickshift_delete (VlQS *q) ;
58 /** @} */
59
60 /** @name Process data
61 ** @{
62 **/
63
64 VL_EXPORT
65 void vl_quickshift_process (VlQS *q) ;
66
67 /** @} */
68
69 /** @name Retrieve data and parameters
70 ** @{
71 **/
72 VL_INLINE vl_qs_type vl_quickshift_get_max_dist (VlQS const *q) ;
73 VL_INLINE vl_qs_type vl_quickshift_get_kernel_size (VlQS const *q) ;
74 VL_INLINE vl_bool vl_quickshift_get_medoid (VlQS const *q) ;
75
76 VL_INLINE int * vl_quickshift_get_parents (VlQS const *q) ;
77 VL_INLINE vl_qs_type * vl_quickshift_get_dists (VlQS const *q) ;
78 VL_INLINE vl_qs_type * vl_quickshift_get_density (VlQS const *q) ;
79 /** @} */
80
81 /** @name Set parameters
82 ** @{
83 **/
84 VL_INLINE void vl_quickshift_set_max_dist (VlQS *f, vl_qs_type tau) ;
85 VL_INLINE void vl_quickshift_set_kernel_size (VlQS *f, vl_qs_type sigma) ;
86 VL_INLINE void vl_quickshift_set_medoid (VlQS *f, vl_bool medoid) ;
87 /** @} */
88
89 /* -------------------------------------------------------------------
90 * Inline functions implementation
91 * ---------------------------------------------------------------- */
92
93 /** ------------------------------------------------------------------
94 ** @brief Get tau.
95 ** @param q quick shift object.
96 ** @return the maximum distance in the feature space between nodes in the
97 ** quick shift tree.
98 **/
99
100 VL_INLINE vl_qs_type
101 vl_quickshift_get_max_dist (VlQS const *q)
102 {
103 return q->tau ;
104 }
105
106 /** ------------------------------------------------------------------
107 ** @brief Get sigma.
108 ** @param q quick shift object.
109 ** @return the standard deviation of the kernel used in the Parzen density
110 ** estimate.
111 **/
112
113 VL_INLINE vl_qs_type
114 vl_quickshift_get_kernel_size (VlQS const *q)
115 {
116 return q->sigma ;
117 }
118
119 /** ------------------------------------------------------------------
120 ** @brief Get medoid.
121 ** @param q quick Shift object.
122 ** @return @c true if medoid shift is used instead of quick shift.
123 **/
124
125 VL_INLINE vl_bool
126 vl_quickshift_get_medoid (VlQS const *q)
127 {
128 return q->medoid ;
129 }
130
131 /** ------------------------------------------------------------------
132 ** @brief Get parents.
133 ** @param q quick shift object.
134 ** @return a @c height x @c width matrix where each element contains the
135 ** linear index of its parent node. The node is a root if its
136 ** value is its own linear index.
137 **/
138
139 VL_INLINE int *
140 vl_quickshift_get_parents (VlQS const *q)
141 {
142 return q->parents ;
143 }
144
145 /** ------------------------------------------------------------------
146 ** @brief Get dists.
147 ** @param q quick shift object.
148 ** @return for each pixel, the distance in feature space to the pixel
149 ** that is its parent in the quick shift tree. The distance is
150 ** set to 'inf' if the pixel is a root node.
151 **/
152
153 VL_INLINE vl_qs_type *
154 vl_quickshift_get_dists (VlQS const *q)
155 {
156 return q->dists ;
157 }
158
159 /** ------------------------------------------------------------------
160 ** @brief Get density.
161 ** @param q quick shift object.
162 ** @return the estimate of the density at each pixel.
163 **/
164
165 VL_INLINE vl_qs_type *
166 vl_quickshift_get_density (VlQS const *q)
167 {
168 return q->density ;
169 }
170
171 /** ------------------------------------------------------------------
172 ** @brief Set sigma
173 ** @param q quick shift object.
174 ** @param sigma standard deviation of the kernel used in the Parzen density
175 ** estimate.
176 **/
177
178 VL_INLINE void
179 vl_quickshift_set_kernel_size (VlQS *q, vl_qs_type sigma)
180 {
181 q -> sigma = sigma ;
182 }
183
184 /** ------------------------------------------------------------------
185 ** @brief Set max distance
186 ** @param q quick shift object.
187 ** @param tau the maximum distance in the feature space between nodes in the
188 ** quick shift tree.
189 **/
190
191 VL_INLINE void
192 vl_quickshift_set_max_dist (VlQS *q, vl_qs_type tau)
193 {
194 q -> tau = tau ;
195 }
196
197 /** ------------------------------------------------------------------
198 ** @brief Set medoid
199 ** @param q quick shift object.
200 ** @param medoid @c true to use kernelized medoid shift, @c false (default) uses
201 ** quick shift.
202 **/
203
204 VL_INLINE void
205 vl_quickshift_set_medoid (VlQS *q, vl_bool medoid)
206 {
207 q -> medoid = medoid ;
208 }
209
210
211 #endif