from PIL import Image
band2 = Image.open('band2.tif')
band3 = Image.open('band3.tif')
band4 = Image.open('band4.tif')
img = Image.merge("RGB",(band4,band3,band2))
band2.tif,band3.tif,band4.tif在USGS(https://earthexplorer.usgs.gov/)中下载。
与正常的.TIF相比,它们可能会有一些差异
错误信息是
/usr/bin/python3.5 /home/lixingang/workspace/20170405/main.py
Traceback (most recent call last):
File "/home/lixingang/workspace/20170405/main.py", line 5, in <module>
img = Image.merge("RGB",(band4,band3,band2))
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2388, in merge
raise ValueError("mode mismatch")
ValueError: mode mismatch
Process finished with exit code 1
最佳答案
您需要将每个通道转换为亮度通道。所以代替这个:
band2 = Image.open('band2.tif')
您需要这样做:
band2 = Image.open('band2.tif').convert('L')
与其他通道相同,合并顺序也应考虑。
关于python - 当我通过python的PIL将.tif合并到RGB波段时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43248094/