morph.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. * morph.h
  30. *
  31. * Contains the following structs:
  32. * struct Sel
  33. * struct Sela
  34. * struct Kernel
  35. *
  36. * Contains definitions for:
  37. * morphological b.c. flags
  38. * structuring element types
  39. * runlength flags for granulometry
  40. * direction flags for grayscale morphology
  41. * morphological operation flags
  42. * standard border size
  43. * grayscale intensity scaling flags
  44. * morphological tophat flags
  45. * arithmetic and logical operator flags
  46. * grayscale morphology selection flags
  47. * distance function b.c. flags
  48. * image comparison flags
  49. * color content flags
  50. */
  51. /*-------------------------------------------------------------------------*
  52. * Sel and Sel array *
  53. *-------------------------------------------------------------------------*/
  54. #define SEL_VERSION_NUMBER 1
  55. struct Sel
  56. {
  57. l_int32 sy; /* sel height */
  58. l_int32 sx; /* sel width */
  59. l_int32 cy; /* y location of sel origin */
  60. l_int32 cx; /* x location of sel origin */
  61. l_int32 **data; /* {0,1,2}; data[i][j] in [row][col] order */
  62. char *name; /* used to find sel by name */
  63. };
  64. typedef struct Sel SEL;
  65. struct Sela
  66. {
  67. l_int32 n; /* number of sel actually stored */
  68. l_int32 nalloc; /* size of allocated ptr array */
  69. struct Sel **sel; /* sel ptr array */
  70. };
  71. typedef struct Sela SELA;
  72. /*-------------------------------------------------------------------------*
  73. * Kernel *
  74. *-------------------------------------------------------------------------*/
  75. #define KERNEL_VERSION_NUMBER 2
  76. struct L_Kernel
  77. {
  78. l_int32 sy; /* kernel height */
  79. l_int32 sx; /* kernel width */
  80. l_int32 cy; /* y location of kernel origin */
  81. l_int32 cx; /* x location of kernel origin */
  82. l_float32 **data; /* data[i][j] in [row][col] order */
  83. };
  84. typedef struct L_Kernel L_KERNEL;
  85. /*-------------------------------------------------------------------------*
  86. * Morphological boundary condition flags *
  87. *
  88. * Two types of boundary condition for erosion.
  89. * The global variable MORPH_BC takes on one of these two values.
  90. * See notes in morph.c for usage.
  91. *-------------------------------------------------------------------------*/
  92. enum {
  93. SYMMETRIC_MORPH_BC = 0,
  94. ASYMMETRIC_MORPH_BC = 1
  95. };
  96. /*-------------------------------------------------------------------------*
  97. * Structuring element types *
  98. *-------------------------------------------------------------------------*/
  99. enum {
  100. SEL_DONT_CARE = 0,
  101. SEL_HIT = 1,
  102. SEL_MISS = 2
  103. };
  104. /*-------------------------------------------------------------------------*
  105. * Runlength flags for granulometry *
  106. *-------------------------------------------------------------------------*/
  107. enum {
  108. L_RUN_OFF = 0,
  109. L_RUN_ON = 1
  110. };
  111. /*-------------------------------------------------------------------------*
  112. * Direction flags for grayscale morphology, granulometry, *
  113. * composable Sels, and convolution *
  114. *-------------------------------------------------------------------------*/
  115. enum {
  116. L_HORIZ = 1,
  117. L_VERT = 2,
  118. L_BOTH_DIRECTIONS = 3
  119. };
  120. /*-------------------------------------------------------------------------*
  121. * Morphological operation flags *
  122. *-------------------------------------------------------------------------*/
  123. enum {
  124. L_MORPH_DILATE = 1,
  125. L_MORPH_ERODE = 2,
  126. L_MORPH_OPEN = 3,
  127. L_MORPH_CLOSE = 4,
  128. L_MORPH_HMT = 5
  129. };
  130. /*-------------------------------------------------------------------------*
  131. * Grayscale intensity scaling flags *
  132. *-------------------------------------------------------------------------*/
  133. enum {
  134. L_LINEAR_SCALE = 1,
  135. L_LOG_SCALE = 2
  136. };
  137. /*-------------------------------------------------------------------------*
  138. * Morphological tophat flags *
  139. *-------------------------------------------------------------------------*/
  140. enum {
  141. L_TOPHAT_WHITE = 0,
  142. L_TOPHAT_BLACK = 1
  143. };
  144. /*-------------------------------------------------------------------------*
  145. * Arithmetic and logical operator flags *
  146. * (use on grayscale images and Numas) *
  147. *-------------------------------------------------------------------------*/
  148. enum {
  149. L_ARITH_ADD = 1,
  150. L_ARITH_SUBTRACT = 2,
  151. L_ARITH_MULTIPLY = 3, /* on numas only */
  152. L_ARITH_DIVIDE = 4, /* on numas only */
  153. L_UNION = 5, /* on numas only */
  154. L_INTERSECTION = 6, /* on numas only */
  155. L_SUBTRACTION = 7, /* on numas only */
  156. L_EXCLUSIVE_OR = 8 /* on numas only */
  157. };
  158. /*-------------------------------------------------------------------------*
  159. * Min/max selection flags *
  160. *-------------------------------------------------------------------------*/
  161. enum {
  162. L_CHOOSE_MIN = 1, /* useful in a downscaling "erosion" */
  163. L_CHOOSE_MAX = 2, /* useful in a downscaling "dilation" */
  164. L_CHOOSE_MAX_MIN_DIFF = 3 /* useful in a downscaling contrast */
  165. };
  166. /*-------------------------------------------------------------------------*
  167. * Distance function b.c. flags *
  168. *-------------------------------------------------------------------------*/
  169. enum {
  170. L_BOUNDARY_BG = 1, /* assume bg outside image */
  171. L_BOUNDARY_FG = 2 /* assume fg outside image */
  172. };
  173. /*-------------------------------------------------------------------------*
  174. * Image comparison flags *
  175. *-------------------------------------------------------------------------*/
  176. enum {
  177. L_COMPARE_XOR = 1,
  178. L_COMPARE_SUBTRACT = 2,
  179. L_COMPARE_ABS_DIFF = 3
  180. };
  181. /*-------------------------------------------------------------------------*
  182. * Color content flags *
  183. *-------------------------------------------------------------------------*/
  184. enum {
  185. L_MAX_DIFF_FROM_AVERAGE_2 = 1,
  186. L_MAX_MIN_DIFF_FROM_2 = 2,
  187. L_MAX_DIFF = 3
  188. };
  189. /*-------------------------------------------------------------------------*
  190. * Standard size of border added around images for special processing *
  191. *-------------------------------------------------------------------------*/
  192. static const l_int32 ADDED_BORDER = 32; /* pixels, not bits */
  193. #endif /* LEPTONICA_MORPH_H */