jpeg2000->gtiff
noneunknown
python
2 years ago
1.6 kB
3
Indexable
Never
import os import geopandas import rasterio as rio from PIL import Image Image.MAX_IMAGE_PIXELS = 300000000 ## Transformando em RGB # Caminho das imagens: B04 = Red, B03 = Green, B02 = Blue redPath = "assets/geodata/dump_r2/S2A_MSIL2A_20220512T133231_N0400_R081_T22JCP_20220512T202012.SAFE/GRANULE/L2A_T22JCP_A035971_20220512T133948/IMG_DATA/R10m/T22JCP_20220512T133231_B04_10m.jp2" greenPath = "assets/geodata/dump_r2/S2A_MSIL2A_20220512T133231_N0400_R081_T22JCP_20220512T202012.SAFE/GRANULE/L2A_T22JCP_A035971_20220512T133948/IMG_DATA/R10m/T22JCP_20220512T133231_B03_10m.jp2" bluePath = "assets/geodata/dump_r2/S2A_MSIL2A_20220512T133231_N0400_R081_T22JCP_20220512T202012.SAFE/GRANULE/L2A_T22JCP_A035971_20220512T133948/IMG_DATA/R10m/T22JCP_20220512T133231_B02_10m.jp2" ## Pega as bandas """ redConv = Image.open(redPath) redConv.save("red.tiff", "TIFF") greenConv = Image.open(greenPath) greenConv.save("green.tiff", "TIFF") blueConv = Image.open(bluePath) blueConv.save("blue.tiff", "TIFF") """ red = rio.open(redPath) green = rio.open(greenPath) blue = rio.open(bluePath) # Cria o arquivo RGB, sendo que driver é o formato, count a quantidade de bandas, crs o sistema de coordenadas referenciadas e transform a afinidade espacial geográfica. rgb = rio.open("RGB.tiff", 'w+', driver="Gtiff", width=red.width, height=red.height, count=3, crs=red.crs, transform=red.transform, dtype=red.dtypes[0]) rgb.write(blue.read(1), 1) rgb.write(green.read(1), 2) rgb.write(red.read(1), 3) rgbData = rgb.read() print(rgbData) print(rgbData.shape) print(red.shape) print(green.shape) print(blue.shape) rgb.close()