2
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))

the band2.tif,band3.tif,band4.tif are downloaded in USGS(https://earthexplorer.usgs.gov/). they may have some differents compared to the normal .TIF

the error information is

/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
XinGang Li
  • 33
  • 5
  • Possible duplicate of [Python PIL ValueError: images do not match](http://stackoverflow.com/questions/12291641/python-pil-valueerror-images-do-not-match) – alphabetasoup Apr 07 '17 at 22:21

1 Answers1

2

You need to convert each channel into a luminosity channel. So instead of this:

band2 = Image.open('band2.tif')

You need do this:

band2 = Image.open('band2.tif').convert('L')

The same as other channels, for merge the order should also be considered.

ForrestZhang
  • 614
  • 5
  • 14