/ocr/ocrservice/jni/hydrogen/include/leptonica/morph.h

http://eyes-free.googlecode.com/ · C++ Header · 218 lines · 94 code · 36 blank · 88 comment · 0 complexity · 499ef32aaa1c7f5669ef00295d325ebb MD5 · raw file

  1. /*====================================================================*
  2. - Copyright (C) 2001 Leptonica. All rights reserved.
  3. - This software is distributed in the hope that it will be
  4. - useful, but with NO WARRANTY OF ANY KIND.
  5. - No author or distributor accepts responsibility to anyone for the
  6. - consequences of using this software, or for whether it serves any
  7. - particular purpose or works at all, unless he or she says so in
  8. - writing. Everyone is granted permission to copy, modify and
  9. - redistribute this source code, for commercial or non-commercial
  10. - purposes, with the following restrictions: (1) the origin of this
  11. - source code must not be misrepresented; (2) modified versions must
  12. - be plainly marked as such; and (3) this notice may not be removed
  13. - or altered from any source or modified source distribution.
  14. *====================================================================*/
  15. #ifndef LEPTONICA_MORPH_H
  16. #define LEPTONICA_MORPH_H
  17. /*
  18. * morph.h
  19. *
  20. * Contains the following structs:
  21. * struct Sel
  22. * struct Sela
  23. * struct Kernel
  24. *
  25. * Contains definitions for:
  26. * morphological b.c. flags
  27. * structuring element types
  28. * runlength flags for granulometry
  29. * direction flags for grayscale morphology
  30. * morphological operation flags
  31. * standard border size
  32. * grayscale intensity scaling flags
  33. * morphological tophat flags
  34. * arithmetic and logical operator flags
  35. * grayscale morphology selection flags
  36. * distance function b.c. flags
  37. * image comparison flags
  38. * color content flags
  39. */
  40. /*-------------------------------------------------------------------------*
  41. * Sel and Sel array *
  42. *-------------------------------------------------------------------------*/
  43. #define SEL_VERSION_NUMBER 1
  44. struct Sel
  45. {
  46. l_int32 sy; /* sel height */
  47. l_int32 sx; /* sel width */
  48. l_int32 cy; /* y location of sel origin */
  49. l_int32 cx; /* x location of sel origin */
  50. l_int32 **data; /* {0,1,2}; data[i][j] in [row][col] order */
  51. char *name; /* used to find sel by name */
  52. };
  53. typedef struct Sel SEL;
  54. struct Sela
  55. {
  56. l_int32 n; /* number of sel actually stored */
  57. l_int32 nalloc; /* size of allocated ptr array */
  58. struct Sel **sel; /* sel ptr array */
  59. };
  60. typedef struct Sela SELA;
  61. /*-------------------------------------------------------------------------*
  62. * Kernel *
  63. *-------------------------------------------------------------------------*/
  64. #define KERNEL_VERSION_NUMBER 2
  65. struct L_Kernel
  66. {
  67. l_int32 sy; /* kernel height */
  68. l_int32 sx; /* kernel width */
  69. l_int32 cy; /* y location of kernel origin */
  70. l_int32 cx; /* x location of kernel origin */
  71. l_float32 **data; /* data[i][j] in [row][col] order */
  72. };
  73. typedef struct L_Kernel L_KERNEL;
  74. /*-------------------------------------------------------------------------*
  75. * Morphological boundary condition flags *
  76. *
  77. * Two types of boundary condition for erosion.
  78. * The global variable MORPH_BC takes on one of these two values.
  79. * See notes in morph.c for usage.
  80. *-------------------------------------------------------------------------*/
  81. enum {
  82. SYMMETRIC_MORPH_BC = 0,
  83. ASYMMETRIC_MORPH_BC = 1
  84. };
  85. /*-------------------------------------------------------------------------*
  86. * Structuring element types *
  87. *-------------------------------------------------------------------------*/
  88. enum {
  89. SEL_DONT_CARE = 0,
  90. SEL_HIT = 1,
  91. SEL_MISS = 2
  92. };
  93. /*-------------------------------------------------------------------------*
  94. * Runlength flags for granulometry *
  95. *-------------------------------------------------------------------------*/
  96. enum {
  97. L_RUN_OFF = 0,
  98. L_RUN_ON = 1
  99. };
  100. /*-------------------------------------------------------------------------*
  101. * Direction flags for grayscale morphology, granulometry, *
  102. * composable Sels, and convolution *
  103. *-------------------------------------------------------------------------*/
  104. enum {
  105. L_HORIZ = 1,
  106. L_VERT = 2,
  107. L_BOTH_DIRECTIONS = 3
  108. };
  109. /*-------------------------------------------------------------------------*
  110. * Morphological operation flags *
  111. *-------------------------------------------------------------------------*/
  112. enum {
  113. L_MORPH_DILATE = 1,
  114. L_MORPH_ERODE = 2,
  115. L_MORPH_OPEN = 3,
  116. L_MORPH_CLOSE = 4,
  117. L_MORPH_HMT = 5
  118. };
  119. /*-------------------------------------------------------------------------*
  120. * Grayscale intensity scaling flags *
  121. *-------------------------------------------------------------------------*/
  122. enum {
  123. L_LINEAR_SCALE = 1,
  124. L_LOG_SCALE = 2
  125. };
  126. /*-------------------------------------------------------------------------*
  127. * Morphological tophat flags *
  128. *-------------------------------------------------------------------------*/
  129. enum {
  130. L_TOPHAT_WHITE = 0,
  131. L_TOPHAT_BLACK = 1
  132. };
  133. /*-------------------------------------------------------------------------*
  134. * Arithmetic and logical operator flags *
  135. * (use on grayscale images and Numas) *
  136. *-------------------------------------------------------------------------*/
  137. enum {
  138. L_ARITH_ADD = 1,
  139. L_ARITH_SUBTRACT = 2,
  140. L_ARITH_MULTIPLY = 3, /* on numas only */
  141. L_ARITH_DIVIDE = 4, /* on numas only */
  142. L_UNION = 5, /* on numas only */
  143. L_INTERSECTION = 6, /* on numas only */
  144. L_SUBTRACTION = 7, /* on numas only */
  145. L_EXCLUSIVE_OR = 8 /* on numas only */
  146. };
  147. /*-------------------------------------------------------------------------*
  148. * Min/max selection flags *
  149. *-------------------------------------------------------------------------*/
  150. enum {
  151. L_CHOOSE_MIN = 1, /* useful in a downscaling "erosion" */
  152. L_CHOOSE_MAX = 2, /* useful in a downscaling "dilation" */
  153. L_CHOOSE_MAX_MIN_DIFF = 3 /* useful in a downscaling contrast */
  154. };
  155. /*-------------------------------------------------------------------------*
  156. * Distance function b.c. flags *
  157. *-------------------------------------------------------------------------*/
  158. enum {
  159. L_BOUNDARY_BG = 1, /* assume bg outside image */
  160. L_BOUNDARY_FG = 2 /* assume fg outside image */
  161. };
  162. /*-------------------------------------------------------------------------*
  163. * Image comparison flags *
  164. *-------------------------------------------------------------------------*/
  165. enum {
  166. L_COMPARE_XOR = 1,
  167. L_COMPARE_SUBTRACT = 2,
  168. L_COMPARE_ABS_DIFF = 3
  169. };
  170. /*-------------------------------------------------------------------------*
  171. * Color content flags *
  172. *-------------------------------------------------------------------------*/
  173. enum {
  174. L_MAX_DIFF_FROM_AVERAGE_2 = 1,
  175. L_MAX_MIN_DIFF_FROM_2 = 2,
  176. L_MAX_DIFF = 3
  177. };
  178. /*-------------------------------------------------------------------------*
  179. * Standard size of border added around images for special processing *
  180. *-------------------------------------------------------------------------*/
  181. static const l_int32 ADDED_BORDER = 32; /* pixels, not bits */
  182. #endif /* LEPTONICA_MORPH_H */