用pylab.imshow()显示图像 [英] Showing an image with pylab.imshow()

查看:3136
本文介绍了用pylab.imshow()显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这一切都比较新,我开始在这里做图像分析教程: http: //www.pythonvision.org/basic-tutorial
我已经安装了所有模块但是在遇到障碍之前我没有走得太远。
尝试执行 pylab.imshow(dna)步骤时返回以下错误:

I'm relatively new to all this and I started to do the tutorial on image analysis here: http://www.pythonvision.org/basic-tutorial I have installed all the modules but I didn't get very far before hitting a snag. when trying to perform the pylab.imshow(dna) step it returns the following error:

In [10]: pylab.imshow(dna)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-fc86cadb4e46> in <module>()
----> 1 pylab.imshow(dna)

 /usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc in imshow(X, cmap, norm, aspect,    interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, hold, **kwargs)
   2375         ax.hold(hold)
   2376     try:
-> 2377         ret = ax.imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs)
   2378         draw_if_interactive()
   2379     finally:

/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs)
   6794                        filterrad=filterrad, resample=resample, **kwargs)
   6795 
-> 6796         im.set_data(X)
   6797         im.set_alpha(alpha)
   6798         self._set_artist_props(im)

/usr/lib/pymodules/python2.7/matplotlib/image.pyc in set_data(self, A)
    409         if (self._A.ndim not in (2, 3) or
    410             (self._A.ndim == 3 and self._A.shape[-1] not in (3, 4))):
--> 411             raise TypeError("Invalid dimensions for image data")
    412 
    413         self._imcache =None

TypeError: Invalid dimensions for image data

相当确定我已按照教程中的所有说明进行了写信,但我无法解决问题是

Fairly certain I have followed all the instructions in the tutorial to the letter but I can't work out was is going wrong

谢谢

推荐答案

这就像dna = mahotas中保存的图像一样.imread('dna.jpeg')类型(dna)给出numpy.ndarray和dna.shape给出(1024,1344,1)

"it's just what the image is saved as in dna = mahotas.imread('dna.jpeg') type(dna) gives numpy.ndarray and dna.shape gives (1024, 1344, 1) "

这是问题,如果您提交3D ndarray ,它预计您将拥有3或4个平面(RGB或RGBA)。 (读取堆栈跟踪最后一帧中第410行的代码)。

This is the problem, if you hand in a 3D ndarray, it expects that you will have 3 or 4 planes (RGB or RGBA). (Read the code on line 410 in the last frame of the stack trace).

您只需要使用

dna = dna.squeeze()

imshow(dna.squeeze())

要查看挤压的作用,请参阅以下示例:

To see what squeeze is doing, see the following example:

a = np.arange(25).reshape(5, 5, 1)
print a.shape # (5, 5, 1)
b = a.squeeze()
print b.shape # (5, 5)

这篇关于用pylab.imshow()显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆