I want to use 5*5 filter mask on my image in order to detect edges but my image is 3*3 how can i make my image 5*5? Please help me, my code is
%Input Image
A=imread('cameraman.jpg');imshow(A);A=rgb2gray(A);%Preallocate the matrices with zeros
I=zeros(size(A));%Filter Masks
F1=[5 8 10 8 5;4 10 20 10 4;0 0 0 0 0;-4 -10 -20 -10 -4;-5 -8 -10 -8 -5];F2=[-5 -4 0 4 5;-8 -10 0 10 8;-10 -20 0 20 10;-8 -10 0 10 8;-5 -4 0 4 5];A=double(A);for i=1:size(A,1) for j=1:size(A,2) %Gradient operations
Gx=sum(sum(F1.*A(i:i+2,j:j+2))); Gy=sum(sum(F2.*A(i:i+2,j:j+2))); %Magnitude of vector
I(i+1,j+1)=sqrt(Gx.^2+Gy.^2); end endI=uint8(I);figure,imshow(I);title('Filtered Image');%Define a threshold value
Thresh=100;B=max(I,Thresh);B(B==round(Thresh))=0;B=uint8(B);%B=im2bw(B);
figure,imshow(~B);title('Edge detected Image');|edgePixels = nnz(B)
error shows- error using .* "matrix dimension must agree"|
Best Answer