Line | Branch | Exec | Source |
---|---|---|---|
1 | /******************************************************************************* | ||
2 | |||
3 | License: | ||
4 | This software and/or related materials was developed at the National Institute | ||
5 | of Standards and Technology (NIST) by employees of the Federal Government | ||
6 | in the course of their official duties. Pursuant to title 17 Section 105 | ||
7 | of the United States Code, this software is not subject to copyright | ||
8 | protection and is in the public domain. | ||
9 | |||
10 | This software and/or related materials have been determined to be not subject | ||
11 | to the EAR (see Part 734.3 of the EAR for exact details) because it is | ||
12 | a publicly available technology and software, and is freely distributed | ||
13 | to any interested party with no licensing requirements. Therefore, it is | ||
14 | permissible to distribute this software as a free download from the internet. | ||
15 | |||
16 | Disclaimer: | ||
17 | This software and/or related materials was developed to promote biometric | ||
18 | standards and biometric technology testing for the Federal Government | ||
19 | in accordance with the USA PATRIOT Act and the Enhanced Border Security | ||
20 | and Visa Entry Reform Act. Specific hardware and software products identified | ||
21 | in this software were used in order to perform the software development. | ||
22 | In no case does such identification imply recommendation or endorsement | ||
23 | by the National Institute of Standards and Technology, nor does it imply that | ||
24 | the products and equipment identified are necessarily the best available | ||
25 | for the purpose. | ||
26 | |||
27 | This software and/or related materials are provided "AS-IS" without warranty | ||
28 | of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, | ||
29 | NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY | ||
30 | or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the | ||
31 | licensed product, however used. In no event shall NIST be liable for any | ||
32 | damages and/or costs, including but not limited to incidental or consequential | ||
33 | damages of any kind, including economic damage or injury to property and lost | ||
34 | profits, regardless of whether NIST shall be advised, have reason to know, | ||
35 | or in fact shall know of the possibility. | ||
36 | |||
37 | By using this software, you agree to bear all risk relating to quality, | ||
38 | use and performance of the software and/or related materials. You agree | ||
39 | to hold the Government harmless from any claim arising from your use | ||
40 | of the software. | ||
41 | |||
42 | *******************************************************************************/ | ||
43 | |||
44 | |||
45 | /*********************************************************************** | ||
46 | LIBRARY: LFS - NIST Latent Fingerprint System | ||
47 | |||
48 | FILE: MORPH.C | ||
49 | AUTHOR: Michael D. Garris | ||
50 | DATE: 10/04/1999 | ||
51 | UPDATED: 10/26/1999 by MDG | ||
52 | To avoid indisciminate erosion of pixels along | ||
53 | the edge of the binary image. | ||
54 | UPDATED: 03/16/2005 by MDG | ||
55 | |||
56 | Contains general support image morphology routines required by | ||
57 | the NIST Latent Fingerprint System (LFS). | ||
58 | |||
59 | *********************************************************************** | ||
60 | ROUTINES: | ||
61 | erode_charimage_2() | ||
62 | dilate_charimage_2() | ||
63 | get_south8_2() | ||
64 | get_north8_2() | ||
65 | get_east8_2() | ||
66 | get_west8_2() | ||
67 | |||
68 | ***********************************************************************/ | ||
69 | |||
70 | #include <morph.h> | ||
71 | #include <string.h> | ||
72 | |||
73 | /************************************************************************* | ||
74 | ************************************************************************** | ||
75 | #cat: erode_charimage_2 - Erodes an 8-bit image by setting true pixels to zero | ||
76 | #cat: if any of their 4 neighbors is zero. Allocation of the | ||
77 | #cat: output image is the responsibility of the caller. The | ||
78 | #cat: input image remains unchanged. This routine will NOT | ||
79 | #cat: erode pixels indiscriminately along the image border. | ||
80 | |||
81 | Input: | ||
82 | inp - input 8-bit image to be eroded | ||
83 | iw - width (in pixels) of image | ||
84 | ih - height (in pixels) of image | ||
85 | Output: | ||
86 | out - contains to the resulting eroded image | ||
87 | **************************************************************************/ | ||
88 | 96 | void erode_charimage_2(unsigned char *inp, unsigned char *out, | |
89 | const int iw, const int ih) | ||
90 | { | ||
91 | 96 | int row, col; | |
92 | 96 | unsigned char *itr = inp, *otr = out; | |
93 | |||
94 | 96 | memcpy(out, inp, iw*ih); | |
95 | |||
96 | /* for true pixels. kill pixel if there is at least one false neighbor */ | ||
97 |
2/2✓ Branch 0 taken 3346 times.
✓ Branch 1 taken 96 times.
|
3442 | for ( row = 0 ; row < ih ; row++ ) |
98 |
2/2✓ Branch 0 taken 101460 times.
✓ Branch 1 taken 3346 times.
|
104806 | for ( col = 0 ; col < iw ; col++ ) |
99 | { | ||
100 |
2/2✓ Branch 0 taken 55956 times.
✓ Branch 1 taken 45504 times.
|
101460 | if (*itr) /* erode only operates on true pixels */ |
101 | { | ||
102 | /* more efficient with C's left to right evaluation of */ | ||
103 | /* conjuctions. E N S functions not executed if W is false */ | ||
104 |
6/6✓ Branch 1 taken 50450 times.
✓ Branch 2 taken 5506 times.
✓ Branch 3 taken 46191 times.
✓ Branch 4 taken 4259 times.
✓ Branch 5 taken 1466 times.
✓ Branch 6 taken 43565 times.
|
151437 | if (!(get_west8_2 ((char *)itr, col , 1 ) && |
105 |
2/2✓ Branch 1 taken 45031 times.
✓ Branch 2 taken 1160 times.
|
96641 | get_east8_2 ((char *)itr, col, iw , 1 ) && |
106 | 46191 | get_north8_2((char *)itr, row, iw , 1 ) && | |
107 | 45031 | get_south8_2((char *)itr, row, iw, ih, 1))) | |
108 | 12391 | *otr = 0; | |
109 | } | ||
110 | 101460 | itr++ ; otr++; | |
111 | } | ||
112 | 96 | } | |
113 | |||
114 | /************************************************************************* | ||
115 | ************************************************************************** | ||
116 | #cat: dilate_charimage_2 - Dilates an 8-bit image by setting false pixels to | ||
117 | #cat: one if any of their 4 neighbors is non-zero. Allocation | ||
118 | #cat: of the output image is the responsibility of the caller. | ||
119 | #cat: The input image remains unchanged. | ||
120 | |||
121 | Input: | ||
122 | inp - input 8-bit image to be dilated | ||
123 | iw - width (in pixels) of image | ||
124 | ih - height (in pixels) of image | ||
125 | Output: | ||
126 | out - contains to the resulting dilated image | ||
127 | **************************************************************************/ | ||
128 | 96 | void dilate_charimage_2(unsigned char *inp, unsigned char *out, | |
129 | const int iw, const int ih) | ||
130 | { | ||
131 | 96 | int row, col; | |
132 | 96 | unsigned char *itr = inp, *otr = out; | |
133 | |||
134 | 96 | memcpy(out, inp, iw*ih); | |
135 | |||
136 | /* for all pixels. set pixel if there is at least one true neighbor */ | ||
137 |
2/2✓ Branch 0 taken 3346 times.
✓ Branch 1 taken 96 times.
|
3442 | for ( row = 0 ; row < ih ; row++ ) |
138 |
2/2✓ Branch 0 taken 101460 times.
✓ Branch 1 taken 3346 times.
|
104806 | for ( col = 0 ; col < iw ; col++ ) |
139 | { | ||
140 |
2/2✓ Branch 0 taken 68855 times.
✓ Branch 1 taken 32605 times.
|
101460 | if (!*itr) /* pixel is already true, neighbors irrelevant */ |
141 | { | ||
142 | /* more efficient with C's left to right evaluation of */ | ||
143 | /* conjuctions. E N S functions not executed if W is false */ | ||
144 |
4/4✓ Branch 1 taken 60228 times.
✓ Branch 2 taken 8627 times.
✓ Branch 3 taken 53736 times.
✓ Branch 4 taken 6492 times.
|
129083 | if (get_west8_2 ((char *)itr, col , 0) || |
145 |
2/2✓ Branch 1 taken 50300 times.
✓ Branch 2 taken 3436 times.
|
113964 | get_east8_2 ((char *)itr, col, iw , 0) || |
146 |
2/2✓ Branch 1 taken 2525 times.
✓ Branch 2 taken 47775 times.
|
104036 | get_north8_2((char *)itr, row, iw , 0) || |
147 | 50300 | get_south8_2((char *)itr, row, iw, ih, 0)) | |
148 | 21080 | *otr = 1; | |
149 | } | ||
150 | 101460 | itr++ ; otr++; | |
151 | } | ||
152 | 96 | } | |
153 | |||
154 | /************************************************************************* | ||
155 | ************************************************************************** | ||
156 | #cat: get_south8_2 - Returns the value of the 8-bit image pixel 1 below the | ||
157 | #cat: current pixel if defined else it returns (char)0. | ||
158 | |||
159 | Input: | ||
160 | ptr - points to current pixel in image | ||
161 | row - y-coord of current pixel | ||
162 | iw - width (in pixels) of image | ||
163 | ih - height (in pixels) of image | ||
164 | failcode - return value if desired pixel does not exist | ||
165 | Return Code: | ||
166 | Zero - if neighboring pixel is undefined | ||
167 | (outside of image boundaries) | ||
168 | Pixel - otherwise, value of neighboring pixel | ||
169 | **************************************************************************/ | ||
170 | 95331 | char get_south8_2(char *ptr, const int row, const int iw, const int ih, | |
171 | const int failcode) | ||
172 | { | ||
173 |
2/2✓ Branch 0 taken 2929 times.
✓ Branch 1 taken 92402 times.
|
95331 | if (row >= ih-1) /* catch case where image is undefined southwards */ |
174 | 2929 | return failcode; /* use plane geometry and return code. */ | |
175 | |||
176 | 92402 | return *(ptr+iw); | |
177 | } | ||
178 | |||
179 | /************************************************************************* | ||
180 | ************************************************************************** | ||
181 | #cat: get_north8_2 - Returns the value of the 8-bit image pixel 1 above the | ||
182 | #cat: current pixel if defined else it returns (char)0. | ||
183 | |||
184 | Input: | ||
185 | ptr - points to current pixel in image | ||
186 | row - y-coord of current pixel | ||
187 | iw - width (in pixels) of image | ||
188 | failcode - return value if desired pixel does not exist | ||
189 | Return Code: | ||
190 | Zero - if neighboring pixel is undefined | ||
191 | (outside of image boundaries) | ||
192 | Pixel - otherwise, value of neighboring pixel | ||
193 | **************************************************************************/ | ||
194 | 99927 | char get_north8_2(char *ptr, const int row, const int iw, | |
195 | const int failcode) | ||
196 | { | ||
197 |
2/2✓ Branch 0 taken 2970 times.
✓ Branch 1 taken 96957 times.
|
99927 | if (row < 1) /* catch case where image is undefined northwards */ |
198 | 2970 | return failcode; /* use plane geometry and return code. */ | |
199 | |||
200 | 96957 | return *(ptr-iw); | |
201 | } | ||
202 | |||
203 | /************************************************************************* | ||
204 | ************************************************************************** | ||
205 | #cat: get_east8_2 - Returns the value of the 8-bit image pixel 1 right of the | ||
206 | #cat: current pixel if defined else it returns (char)0. | ||
207 | |||
208 | Input: | ||
209 | ptr - points to current pixel in image | ||
210 | col - x-coord of current pixel | ||
211 | iw - width (in pixels) of image | ||
212 | failcode - return value if desired pixel does not exist | ||
213 | Return Code: | ||
214 | Zero - if neighboring pixel is undefined | ||
215 | (outside of image boundaries) | ||
216 | Pixel - otherwise, value of neighboring pixel | ||
217 | **************************************************************************/ | ||
218 | 110678 | char get_east8_2(char *ptr, const int col, const int iw, | |
219 | const int failcode) | ||
220 | { | ||
221 |
2/2✓ Branch 0 taken 3748 times.
✓ Branch 1 taken 106930 times.
|
110678 | if (col >= iw-1) /* catch case where image is undefined eastwards */ |
222 | 3748 | return failcode; /* use plane geometry and return code. */ | |
223 | |||
224 | 106930 | return *(ptr+ 1); | |
225 | } | ||
226 | |||
227 | /************************************************************************* | ||
228 | ************************************************************************** | ||
229 | #cat: get_west8_2 - Returns the value of the 8-bit image pixel 1 left of the | ||
230 | #cat: current pixel if defined else it returns (char)0. | ||
231 | |||
232 | Input: | ||
233 | ptr - points to current pixel in image | ||
234 | col - x-coord of current pixel | ||
235 | failcode - return value if desired pixel does not exist | ||
236 | Return Code: | ||
237 | Zero - if neighboring pixel is undefined | ||
238 | (outside of image boundaries) | ||
239 | Pixel - otherwise, value of neighboring pixel | ||
240 | **************************************************************************/ | ||
241 | 124811 | char get_west8_2(char *ptr, const int col, const int failcode) | |
242 | { | ||
243 |
2/2✓ Branch 0 taken 3958 times.
✓ Branch 1 taken 120853 times.
|
124811 | if (col < 1) /* catch case where image is undefined westwards */ |
244 | 3958 | return failcode; /* use plane geometry and return code. */ | |
245 | |||
246 | 120853 | return *(ptr- 1); | |
247 | } | ||
248 |