You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
5.4 KiB

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