6

I have a classified landcover raster which also contains the classes "clouds" (pixelvalue 5) and "shadows" (pixelvalue 10). I want to eliminate them by replacing these two classes by the majority of the surrounding classes e.g. "forest" (value 3) or "agriculture" (value 7). I want to do this automatically for the whole raster.

It does not matter whether the clouds are replaced only by the "biggest" neighbouring class or by percentage of the "biggest" and "smaller" neighbouring classes.

Here is an example: White are clouds, black shadows, green forest and yellow agriculture.

enter image description here

Cloud-Masking or mosaicing was not an option in my case. So, how can I postprocess the classification and elminate these classes using QGIS? Is it possible to perform a majority filter on a specific class?

2 Answers 2

6

You can convert your clouds and shadows to null / no data (e.g. by using r.null) and then interpolate those "null areas" based on the surrounding values using the Fill nodata tool, see the documentation here: https://docs.qgis.org/2.8/en/docs/user_manual/processing_algs/gdalogr/gdal_analysis/fillnodata.html

Additionally, there is a Fill gaps tool.

https://grass.osgeo.org/grass76/manuals/addons/r.fill.gaps.html

However, using Close gaps with stepwise resampling from SAGA processing toolbox might be a good alternative to Fill gaps in your usecase. Just set its Resampling method to Nearest Neighbour. This will prevent you from receiving interpolated float values from surrounding pixels and just takes the nearest (interpolated) integer neighbour value instead.

http://www.saga-gis.org/saga_tool_doc/2.2.7/grid_tools_29.html

Keep in mind the Rastertype after interpolation. Default output seems to be float32 by default. You might want to change this back to integer.

1
  • 1
    Figured out the SAGA Tool Close gaps with stepwise resampling gives a much better result for my usecase because I can set Resampling method to Nearest Neighbour. Therefore it does not create interpolated float values from its neighbours but just takes the nearest neighbour. Result is still not perfect, but better than with Fill Gaps tool.
    – MrXsquared
    Commented Nov 19, 2019 at 21:00
4

You can also do it in one step without replacing values with NULL values. Use the SAGA provided Majority filter for that:

2
  • 1
    Sorry, but I don't get how I can eliminate only two specific classes in my image using this. I can only perform the majority filter on all classes. Maybe I have overlooked something?
    – MrXsquared
    Commented Nov 19, 2019 at 16:09
  • I think that is right, then I missunderstood your question...sorry
    – eurojam
    Commented Nov 19, 2019 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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