Index exceeds matrix dimensions

1 次查看(过去 30 天)
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...

采纳的回答

Walter Roberson
Walter Roberson 2013-3-30
You have
Gx = filter2(filter_gradient,0);
that is applying the filter to the scalar value 0. The result is going to be a scalar value. You do the same thing for Gy. You then calculate gl = Gx .* Gy;, so gl is going to be a scalar as well. You then try to access the scalar gl at indices as high as the size of the image.
  2 个评论
pooja dixit
pooja dixit 2013-3-30
编辑:pooja dixit 2013-3-30
thanks for reply.. i cant understand how to solve this prob ..plz help me out of this... do you have this code ... i need it ... for my work ... can u help me by sending it to ... poojadixit565@gmail.com ... i will be grateful to you ....
Walter Roberson
Walter Roberson 2013-3-30
I do not have the code, but I would imagine that you should be filtering your image rather than the scalar 0

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by