edge detection filters are not detecting my edges for the matrix I created, even though the gradient changes are super obvious

3 views (last 30 days)
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');

Accepted Answer

Ahmet Cecen
Ahmet Cecen on 22 Apr 2018

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');

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!