Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skimage Python33 Canny

Long story short, I'm just simply trying to get a canny edged image of image.jpg.

The documentation is very spotty so I'm getting very confused. If anyone can help that'd be greatly appreciated.

from scipy import misc
import numpy as np
from skimage import data
from skimage import feature
from skimage import io


im=misc.imread('image1.jpg')
edges1 = feature.canny(im)
...

And I'm getting this error

ValueError: The parameter `image` must be a 2-dimensional array

Can anyone explain how to create a 2D array from an image file? Thanks!

like image 464
user1985351 Avatar asked Jun 03 '15 04:06

user1985351


1 Answers

I suspect image1.jpg is a color image, so im is 3D, with shape (num_rows, num_cols, num_color_channels). One option is to tell imread to flatten the image into a 2D array by giving it the argument flatten=True:

im = misc.imread('image1.jpg', flatten=True)

Or you could apply canny to just one of the color channels, e.g.

im = misc.imread('image1.jpg')
red_edges = feature.canny(im[:, :, 0])
like image 109
Warren Weckesser Avatar answered Sep 29 '22 13:09

Warren Weckesser