Hi all,
I am trying to create a binary mask for a single raster band in such a way that >75% of the pixels in each 3x3 block of the raster are regarded as valid pixels (1) and 25% or less are regarded as invalid (0).
Much like the above throughout the raster. My thought was to create a numpy mask array and then multiply that by an array of the raster itself but I'm not sure how to create a masked array with such specific details.
Any help would be greatly appreciated.
Solved! Go to Solution.
Within each 3x3 block of cells, what determines the <25% of cells to mask? Would this be random, or based on their value, or always mask the two black cells in your example?
Hi,
Let me give some background on why I need the mask, I have 2 images the first being a 30m land cover image (whose pixels have been filtered earlier based on some conditions), and the 2nd a 10m sentinel image (single band) of the same region.
I need to extract pixels of the land cover image that are covered by 75-100% of the 10m image pixels, for instance there are (9) 10m pixels in each 30m land cover pixel in other areas especially around the edges the coverage may not be 100%, so the condition is to extract each land cover pixel there must be no less than (7) 10m pixels covering them.
I had thought of creating a mask of the 10m pixel image in the format described above which would help in extracting or filtering the 30m land cover pixels.
Thanks.
Thank a lot Brennan, your solution was spot on.
Do you think it's possible to have a result on the number of cells that isn't a whole number?
Let say 7.5 or 8.5, that is remove all cells that are less than 7.5.
Because this is a simplified approach with stacked, snapped rasters that works by counting the number of small cells inside the larger cells, it's limited to whole numbers. Another approach would be to create a polygon feature class (probably Create Fishnet) that exactly matches each cell of your 30m raster, then you could run Zonal Stats on those polygons with your 10m raster (after reclassifying it to be either 1 or 0), where the zonal average would be in the range 0-1 and then you could use a threshold of 0.75 to select only the polygons you want and then extract your 30m raster to that selection.