Why are you extracting a 3x3 subset of your image in the first place if you have a 5x5 filter?
I would assume you need
Gx=sum(sum(F1.*A(i-2:i+2,j-2:j+2)));
Gy=sum(sum(F2.*A(i-2:i+2,j-2:j+2)));
and your loops will have to run from 3 up to size-2 instead unless you want to do special handling for the edge pixels where you don't have a full neighbourhood.
you should be able to use
or similar functions for this though too, although last time I used it it did annoyingly force a progress bar on you.
Best Answer