Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [S,P,R]=deal(double(rgb2gray(imread('peppers.png'))));
- [r c] = size(S);
- for i=1:r-2
- for j=1:c-2
- %Sobel mask
- Sx=((2*S(i+2,j+1)+S(i+2,j)+S(i+2,j+2))-(2*S(i,j+1)+S(i,j)+S(i,j+2)));
- Sy=((2*S(i+1,j+2)+S(i,j+2)+S(i+2,j+2))-(2*S(i+1,j)+S(i,j)+S(i+2,j)));
- S(i,j) = sqrt(Sx.^2+Sy.^2);
- %Perwitt mask
- Px=((P(i+2,j+1)+P(i+2,j)+P(i+2,j+2))-(P(i,j+1)+C(i,j)+P(i,j+2)));
- Py=((P(i+1,j+2)+P(i,j+2)+P(i+2,j+2))-(P(i+1,j)+P(i,j)+P(i+2,j)));
- P(i,j)=sqrt(Px.^2+Py.^2);
- %Roberts mask
- Rx = R(i+2, j+2)-R(i+1,j+1);
- Ry = R(i+1, j+2)-R(i+2, j+1);
- R(i,j)=sqrt(Rx.^2+Ry.^2);
- end
- end
- figure(1),imshow(uint8(S)); title('Sobel gradient');
- figure(2),imshow(uint8(P)); title('Prewitt gradient');
- figure(3),imshow(uint8(R)); title('Roberts gradient');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement