5

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).

1

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"
    
0

There is no need to polygonize your raster layer (raster to polygon operation is slow IMO). You can directly mask the target raster pixels with the QGIS raster calculator and classified raster. Just open the properties of the classified raster and get the class values you would like to mask. Then open the raster calculator and type the band formula, for e.g.:

(classifiedRasterBand = 0) * myTargetRaster 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.