edge detection filters are not detecting my edges for the matrix

Illustration
Aaron Connell - 2023-03-01T13:10:09+00:00
Question: edge detection filters are not detecting my edges for the matrix

edge detection filters are not detecting my edges for the matrix I created, even though the gradient changes are super obvious   I am trying to use the three edge filters below to show the edges of the image I created. For some reason the filters keep returning matrixes of zeros (black) even though there is super obvious gradient changes. Why are the filters not detecting the edges? Below is the code I have, and you can see from the images they are all black. clear figure im=200*ones(10,10); im(3:5,3:8)=50; im(6:8,4:7)=50; im2=mat2gray(im+round(9*randn(10,10))) edge_p = edge(im2,'prewitt') edge_s = edge(im2,'sobel') edge_r = edge(im2,'roberts'); subplot(2,2,1); imshow(im2); title('Original Grayscale Image'); subplot(2,2,2); imshow(edge_p); title('Edge Using Prewit'); subplot(2,2,3); imshow(edge_s); title('Edge Using Sobel'); subplot(2,2,4); imshow(edge_r); title('Edge Using Roberts');  

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

I believe the very small size of your image is messing with the heuristics of the "edge" function to find thresholds. You can either define thresholds manually like:

 

 

edge_s = edge(im2,'sobel',0.1);

or resize your image before the operation:

im2 = resize(im2,5,'nearest');

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!