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,Sentinel1.shape),dtype=np.float32) Ones_array[Mask_Zero] = 0 out_raster = gdal.GetDriverByName("GTIFF").Create(r"Sentinel1_Mask.tif",Sentinel1.shape,Sentinel1.shape,1,gdal.GDT_Float32) out_raster.SetGeoTransform((ulx, xres, xskew, uly, yskew, yres)) band = out_raster.GetRasterBand(1) band.WriteArray(Ones_array) 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:
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?