Hello, I'm trying to implement a Laplacian of Guassians Edge Detection using the following code, the issue I have is that Indexing errors pop up when I try to implement the following algorithm
What im trying to do is For each pixel location where the convolution is positive:
a. Test to see of the value of convolution immediately to the left is negative. If so then a zero crossing is present. If the sum of the absolute of the two values is greater than t then this pixel is an edge pixel.
b. repeat step (a) for pixels to the right, above and below the current one.
The edge image, the gradient and filter gradient image should be returned in variables E, F and G respectively
My code:
function [E,F,G] = log_edge(I,N)
if (nargin<2)
N=5;
end
I=double(I(:,:,1));
if (N<=3)
F=[0 1 0; 1 -4 1; 0 1 0]/8;
else
F = fspecial('log',N,floor((N-1)/3)/2);
end
threshK=max(1,-0.5*N+7.5);
E = zeros(size(I));
G = conv2(I,F,'same');
t = 0.75*mean(G(:))*threshK;
[r, c] = size(I);
for i= 1:r
for j = 1:c
if I(i,j-1)>0
res = abs(j+(j-1));
if res>t
E(i,j) = res;
end
end
if I(i-1,j)>0
res = abs(j+(j-1));
if res>t
E(i,j) = res;
end
end
if I(i,j+1)>0
res = abs(j-(j-1));
if res>t
E(i,j) = res;
end
end
if I(i+1,j)>0
res = abs(j+(j-1));
if res>t
E(i,j) = res;
end
end
end
end
return
For reference I have a test script that checks my solution, the script is as follows :
I = double(imread('pout.tif'))/255;
[E,B,G] = log_edge(I,13);
figure
subplot(2,2,1);
imagesc(I); title('Image'); axis equal tight;
subplot(2,2,2);
imagesc(G); title('LoG Output'); axis equal tight;
subplot(2,2,3);
imagesc(B); axis equal tight; title('LoG Filter');
subplot(2,2,4);
imagesc(E); title('Edges'); axis equal tight;
colormap(gray);
drawnow;
[E,B,G] = log_edge(I,15);
figure
subplot(2,2,1);
imagesc(I); title('Image'); axis equal tight;
subplot(2,2,2);
imagesc(G); title('LoG Output'); axis equal tight;
subplot(2,2,3);
imagesc(B); axis equal tight; title('LoG Filter');
subplot(2,2,4);
imagesc(E); title('Edges'); axis equal tight;
colormap(gray);
drawnow;
Thank you for the help and have a good day.