I'm trying to merge Sentinel 2 bands RGB bands with rasterio like this:
import rasterio
import numpy as np
from rasterio import plot
from rasterio.plot import show
band2=rasterio.open("B02.jp2")
band3=rasterio.open("B03.jp2")
band4=rasterio.open("B04.jp2")
rgb=rasterio.open('rgb.tiff', 'w', driver='Gtiff',
width=band2.width, height=band2.height,
count=3,
crs=band2.crs,
transform=band2.transform,
dtype='uint16')
rgb.write(band4.read(1),1)
rgb.write(band3.read(1),2)
rgb.write(band2.read(1),3)
rgb.close()
This works as expected and creates a RGB-GeoTIFF that is properly displayed in QGIS. However if I try to visualize it with rasterio, I get an almost black image:
show(plot.adjust_band(rasterio.open('rgb.tiff').read([1,2,3])))
when I inspect the normalized values the mean for each band is around 0.05. Is there something wrong how I create the RGB?
Band 1 Block=10980x1 Type=UInt16, ColorInterp=Gray Band 2 Block=10980x1 Type=UInt16, ColorInterp=Undefined Band 3 Block=10980x1 Type=UInt16, ColorInterp=Undefined