As from ESA snap, for a RGB image we should put Band 4 into Red Channel, Band 3 into Green Channel and Band 2 into Blue Channel. How can we read those bands with python into a numpy
array so we could do whatever image processing we want and then save a RGB image on disk?
from snappy import Product
from snappy import ProductIO
import numpy as np
import cv2
product = ProductIO.readProduct(path_to_product)
width = product.getSceneRasterWidth()
height = product.getSceneRasterHeight()
# Natural colors
red = product.getBand('B4')
green = product.getBand('B3')
blue = product.getBand('B2')
For example here is the type of one of the above variables (same for the others):
type(red)
# org.esa.snap.core.datamodel.Band
How can I get numpy arrays from these data, and subsequently save them to disk as jpg images?
So far we have a rgb image in a
numpy
array with float values. In order to write to disk as a jpg image, we first clip large values to make image brighter, and then convert the image to 0-255 integer values.