Outliers Detection in Sentinel Bands

25 Views Asked by At

I have tifs of Sentinel bands for a specific tile, I have already implemented cloudmasking. I should now create an RGB in 8bit, but first I have to reduce outliers in my images and reduce gaussian noise. I am really confused in the process of reducing outliers, normalizing, rescaling images. I am working on Python and a snippet of my code is:

# Use of cloudmasked images from previous exercise
denoised_imgs = {}

for band, values in cloudfree.items():
    print(f'band max is {values.max()} and min is {values.min()}')

    # Outlier Detection
    mean_val = np.mean(values)
    print(f'mean: {mean_val}')
    std_val = np.std(values)
    print(f'std: {std_val}')
    z_scores = (values - mean_val) / std_val

    thershold = 2
    outlier_mask  = np.abs(z_scores) > thershold

    values[outlier_mask] = mean_val

    rescaled = np.clip(values, 0, 255).astype(np.uint8)

    min_val = np.min(values)
    max_val = np.max(values)
    normalized_data = ((values - min_val) / (max_val - min_val)) * 255
    
    # Reduce Gaussian Blur
    # img_blur = cv2.bilateralFilter(clipped_band, 9, 5, 5)

    denoised_imgs[band] = normalized_data

# Stack RGB-denoised
rgb_denoised = np.dstack([denoised_imgs['B04'], denoised_imgs['B03'], denoised_imgs['B02']])
cropped_denoised = rgb_denoised[uly_pixel:lry_pixel, ulx_pixel:lrx_pixel]

cloudfree: dictionary where keys are the band names and values the arrays of image (values.dtype('uint16'))

Thanks! L.

I am trying to figure out outliers detection methods in python. I am using these libraries, and i would prefer to stick with them for now. But I am open to suggestions of other libraries for future studying.

# Import libraries
from pathlib import Path
from osgeo import gdal
import numpy as np
import cv2
import matplotlib.pyplot as plt
0

There are 0 best solutions below