I’m trying to save an array as an image using plt.imsave(). The original image is a 16 greyscale ‘L’ tiff. But I keep on getting the error:
Attribute error: 'str' object has no attribute 'shape'
figsize = [x / float(dpi) for x in (arr.shape[1], arr.shape[0])]
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')
The image is 2048×2048, the array is 2048Lx2048L. Everything I’ve tried doesn’t work: shape=[2048,2048], im2.shape(2048,2048). Can anybody tell me out how to add shape as a keyword argument? Or is there any easier way to do this, preferably avoiding PIL, since it seems to have issues with 16-bit greyscale tiffs and I absolutely have to use that format?
I think you’ve got the arguments backwards. From
help(plt.imsave):i.e.: