Arrays 将数组保存为灰度';L';使用matplotlib的图像?
我正在尝试使用Arrays 将数组保存为灰度';L';使用matplotlib的图像?,arrays,matplotlib,Arrays,Matplotlib,我正在尝试使用plt.imsave()将数组保存为图像。原始图像为16灰度“L”tiff。但我一直在犯错误: Attribute error: 'str' object has no attribute 'shape' figsize = [x / float(dpi) for x in (arr.shape[1], arr.shape[0])] 图像为2048x2048,阵列为2048Lx2048L。我尝试过的一切都不起作用:shape=[20482048],im2.shape(2
plt.imsave()
将数组保存为图像。原始图像为16灰度“L”tiff。但我一直在犯错误:
Attribute error: 'str' object has no attribute 'shape'
figsize = [x / float(dpi) for x in (arr.shape[1], arr.shape[0])]
图像为2048x2048,阵列为2048Lx2048L。我尝试过的一切都不起作用:
shape=[20482048]
,im2.shape(20482048)
。有人能告诉我如何添加形状作为关键字参数吗?或者有没有更简单的方法来做到这一点,最好是避免PIL,因为它似乎有16位灰度TIFF的问题,而我绝对必须使用这种格式?我认为你的论点是相反的。从帮助(plt.imsave)
:
i、 e:
>im2.shape
(256, 256)
>>>plt.imsave(im2,“图片tif”)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
plt.imsave(im2,“图片tif”)
文件“/usr/lib/pymodules/python2.7/matplotlib/pyplot.py”,第1753行,在imsave中
返回_imsave(*args,**kwargs)
文件“/usr/lib/pymodules/python2.7/matplotlib/image.py”,第1230行,在imsave中
figsize=[x/float(dpi)表示arr.shape[:-1]中的x]
AttributeError:“str”对象没有属性“shape”
>>>plt.imsave(“pic.tif”,im2)
>>>
哇,谢谢!我已经盯着它看了一段时间了。是否有一个示例说明如何在任何地方格式化多个参数?我正在尝试将它制作成16位灰度tiff,这样它最终会适合不同的程序。
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from PIL import Image
im2=plt.imread('C:\Documents\Image\pic.tif')
plt.imsave(im2, '*.tif')
Help on function imsave in module matplotlib.pyplot:
imsave(*args, **kwargs)
Saves a 2D :class:`numpy.array` as an image with one pixel per element.
The output formats available depend on the backend being used.
Arguments:
*fname*:
A string containing a path to a filename, or a Python file-like object.
If *format* is *None* and *fname* is a string, the output
format is deduced from the extension of the filename.
*arr*:
A 2D array.
>>> im2.shape
(256, 256)
>>> plt.imsave(im2, "pic.tif")
Traceback (most recent call last):
File "<ipython-input-36-a7bbfaeb1a4c>", line 1, in <module>
plt.imsave(im2, "pic.tif")
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 1753, in imsave
return _imsave(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/image.py", line 1230, in imsave
figsize = [x / float(dpi) for x in arr.shape[::-1]]
AttributeError: 'str' object has no attribute 'shape'
>>> plt.imsave("pic.tif", im2)
>>>