
Purpose
Masking is important in remote sensing analysis as it is used to exclude areas not intended for processing and thereby analysis. This focuses the analysis and cuts down processing times as only what’s important is worked on.
General masking is where areas common to all image time steps are masked. For example in this study, land above the high water level where mangroves don’t grow, is excluded. Masking that affects only specific time steps, for example cloud or haze, is covered in the next vignette.
Use the general_mask() function
To mask out an area, a raster mask is applied to a raster of interest. Usually a mask is generated with 1’s and 0 values (or NA’s), where 1’s indicate the area of interest. When the mask is applied, any areas where there is a 0 is excluded.
The example data includes a land mask and is the only mask residing
in the raster_masks/
directory and this will be applied
below.
# The general form of the function is (NOTE the default parameters)
# general_mask <- function(irast, imask, ext = ".tif", mval = 0)
# the mval parameter is the "mask value" i.e. what value to mask out.
# We only need to assign the first 2 parameters as the defaults are fine
irast <- "veg_dens"
imask <- "raster_masks"
# Run the function
general_mask(irast, imask)
- irast - input veg density rasters directory.
- imask - input masks raster directory.
What’s going to happen?
A new directory will be created, veg_dens_mskd/
and the
masked vegetation density rasters will be written to it. These will be
the inputs for other functions.
NOTE on general masks. The above example is only
applying one land mask, however if there were multiple masks then they
would also be applied. This is so you can have different masks relating
to different entities, such as one for land, one for reefs etc. When the
general_mask()
function looks for input masks it does not
recursively examine the imask
directory which is why cloud
masks can reside in a directory at that location too.