Index exceeds matrix dimensions
Show older comments
In the following code i get error
<%This is the Matlab code for the Orientation Estimation;
clear all; close all; clc;
image=imread('input_3.bmp');
%imwrite(img,'input_3.bmp','bmp');%img is the squelittized Image.
%image=imread('input_3.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,0);
%to get y gradient
filter_gradient = transpose(filter_gradient);
Gy = filter2(filter_gradient,0);
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;
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 for find the error ??? Index exceeds matrix dimensions.
Error in ==> orientation_2 at 48 times_value = sum(sum(g1(i:i+W-1, j:j+W-1)));....
if anyone have the code for find orientation in fingerprint image so please help me...
Accepted Answer
More Answers (0)
Categories
Find more on Axes Transformations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!