I previously used fromarray to create stacked image using three numpy arrays:
from PIL import Image
import numpy as np
rgbArray = np.zeros((4224,2560,3), 'uint8')
rgbArray[..., 0] = layerA*256
rgbArray[..., 1] = LayerB*256
rgbArray[..., 2] = LayerC*256
img = Image.fromarray(rgbArray)
img.save('stack_n.jpeg')
I am trying to adopt this approach for one numpy array as below:
gsArray = np.zeros((4224,2560,1), 'uint8')
gsArray = layer4_norm*256
layer4t = Image.fromarray(gsArray)
layer4t.save('layer4t.jpeg')
but it produces the following error. Please let me know how I can resolve it.
AttributeError Traceback (most recent call last)
<ipython-input-72-bcfbe3849ecb> in <module>()
1 gsArray = np.zeros((4224,2560,1), 'uint8')
2 gsArray = layer4_norm*256
----> 3 layer4t_normt = Image.fromarray(gsArray)
4 layer4t.save('layer4t.jpeg')
/usr/local/lib/python3.6/dist-packages/PIL/Image.py in fromarray(obj, mode)
2668 .. versionadded:: 1.1.6
2669 """
-> 2670 arr = obj.__array_interface__
2671 shape = arr["shape"]
2672 ndim = len(shape)
AttributeError: 'list' object has no attribute '__array_interface__'
question from:
https://stackoverflow.com/questions/65849260/writing-a-numpy-array-to-single-band-image 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…