pooja sharma
Junior Member level 2
- Joined
- Sep 20, 2012
- Messages
- 22
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Location
- ajmer,rajesthan
- Activity points
- 1,418
hi,
I am doing my research work on fingerprint matching.This is the Matlab code for the Orientation Estimation;
imwrite(img,'image.bmp','bmp');%img is the squelittized Image.
image=imread('image.bmp');
[w,h] = size(image);
direct = zeros(w,h);
W = 16;
sum_value = 1;
bg_certainty = 0;
blockIndex = zeros(ceil(w/W),ceil(h/W));
%directionIndex = zeros(ceil(w/W),ceil(h/W));
times_value = 0;
minus_value = 0;
center = [];
%Note that the image coordinate system is
%x axis towards bottom and y axis towards right
filter_gradient = fspecial('sobel');
%to get x gradient
Gx = filter2(filter_gradient,o);
%to get y gradient
filter_gradient = transpose(filter_gradient);
Gy = filter2(filter_gradient,o);
g1=Gx.*Gy;
g2=(Gy-Gx).*(Gy+Gx);%gy²-gx²
g3 = (Gx.*Gx) + (Gy.*Gy);
for i=1:W:w
for j=1:W:h
if j+W-1 < h && i+W-1 < w
times_value = sum(sum(g1(i:i+W-1, j:j+W-1)));
minus_value = sum(sum(g2(i:i+W-1, j:j+W-1)));
sum_value = sum(sum(g3(i:i+W-1, j:j+W-1)));
if sum_value ~= 0 && times_value ~=0
bg_certainty = (times_value*times_value + minus_value*minus_value)/(W*W*sum_value);
if bg_certainty > 0.05
blockIndex(ceil(i/W),ceil(j/W)) = 1;
%tan_value = atan2(minus_value,2*times_value);
theta1 = pi/2+ atan2(2*times_value,minus_value)/2;
%now the theta is within [0,pi]
theta2=2*theta1;
Oy = sin(theta2);
Ox=cos(theta2);
f = fspecial('gaussian');
cos2theta = filter2(f,Ox); % Smoothed sine and cosine of
sin2theta = filter2(f,Oy);
theta = atan2(sin2theta,cos2theta)/2;
%center = [center;[round(i + (W-1)/2),round(j + (W-1)/2),theta,bg_certainty]];
center = [center;[round(i + (W-1)/2),round(j + (W-1)/2),theta]];
end;
end;
end;
end;
end;
figure;imagesc(direct);title('Orientation Field');
hold on
[u,v] = pol2cart(center,3),8);
quiver(center,2),center,1),u,v,0.3,'r');
% quiver(x,y,px,py)trace les vecteurs gradient(px,py) en chaque pt (x,y)
colormap Gray;
hold off;
In the following code i get error
Index exceeds matrix dimensions.??? Error in ==> orientation_2 at 45 times_value = sum(sum(g1(i:i+W-1, j:j+W-1))); please help....
I am doing my research work on fingerprint matching.This is the Matlab code for the Orientation Estimation;
imwrite(img,'image.bmp','bmp');%img is the squelittized Image.
image=imread('image.bmp');
[w,h] = size(image);
direct = zeros(w,h);
W = 16;
sum_value = 1;
bg_certainty = 0;
blockIndex = zeros(ceil(w/W),ceil(h/W));
%directionIndex = zeros(ceil(w/W),ceil(h/W));
times_value = 0;
minus_value = 0;
center = [];
%Note that the image coordinate system is
%x axis towards bottom and y axis towards right
filter_gradient = fspecial('sobel');
%to get x gradient
Gx = filter2(filter_gradient,o);
%to get y gradient
filter_gradient = transpose(filter_gradient);
Gy = filter2(filter_gradient,o);
g1=Gx.*Gy;
g2=(Gy-Gx).*(Gy+Gx);%gy²-gx²
g3 = (Gx.*Gx) + (Gy.*Gy);
for i=1:W:w
for j=1:W:h
if j+W-1 < h && i+W-1 < w
times_value = sum(sum(g1(i:i+W-1, j:j+W-1)));
minus_value = sum(sum(g2(i:i+W-1, j:j+W-1)));
sum_value = sum(sum(g3(i:i+W-1, j:j+W-1)));
if sum_value ~= 0 && times_value ~=0
bg_certainty = (times_value*times_value + minus_value*minus_value)/(W*W*sum_value);
if bg_certainty > 0.05
blockIndex(ceil(i/W),ceil(j/W)) = 1;
%tan_value = atan2(minus_value,2*times_value);
theta1 = pi/2+ atan2(2*times_value,minus_value)/2;
%now the theta is within [0,pi]
theta2=2*theta1;
Oy = sin(theta2);
Ox=cos(theta2);
f = fspecial('gaussian');
cos2theta = filter2(f,Ox); % Smoothed sine and cosine of
sin2theta = filter2(f,Oy);
theta = atan2(sin2theta,cos2theta)/2;
%center = [center;[round(i + (W-1)/2),round(j + (W-1)/2),theta,bg_certainty]];
center = [center;[round(i + (W-1)/2),round(j + (W-1)/2),theta]];
end;
end;
end;
end;
end;
figure;imagesc(direct);title('Orientation Field');
hold on
[u,v] = pol2cart(center,3),8);
quiver(center,2),center,1),u,v,0.3,'r');
% quiver(x,y,px,py)trace les vecteurs gradient(px,py) en chaque pt (x,y)
colormap Gray;
hold off;
In the following code i get error
Index exceeds matrix dimensions.??? Error in ==> orientation_2 at 45 times_value = sum(sum(g1(i:i+W-1, j:j+W-1))); please help....