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