Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble with Canny Edge Detector - Returning black image

I'm trying to run the canny edge detector on this image:

enter image description here

With this code:

def edges(img):
    from skimage import feature
    img = Image.open(img)
    img.convert('L')
    array = np.array(img)    
    out = feature.canny(array, sigma=1, )
    return Image.fromarray(out,'L')

edges('Q_3.jpg').save('Q_3_edges.jpg')

But I'm just getting a black image back. Any ideas what I could be doing wrong? I tried sigma of 1 and of 3.

enter image description here

like image 584
Greg Avatar asked Aug 31 '25 18:08

Greg


2 Answers

I have the same situation and this helps for me. Before use the Canny filter, just convert your elements of image array to float32 type:

array = np.array(img)
array = array.astype('float32')    
out = feature.canny(array, sigma=1, )
like image 180
user13282626 Avatar answered Sep 02 '25 08:09

user13282626


Your images need to be in the correct range for the relevant dtype, as discussed in the user manual here: http://scikit-image.org/docs/stable/user_guide/data_types.html

This should be automatically handled if you use the scikit-image image I/O functions:

from skimage import io
img = io.imread('Q_3.jpg')
like image 39
Stefan van der Walt Avatar answered Sep 02 '25 07:09

Stefan van der Walt