Hi,
I am quite new with the snappy API. I would like to implement a python script that transforms Sentinel2 RGB images (encoded in uint16) into small RGB png files (encoded in 8bits).
I managed to export a part of an image with the snap HMI (following the differents SNAP tutorials). So I was wondering if the method that can save images into png is reachable from snappy in python ?
So long, I managed to open and read the several bands corresponding to the Blue, Green and Red channels in uint16 thanks to the readRasterData(x,y,w,h,ouput) method (the readPixels method only returning float instead of uint16).
I also tried the createRgbImage methods but I did not managed to limit the opening to an area of pixels for the moment.
Is there any way to open from a python script several bands corresponding to a small area of the Sentinel image and then save the product as a png file ?
Here is my code so far :
> import snappy
> import numpy as np
> from snappy import GPF
> from snappy import jpy
> from snappy import ProductUtils
> from snappy import ProductData
> imageIO = jpy.get_type('javax.imageio.ImageIO')
> HashMap = jpy.get_type('java.util.HashMap')
> GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis()
> filename = 'path_to_the_XML_file.xml'
> File = jpy.get_type('java.io.File')
> reader = snappy.ProductIO.getProductReader("SENTINEL-2-MSI-20M-UTM30N")
> prod = snappy.ProductIO.readProduct(File(filename))
> B = prod.getBand('B2')
> G = prod.getBand('B3')
> R = prod.getBand('B4')
> RGB = [R, G, B]
> RES = []
> for i in range(len(RGB)):
> Band = ProductData.createInstance(np.zeros((1000, 1000), np.uint16))
> RGB[i].readRasterData(0, 0, 1000, 1000, Band)
> RES.append(Band)
What I am searching now is a function that would take the list RES and save it into a RGB png file.
Best regards