morph.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*====================================================================*
  2. - Copyright (C) 2001 Leptonica. All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions
  6. - are met:
  7. - 1. Redistributions of source code must retain the above copyright
  8. - notice, this list of conditions and the following disclaimer.
  9. - 2. Redistributions in binary form must reproduce the above
  10. - copyright notice, this list of conditions and the following
  11. - disclaimer in the documentation and/or other materials
  12. - provided with the distribution.
  13. -
  14. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
  18. - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *====================================================================*/
  26. #ifndef LEPTONICA_MORPH_H
  27. #define LEPTONICA_MORPH_H
  28. /*!
  29. * \file morph.h
  30. *
  31. * <pre>
  32. * Contains the following structs:
  33. * struct Sel
  34. * struct Sela
  35. * struct Kernel
  36. *
  37. * Contains definitions for:
  38. * morphological b.c. flags
  39. * structuring element types
  40. * runlength flags for granulometry
  41. * direction flags for grayscale morphology
  42. * morphological operation flags
  43. * standard border size
  44. * grayscale intensity scaling flags
  45. * morphological tophat flags
  46. * arithmetic and logical operator flags
  47. * grayscale morphology selection flags
  48. * distance function b.c. flags
  49. * image comparison flags
  50. * color content flags
  51. * </pre>
  52. */
  53. /*-------------------------------------------------------------------------*
  54. * Sel and Sel array *
  55. *-------------------------------------------------------------------------*/
  56. #define SEL_VERSION_NUMBER 1
  57. /*! Selection */
  58. struct Sel
  59. {
  60. l_int32 sy; /*!< sel height */
  61. l_int32 sx; /*!< sel width */
  62. l_int32 cy; /*!< y location of sel origin */
  63. l_int32 cx; /*!< x location of sel origin */
  64. l_int32 **data; /*!< {0,1,2}; data[i][j] in [row][col] order */
  65. char *name; /*!< used to find sel by name */
  66. };
  67. typedef struct Sel SEL;
  68. /*! Array of Sel */
  69. struct Sela
  70. {
  71. l_int32 n; /*!< number of sel actually stored */
  72. l_int32 nalloc; /*!< size of allocated ptr array */
  73. struct Sel **sel; /*!< sel ptr array */
  74. };
  75. typedef struct Sela SELA;
  76. /*-------------------------------------------------------------------------*
  77. * Kernel *
  78. *-------------------------------------------------------------------------*/
  79. #define KERNEL_VERSION_NUMBER 2
  80. /*! Kernel */
  81. struct L_Kernel
  82. {
  83. l_int32 sy; /*!< kernel height */
  84. l_int32 sx; /*!< kernel width */
  85. l_int32 cy; /*!< y location of kernel origin */
  86. l_int32 cx; /*!< x location of kernel origin */
  87. l_float32 **data; /*!< data[i][j] in [row][col] order */
  88. };
  89. typedef struct L_Kernel L_KERNEL;
  90. /*-------------------------------------------------------------------------*
  91. * Morphological boundary condition flags *
  92. * *
  93. * Two types of boundary condition for erosion. *
  94. * The global variable MORPH_BC takes on one of these two values. *
  95. * See notes in morph.c for usage. *
  96. *-------------------------------------------------------------------------*/
  97. /*! Morphological boundary condition flags */
  98. enum {
  99. SYMMETRIC_MORPH_BC = 0,
  100. ASYMMETRIC_MORPH_BC = 1
  101. };
  102. /*-------------------------------------------------------------------------*
  103. * Structuring element types *
  104. *-------------------------------------------------------------------------*/
  105. /*! Structuring element types */
  106. enum {
  107. SEL_DONT_CARE = 0,
  108. SEL_HIT = 1,
  109. SEL_MISS = 2
  110. };
  111. /*-------------------------------------------------------------------------*
  112. * Runlength flags for granulometry *
  113. *-------------------------------------------------------------------------*/
  114. /*! Runlength flags for granulometry */
  115. enum {
  116. L_RUN_OFF = 0,
  117. L_RUN_ON = 1
  118. };
  119. /*-------------------------------------------------------------------------*
  120. * Direction flags for grayscale morphology, granulometry, *
  121. * composable Sels, convolution, etc. *
  122. *-------------------------------------------------------------------------*/
  123. /*! Direction flags */
  124. enum {
  125. L_HORIZ = 1,
  126. L_VERT = 2,
  127. L_BOTH_DIRECTIONS = 3
  128. };
  129. /*-------------------------------------------------------------------------*
  130. * Morphological operation flags *
  131. *-------------------------------------------------------------------------*/
  132. /*! Morphological operation flags */
  133. enum {
  134. L_MORPH_DILATE = 1,
  135. L_MORPH_ERODE = 2,
  136. L_MORPH_OPEN = 3,
  137. L_MORPH_CLOSE = 4,
  138. L_MORPH_HMT = 5
  139. };
  140. /*-------------------------------------------------------------------------*
  141. * Grayscale intensity scaling flags *
  142. *-------------------------------------------------------------------------*/
  143. /*! Grayscale intensity scaling flags */
  144. enum {
  145. L_LINEAR_SCALE = 1,
  146. L_LOG_SCALE = 2
  147. };
  148. /*-------------------------------------------------------------------------*
  149. * Morphological tophat flags *
  150. *-------------------------------------------------------------------------*/
  151. /*! Morphological tophat flags */
  152. enum {
  153. L_TOPHAT_WHITE = 0,
  154. L_TOPHAT_BLACK = 1
  155. };
  156. /*-------------------------------------------------------------------------*
  157. * Arithmetic and logical operator flags *
  158. * (use on grayscale images and Numas) *
  159. *-------------------------------------------------------------------------*/
  160. /*! Arithmetic and logical operator flags */
  161. enum {
  162. L_ARITH_ADD = 1,
  163. L_ARITH_SUBTRACT = 2,
  164. L_ARITH_MULTIPLY = 3, /* on numas only */
  165. L_ARITH_DIVIDE = 4, /* on numas only */
  166. L_UNION = 5, /* on numas only */
  167. L_INTERSECTION = 6, /* on numas only */
  168. L_SUBTRACTION = 7, /* on numas only */
  169. L_EXCLUSIVE_OR = 8 /* on numas only */
  170. };
  171. /*-------------------------------------------------------------------------*
  172. * Min/max selection flags *
  173. *-------------------------------------------------------------------------*/
  174. /*! Min/max selection flags */
  175. enum {
  176. L_CHOOSE_MIN = 1, /* useful in a downscaling "erosion" */
  177. L_CHOOSE_MAX = 2, /* useful in a downscaling "dilation" */
  178. L_CHOOSE_MAXDIFF = 3, /* useful in a downscaling contrast */
  179. L_CHOOSE_MIN_BOOST = 4, /* use a modification of the min value */
  180. L_CHOOSE_MAX_BOOST = 5 /* use a modification of the max value */
  181. };
  182. /*-------------------------------------------------------------------------*
  183. * Distance function b.c. flags *
  184. *-------------------------------------------------------------------------*/
  185. /*! Distance function b.c. flags */
  186. enum {
  187. L_BOUNDARY_BG = 1, /* assume bg outside image */
  188. L_BOUNDARY_FG = 2 /* assume fg outside image */
  189. };
  190. /*-------------------------------------------------------------------------*
  191. * Image comparison flags *
  192. *-------------------------------------------------------------------------*/
  193. /*! Image comparison flags */
  194. enum {
  195. L_COMPARE_XOR = 1,
  196. L_COMPARE_SUBTRACT = 2,
  197. L_COMPARE_ABS_DIFF = 3
  198. };
  199. /*-------------------------------------------------------------------------*
  200. * Color content flags *
  201. *-------------------------------------------------------------------------*/
  202. /*! Color content flags */
  203. enum {
  204. L_MAX_DIFF_FROM_AVERAGE_2 = 1,
  205. L_MAX_MIN_DIFF_FROM_2 = 2,
  206. L_MAX_DIFF = 3
  207. };
  208. /*-------------------------------------------------------------------------*
  209. * Standard size of border added around images for special processing *
  210. *-------------------------------------------------------------------------*/
  211. static const l_int32 ADDED_BORDER = 32; /*!< pixels, not bits */
  212. #endif /* LEPTONICA_MORPH_H */