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

3 ビュー (過去 30 日間)
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');

採用された回答

Ahmet Cecen
Ahmet Cecen 2018 年 4 月 22 日

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by