I am struggling to succesfully filter out anomalous pixels from a Sentinel-1 image band mask (Pixel based), produced in Python.

I am new to Python.

By anomalies, in this situation, I mean individual (or small clumps of) pixels that give off the same backscatter value as water features, but are most likely something else.

I'm currently working on a large scale water body mapping project using SAR (Sentinel-1), using the backscatter as the identifier of permanent water bodies. The pre-processing has all been done using SNAP, using batch processing, but my mask has been created using Python (GDAL and Numpy), due to the amount of images I will be doing this for.

This is my code:

from osgeo import gdal
import numpy as np
ds = gdal.Open(r"Processed_Sentinel1.tif")
ulx, xres, xskew, uly, yskew, yres =ds.GetGeoTransform()
band_ds = ds.GetRasterBand(1)
Sentinel1 = band_ds.ReadAsArray()

Mask_Zero = Sentinel1 > -21  #In units of the raster, e.g. Pixel Value
Ones_array = np.ones((Sentinel1.shape[0],Sentinel1.shape[1]),dtype=np.float32)

Ones_array[Mask_Zero] = 0

out_raster = gdal.GetDriverByName("GTIFF").Create(r"Sentinel1_Mask.tif",Sentinel1.shape[1],Sentinel1.shape[0],1,gdal.GDT_Float32)
out_raster.SetGeoTransform((ulx, xres, xskew, uly, yskew, yres))
band = out_raster.GetRasterBand(1)
out_raster = None
band = None

The following code has produced reasonable results, but with a fair few "false positives" or "anomalies", and for only one image at a time - Please see below:

Results of Mask - indicating areas of water

I know water isn't the only surface that gives off a low backscatter, hence the results, but it would be useful if I could filter out pixels and produce a smoother map. For example, in SNAP, I would apply a median 5x5 filter, and this would usually remove the bulk of the "False Positives".

How would I filter out these "False Positive" pixels according to their surrounding pixels, in Python?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.