|
a |
|
b/functions/functions_Kovesi/freqest.m |
|
|
1 |
% FREQEST - Estimate fingerprint ridge frequency within image block |
|
|
2 |
% |
|
|
3 |
% Function to estimate the fingerprint ridge frequency within a small block |
|
|
4 |
% of a fingerprint image. This function is used by RIDGEFREQ |
|
|
5 |
% |
|
|
6 |
% Usage: |
|
|
7 |
% freqim = freqest(im, orientim, windsze, minWaveLength, maxWaveLength) |
|
|
8 |
% |
|
|
9 |
% Arguments: |
|
|
10 |
% im - Image block to be processed. |
|
|
11 |
% orientim - Ridge orientation image of image block. |
|
|
12 |
% windsze - Window length used to identify peaks. This should be |
|
|
13 |
% an odd integer, say 3 or 5. |
|
|
14 |
% minWaveLength, maxWaveLength - Minimum and maximum ridge |
|
|
15 |
% wavelengths, in pixels, considered acceptable. |
|
|
16 |
% |
|
|
17 |
% Returns: |
|
|
18 |
% freqim - An image block the same size as im with all values |
|
|
19 |
% set to the estimated ridge spatial frequency. If a |
|
|
20 |
% ridge frequency cannot be found, or cannot be found |
|
|
21 |
% within the limits set by min and max Wavlength |
|
|
22 |
% freqim is set to zeros. |
|
|
23 |
% |
|
|
24 |
% Suggested parameters for a 500dpi fingerprint image |
|
|
25 |
% freqim = freqest(im,orientim, 5, 5, 15); |
|
|
26 |
% |
|
|
27 |
% See also: RIDGEFREQ, RIDGEORIENT, RIDGESEGMENT |
|
|
28 |
% |
|
|
29 |
% Note I am not entirely satisfied with the output of this function. |
|
|
30 |
|
|
|
31 |
% Peter Kovesi |
|
|
32 |
% School of Computer Science & Software Engineering |
|
|
33 |
% The University of Western Australia |
|
|
34 |
% pk at csse uwa edu au |
|
|
35 |
% http://www.csse.uwa.edu.au/~pk |
|
|
36 |
% |
|
|
37 |
% January 2005 |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
function freqim = freqest(im, orientim, windsze, minWaveLength, maxWaveLength) |
|
|
41 |
|
|
|
42 |
debug = 0; |
|
|
43 |
|
|
|
44 |
[rows,cols] = size(im); |
|
|
45 |
|
|
|
46 |
% Find mean orientation within the block. This is done by averaging the |
|
|
47 |
% sines and cosines of the doubled angles before reconstructing the |
|
|
48 |
% angle again. This avoids wraparound problems at the origin. |
|
|
49 |
orientim = 2*orientim(:); |
|
|
50 |
cosorient = mean(cos(orientim)); |
|
|
51 |
sinorient = mean(sin(orientim)); |
|
|
52 |
orient = atan2(sinorient,cosorient)/2; |
|
|
53 |
|
|
|
54 |
% Rotate the image block so that the ridges are vertical |
|
|
55 |
rotim = imrotate(im,orient/pi*180+90,'nearest', 'crop'); |
|
|
56 |
|
|
|
57 |
% Now crop the image so that the rotated image does not contain any |
|
|
58 |
% invalid regions. This prevents the projection down the columns |
|
|
59 |
% from being mucked up. |
|
|
60 |
cropsze = fix(rows/sqrt(2)); offset = fix((rows-cropsze)/2); |
|
|
61 |
rotim = rotim(offset:offset+cropsze, offset:offset+cropsze); |
|
|
62 |
|
|
|
63 |
% Sum down the columns to get a projection of the grey values down |
|
|
64 |
% the ridges. |
|
|
65 |
proj = sum(rotim); |
|
|
66 |
|
|
|
67 |
% Find peaks in projected grey values by performing a greyscale |
|
|
68 |
% dilation and then finding where the dilation equals the original |
|
|
69 |
% values. |
|
|
70 |
dilation = ordfilt2(proj, windsze, ones(1,windsze)); |
|
|
71 |
maxpts = (dilation == proj) & (proj > mean(proj)); |
|
|
72 |
maxind = find(maxpts); |
|
|
73 |
|
|
|
74 |
% Determine the spatial frequency of the ridges by divinding the |
|
|
75 |
% distance between the 1st and last peaks by the (No of peaks-1). If no |
|
|
76 |
% peaks are detected, or the wavelength is outside the allowed bounds, |
|
|
77 |
% the frequency image is set to 0 |
|
|
78 |
if length(maxind) < 2 |
|
|
79 |
freqim = zeros(size(im)); |
|
|
80 |
else |
|
|
81 |
NoOfPeaks = length(maxind); |
|
|
82 |
waveLength = (maxind(end)-maxind(1))/(NoOfPeaks-1); |
|
|
83 |
if waveLength > minWaveLength & waveLength < maxWaveLength |
|
|
84 |
freqim = 1/waveLength * ones(size(im)); |
|
|
85 |
else |
|
|
86 |
freqim = zeros(size(im)); |
|
|
87 |
end |
|
|
88 |
end |
|
|
89 |
|
|
|
90 |
|
|
|
91 |
if debug |
|
|
92 |
show(im,1) |
|
|
93 |
show(rotim,2); |
|
|
94 |
figure(3), plot(proj), hold on |
|
|
95 |
meanproj = mean(proj) |
|
|
96 |
if length(maxind) < 2 |
|
|
97 |
fprintf('No peaks found\n'); |
|
|
98 |
else |
|
|
99 |
plot(maxind,dilation(maxind),'r*'), hold off |
|
|
100 |
waveLength = (maxind(end)-maxind(1))/(NoOfPeaks-1); |
|
|
101 |
end |
|
|
102 |
end |
|
|
103 |
|