What is the right way to detect edges using gradient filter
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have to apply a the gradient filter to detect edges but i dont know how and when i must convert the image in a proper way to have the correct results.
the image to be filtered is on a grayscale and of type uint8, when i perform the convolution by my own function, what must i convert before and after ?
i get an image with edges but i dont know if it is correct ?
cam = imread("cameraman.pgm");
filtre_x = [ 0 0 0 ; -1 0 1 ; 0 0 0 ];
filtre_y = [ 0 -1 0 ; 0 0 0 ; 0 1 0 ];
Gx = convolution(filtre_x,cam);
Gy = convolution(filtre_y,cam);
magnitude = sqrt( Gx.^2 + Gy.^2 );
imshow(cam);
imshow(magnitude);
here is my function
function img_filtre = convolution(filtre,img)
img = im2double(img);
Taille = size(img);
M = Taille(1); % nombre de ligne
N = Taille(2); % nombre de colonne
img_temp = zeros(M,N);
img_temp = img;
temp = 0;
for i=1:M-2
for j=1:N-2
temp = filtre .* img(i:i+2,j:j+2);
img_temp( i+1 , j+1 ) = sum(temp(:));
end
end
img_filtre = (img_temp); % retourner l'image filtrée
end

0 commentaires
Réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!