我认为您的失真是由您将原始图像分割成各个频段,然后在将其合并之前再次调整其大小引起的;
`
image=Image.open("your image")
print(image.size) #size is inverted i.e columns first rows second eg: 500,250
#convert to array
li_r=list(image.getdata(band=0))
arr_r=np.array(li_r,dtype="uint8")
li_g=list(image.getdata(band=1))
arr_g=np.array(li_g,dtype="uint8")
li_b=list(image.getdata(band=2))
arr_b=np.array(li_b,dtype="uint8")
# reshape
reshaper=arr_r.reshape(250,500) #size flipped so it reshapes correctly
reshapeb=arr_b.reshape(250,500)
reshapeg=arr_g.reshape(250,500)
imr=Image.fromarray(reshaper,mode=None) # mode I
imb=Image.fromarray(reshapeb,mode=None)
img=Image.fromarray(reshapeg,mode=None)
#merge
merged=Image.merge("RGB",(imr,img,imb))
merged.show()
`
这很好用!
0
因此,我有一组数据,可以转换为R,G,B波段的单独的numpy数组。现在,我需要将它们组合以形成RGB图像。
我尝试使用“图像”来完成这项工作,但需要将“模式”归因于此。
我试图做个把戏。我将使用Image.fromarray()将数组转换为图像,但是当Image.merge要求将“ L”模式图像合并时,默认情况下它将达到“ F”模式。如果我首先将fromarray()中array的属性声明为'L',则所有RGB图像都会失真。
但是,如果我保存图像然后打开它们然后合并,则效果很好。图像以“ L”模式读取图像。
现在我有两个问题。
首先,我不认为这是一种优雅的工作方式。所以,如果有人知道更好的方法,请告诉
其次,Image.SAVE无法正常工作。以下是我遇到的错误:
请提出解决方案。
并且请注意,图像大小约为4000x4000。