使用Imageio -typeError:Imaplotlib:图像数据无效的形状(3,408,612)
我想使用matplotlib进行图像处理。 代码
import matplotlib.pyplot as plt
img = io.imread('/content/drive/MyDrive/fishsampleimages/fish1.jpg')
# io.imwrite("readfish1.jpg", img)
plt.imshow(img)
这是我收到错误和输出的
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-4abe12c2ad85> in <module>()
5
6 # io.imwrite("readfish1.jpg", img)
----> 7 plt.imshow(img)
5 frames
/usr/local/lib/python3.7/dist-packages/matplotlib/image.py in set_data(self, A)
697 or self._A.ndim == 3 and self._A.shape[-1] in [3, 4]):
698 raise TypeError("Invalid shape {} for image data"
--> 699 .format(self._A.shape))
700
701 if self._A.ndim == 3:
TypeError: Invalid shape (3, 408, 612) for image data
I want to do image processing using matplotlib.
Here is the code
import matplotlib.pyplot as plt
img = io.imread('/content/drive/MyDrive/fishsampleimages/fish1.jpg')
# io.imwrite("readfish1.jpg", img)
plt.imshow(img)
I got the error and output as below
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-4abe12c2ad85> in <module>()
5
6 # io.imwrite("readfish1.jpg", img)
----> 7 plt.imshow(img)
5 frames
/usr/local/lib/python3.7/dist-packages/matplotlib/image.py in set_data(self, A)
697 or self._A.ndim == 3 and self._A.shape[-1] in [3, 4]):
698 raise TypeError("Invalid shape {} for image data"
--> 699 .format(self._A.shape))
700
701 if self._A.ndim == 3:
TypeError: Invalid shape (3, 408, 612) for image data
How should I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎在您的源文件中。标准图像将带有(高度,宽度,num_colors)的形状,因此,当您的情况下,
您应该得到形状的结果
,形状似乎是向后的。
要么尝试另一个图像,也可以在显示图像之前重塑图像
可以正确显示您的图像,否则您必须转到图像源并确保正确编写的图像。
The problem seems to be in your source file. A standard image would load with a shape of (height, width, num_colors) so when you do
you should get a result of
in your case, the shape seems to be backwards.
either try with another image or you can reshape the image before showing it
This may show your image correctly, else you would have to go to the source of the image and make sure it is written correctly.