geo-deep-learning icon indicating copy to clipboard operation
geo-deep-learning copied to clipboard

Use NODATA mask to avoid out of bounds extractions

Open micpilon opened this issue 2 years ago • 1 comments

The extraction of our models is done on the whole extent of the images without considering the NODATA. Frequently we get false positives - especially from water - in the out of bounds area since the band used for extraction exploits the entire 0-255 value range without dedicating any slot to the NODATA. It would be preferable to mask the extractions outside the valid area of the image.

image (3)

In the STAC storage structure that is used as input for the extraction, each "single-band COG" actually includes 2 bands - one for the actual 8-bit dataset and one for its mask.

The mask band is a 8-bit binary array with 0s and 255s

mask_image

gdalinfo

Band 1 Block=512x512 Type=Byte, ColorInterp=Gray Overviews: 11214x16710, 5607x8355, 2803x4177, 1401x2088, 700x1044, 350x522, 175x261 Mask Flags: PER_DATASET Overviews of mask band: 11214x16710, 5607x8355, 2803x4177, 1401x2088, 700x1044, 350x522, 175x261

rasterio

import rasterio src = rasterio.open("/path/to/data") msk = src.read_masks(1)

My suggestion would be to append a step by the end of the inference process to apply the mask to the extraction raster to remove any out of bounds features.

micpilon avatar Sep 21 '22 19:09 micpilon

Good idea I think that's important to crop the over-site prediction.

CharlesAuthier avatar Sep 23 '22 15:09 CharlesAuthier