我是Python新手,我想知道如何保存我添加了一个额外chanel的图像。你知道吗
我导入了一个打开的图像,并添加了两个通道的零数组来尝试转换成一个RBG图像,但是我不能像我通常保存的那样保存。你知道吗
from PIL import Image
import numpy as np
from array import array
i= Image.open('/content/drive/My Drive/DDICM19/imagens/mdb001.jpg')
dim = np.zeros((1024,1024))
R = np.stack((i,dim, dim), axis=2)
dim = np.zeros((1024,1024))
dim.save('/content/drive/My Drive/DDICM19/imagensP/teste.jpg')
它返回:
AttributeError Traceback (most recent call last)
<ipython-input-32-073545b24d75> in <module>()
7 R = np.stack((i,dim, dim), axis=2)
8 dim = np.zeros((1024,1024))
----> 9 dim.save('/content/drive/My Drive/DDICM19/imagensP/teste.jpg')
AttributeError: 'numpy.ndarray' object has no attribute 'save'
快来人帮忙。你知道吗
首先:尝试用零
div
保存numpy数组,而不是用RGB通道R
。你知道吗但是
R
是numpy数组,您必须将它转换回PIL
图像要将灰度转换为RGB,最好对R、G、B重复相同的值,而不是加零
有了零,我就有点奇怪了。它必须使用
int8
或unit8
数据类型才能正确地将其转换为RGB
我也使用size from image来创建带有零的数组,但是您必须记住,image使用
(x,y)
,而array使用(y, x)
,意思是(row, column)
示例
编辑:您还可以将零数组转换为灰度图像,该图像可用作图像中的通道
然后图像看起来很有趣。你知道吗
相关问题 更多 >
编程相关推荐