【发布时间】:2017-11-12 14:13:57
【问题描述】:
我正在尝试从这个问题中附加的深度图像中分割手。在此过程中,我编写了以下代码,该代码首先处理图像的直方图,然后对处理后的图像进行中值滤波。但是即使在努力解决它之后,这段代码也会不断地出错。
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import scipy
from scipy import ndimage, misc
from scipy.misc import imshow
import skimage
img = mpimg.imread('C:/Users/Prachi/Desktop/kinect_leap_dataset/acquisitions/P1/G1/1_depth.png')
plt.hist(img.ravel(), bins=256, range=(0.0, 1.0))
plt.show()
imgplot = plt.imshow(img, clim=(0.064, 0.068))
#plt.axis('off')
plt.show()
mod_img = ndimage.median_filter(imgplot, 20)
plt.imshow(mod_img)
plt.show()
这是我得到的错误。请帮助解决此错误。我已经检查了有关此错误的每个线程,但未能成功解决它。 似乎代码正在执行中值滤波,但由于在线发生错误而无法显示图像:
plt.imshow(mod_img)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-129-8482175fdf0e> in <module>()
16 plt.show()
17 mod_img = ndimage.median_filter(imgplot, 20)
---> 18 plt.imshow(mod_img)
19 plt.show()
C:\Users\Prachi\AppData\Local\Programs\Python\Python36-32\Anaconda3\lib\site-packages\matplotlib\pyplot.py in imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, hold, data, **kwargs)
3155 filternorm=filternorm, filterrad=filterrad,
3156 imlim=imlim, resample=resample, url=url, data=data,
-> 3157 **kwargs)
3158 finally:
3159 ax._hold = washold
C:\Users\Prachi\AppData\Local\Programs\Python\Python36-32\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1895 warnings.warn(msg % (label_namer, func.__name__),
1896 RuntimeWarning, stacklevel=2)
-> 1897 return func(ax, *args, **kwargs)
1898 pre_doc = inner.__doc__
1899 if pre_doc is None:
C:\Users\Prachi\AppData\Local\Programs\Python\Python36-32\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs)
5122 resample=resample, **kwargs)
5123
-> 5124 im.set_data(X)
5125 im.set_alpha(alpha)
5126 if im.get_clip_path() is None:
C:\Users\Prachi\AppData\Local\Programs\Python\Python36-32\Anaconda3\lib\site-packages\matplotlib\image.py in set_data(self, A)
594 if (self._A.dtype != np.uint8 and
595 not np.can_cast(self._A.dtype, np.float)):
--> 596 raise TypeError("Image data can not convert to float")
597
598 if (self._A.ndim not in (2, 3) or
TypeError: Image data can not convert to float
由于我无法附上图片,所以这里是图片的详细信息。
图像(灰色)是来自数据集“Microsoft Kinect and Leap Motion”的“1_depth.png”,位于
【问题讨论】:
标签: python-3.x image-processing matplotlib jupyter-notebook