0

我第一次使用 Python + Scipy + Scikit-image + numpy。

我正在使用页面寻求帮助,我只是稍微更改了给定的代码以获取我喜欢的图像:

tree = misc.imread('C:\\Users\\app\\Pictures\\treephoto1.jpg')
type(tree)
<type 'numpy.ndarray' >
tree.shape, tree.dtype((512, 512), dtype('uint8'))

但我收到以下错误:

 type(tree) <type 'numpy.ndarray'>
                                   ^
SyntaxError: invalid syntax

语法有什么问题?我在Windows上使用的是python 2.7,所有相关的工具包也是按照Python 2.7的。

我需要将图像转换为 2-D numpy 数组,以便我可以使用 canny 边缘检测器。

4

1 回答 1

3

不加思索地写作可能很危险,但在你的情况下这是错误的。您提到的页面显示了这一点:

>>> lena = misc.imread('lena.png')
>>> type(lena)
<type 'numpy.ndarray'>
>>> lena.shape, lena.dtype
((512, 512), dtype('uint8'))

>>>是 Python 的交互式控制台提示字符串。它是有命令去。

<type 'numpy.ndarray'>并且((512, 512), dtype('uint8'))是命令的结果。所以你对应的代码应该只有

tree = misc.imread('C:\\Users\\app\\Pictures\\treephoto1.jpg')
type(tree)
tree.shape, tree.dtype

请注意

type(tree)
tree.shape, tree.dtype

什么都不做,只向您显示有关您的图像数据的信息。

更新

基本上(并非总是)您的图像是分层的。RGB 是三个独立的层。因此,如果您的过滤不知道它,您将不得不自己分离图层。

希望有帮助。

于 2014-04-03T18:02:17.817 回答