[GIS] Mask pixel values in Raster image QGIS

extract-by-maskqgis

I am looking at classifying an image to identify crop types.

I am interested in masking out all other landcover classes except crop class in the band stack false colour composite image e.g. buildings, roads, water, cloud,… in QGIS.

How would I go about this?

(a) classify the image, convert classes from raster to vector and clip the raster image to the vegetation vector polygon

or

(b) mask out the pixels using band math where by the pixel values for the unwanted classes are equaled to 0

I think both of these should theoretically work (apart from risk of pixel misclassification in approach (a) and an issue whereby the layer stack cannot be chosen as a source file in approach (b).

Best Answer

I think the proper way to extract only the vegetation/cropland cover is to do the following:

  1. Create a land use/cover map by classifying the image first using supervised/unsupervised classification technique of your choice;
  2. Convert the final land use/cover map from raster to vector
  3. Select the class that represents the vegetation/cropland cover and save it to a new shapefile.
  4. If you want the output as raster image to keep only the vegetation/cropland cover and mask other classes, you can use the following expression in QGIS Raster Calculator:

    ("ImageName@1" = PixelValueOfCrop) *"ImageName@1"