I have a raster layer (based on Landsat (30x30m)) of newly emergent lakes after spring snowmelt and subsequent runoff. These are stored in a raster layer. When I look at it, there is a lot of noise (single pixels) everywhere. The raster specs are:
class : SpatRaster
dimensions : 20191, 51818, 1 (nrow, ncol, nlyr)
resolution : 0.0002694946, 0.0002694946 (x, y)
extent : -122.5147, -108.55, 59.38906, 64.83043 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326)
source : dNBR14_02.tif
name : lakes
min value : 0
max value : 2
I want to delete pixels based on their area and not the values! This means deleting all pixels that cover an area of fewer than two pixels.
I am using R.
library(terra)
lakes = rast('path/lakes.tif')
condition = extent < 2 pixels #How can I set an condition for my masking?
x = mask(lakes, condition, inverse = T)