GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 44 / 0 / 44
Functions: 100.0% 6 / 0 / 6
Branches: 100.0% 36 / 0 / 36

libfprint/nbis/mindtct/morph.c
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 100 void erode_charimage_2(unsigned char *inp, unsigned char *out,
89 const int iw, const int ih)
90 {
91 100 int row, col;
92 100 unsigned char *itr = inp, *otr = out;
93
94 100 memcpy(out, inp, iw*ih);
95
96 /* for true pixels. kill pixel if there is at least one false neighbor */
97
2/2
✓ Branch 16 → 17 taken 3624 times.
✓ Branch 16 → 18 taken 100 times.
3724 for ( row = 0 ; row < ih ; row++ )
98
2/2
✓ Branch 14 → 3 taken 111668 times.
✓ Branch 14 → 15 taken 3624 times.
115292 for ( col = 0 ; col < iw ; col++ )
99 {
100
2/2
✓ Branch 3 → 4 taken 60879 times.
✓ Branch 3 → 13 taken 50789 times.
111668 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 5 → 6 taken 55011 times.
✓ Branch 5 → 12 taken 5868 times.
✓ Branch 7 → 8 taken 50407 times.
✓ Branch 7 → 12 taken 4604 times.
✓ Branch 11 → 12 taken 1282 times.
✓ Branch 11 → 13 taken 47908 times.
165080 if (!(get_west8_2 ((char *)itr, col , 1 ) &&
105
2/2
✓ Branch 9 → 10 taken 49190 times.
✓ Branch 9 → 12 taken 1217 times.
105418 get_east8_2 ((char *)itr, col, iw , 1 ) &&
106 50407 get_north8_2((char *)itr, row, iw , 1 ) &&
107 49190 get_south8_2((char *)itr, row, iw, ih, 1)))
108 12971 *otr = 0;
109 }
110 111668 itr++ ; otr++;
111 }
112 100 }
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 100 void dilate_charimage_2(unsigned char *inp, unsigned char *out,
129 const int iw, const int ih)
130 {
131 100 int row, col;
132 100 unsigned char *itr = inp, *otr = out;
133
134 100 memcpy(out, inp, iw*ih);
135
136 /* for all pixels. set pixel if there is at least one true neighbor */
137
2/2
✓ Branch 16 → 17 taken 3624 times.
✓ Branch 16 → 18 taken 100 times.
3724 for ( row = 0 ; row < ih ; row++ )
138
2/2
✓ Branch 14 → 3 taken 111668 times.
✓ Branch 14 → 15 taken 3624 times.
115292 for ( col = 0 ; col < iw ; col++ )
139 {
140
2/2
✓ Branch 3 → 4 taken 75586 times.
✓ Branch 3 → 13 taken 36082 times.
111668 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 5 → 6 taken 66206 times.
✓ Branch 5 → 12 taken 9380 times.
✓ Branch 7 → 8 taken 59164 times.
✓ Branch 7 → 12 taken 7042 times.
141792 if (get_west8_2 ((char *)itr, col , 0) ||
145
2/2
✓ Branch 9 → 10 taken 55776 times.
✓ Branch 9 → 12 taken 3388 times.
125370 get_east8_2 ((char *)itr, col, iw , 0) ||
146
2/2
✓ Branch 11 → 12 taken 2578 times.
✓ Branch 11 → 13 taken 53198 times.
114940 get_north8_2((char *)itr, row, iw , 0) ||
147 55776 get_south8_2((char *)itr, row, iw, ih, 0))
148 22388 *otr = 1;
149 }
150 111668 itr++ ; otr++;
151 }
152 100 }
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 104966 char get_south8_2(char *ptr, const int row, const int iw, const int ih,
171 const int failcode)
172 {
173
2/2
✓ Branch 2 → 3 taken 3048 times.
✓ Branch 2 → 4 taken 101918 times.
104966 if (row >= ih-1) /* catch case where image is undefined southwards */
174 3048 return failcode; /* use plane geometry and return code. */
175
176 101918 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 109571 char get_north8_2(char *ptr, const int row, const int iw,
195 const int failcode)
196 {
197
2/2
✓ Branch 2 → 3 taken 3075 times.
✓ Branch 2 → 4 taken 106496 times.
109571 if (row < 1) /* catch case where image is undefined northwards */
198 3075 return failcode; /* use plane geometry and return code. */
199
200 106496 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 121217 char get_east8_2(char *ptr, const int col, const int iw,
219 const int failcode)
220 {
221
2/2
✓ Branch 2 → 3 taken 3996 times.
✓ Branch 2 → 4 taken 117221 times.
121217 if (col >= iw-1) /* catch case where image is undefined eastwards */
222 3996 return failcode; /* use plane geometry and return code. */
223
224 117221 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 136465 char get_west8_2(char *ptr, const int col, const int failcode)
242 {
243
2/2
✓ Branch 2 → 3 taken 4204 times.
✓ Branch 2 → 4 taken 132261 times.
136465 if (col < 1) /* catch case where image is undefined westwards */
244 4204 return failcode; /* use plane geometry and return code. */
245
246 132261 return *(ptr- 1);
247 }
248