I'm writing an function to detect corners in certain images, it runs forever. If I pause after 2 minutes, it ends up in the function INDEX listed at the bottom ([edit Rik: the give_index function was bold]). BAsed on my playing around with the ebugging tool, it never leaves the INDEX function. The value of INDEX is always zero. I'm not sure why, can anyone deliver some insight?

I apologize for the code dump, please ask any questions if you need clarification.

`clcclearclose allIMAGE_1 = imread('Building1.jpg');IMAGE_2 = imread('CheckerBoard.jpg');SIGMA = 1;X = -2:1:2; % Setting up gaussian filter`

H = [];for i = 1 : 5 H(i) = exp(-X(i)^2/(2*SIGMA^2))/(SIGMA * sqrt(2*3.14));endH = H / min(H);H = H / sum(H); I_s = uint8(conv2(H,H', IMAGE_1));[row,col] = size(I_s);grad = [-1 0 1]; % Setting up gradient

E_x = conv2(I_s,grad);E_x = imresize(E_x,[row, col]);E_y= conv2(I_s,grad');E_y = imresize(E_y, [row,col]);INPUT = 'Input N \n';N = input(INPUT);INPUT = 'Type desired Tau \n';TAU = input(INPUT);L = [];for i = 2:row-1 for j = 2 : col -1 C = [E_x(i,j)^2,E_x(i,j)*E_y(i,j);E_x(i,j)*E_y(i,j),E_y(i,j)^2]; TEMP = eig(C); if TEMP(2) > TAU L(end+1,:) = [TEMP(2),[i,j]]; end endendL = sortrows(L,1,'descend');[row_L, col_L] = size(L);for i = 1 : row_L % Check N

TEMP = L(i,:); row_temp = TEMP(2); col_temp = TEMP(3); % Determine appropiate matrix

if row_temp-N>1 && row_temp+N<row && col_temp-N>1 && col_temp+N<col for m = row_temp-N : row_temp+N for n = col_temp-N : col_temp+N if m ~= row_temp && n ~= col_temp L_row_ind = find(L(:,2) == m); L_col_ind = find(L(:,3) == n); INDEX = give_index(L_row_ind,L_col_ind); if INDEX ~= 0 L(INDEX,:) = 0; end end end end endend%% delete rows contain 0 i.e. garma2 = 0

L = L(any(L,2),:);plot(L(:,2),L(:,3),'x')function INDEX = give_index(x,y)INDEX = 0;for i = 1 : size(x) for j = 1 : size(y) if x(i) == y(j) INDEX = x(i); return end endendend

## Best Answer