3

I generate a Vegetation Index (VI) with a script and write the resulting 2d array into a .TIF file. When I load it into QGIS, I get the following result:

enter image description here

As you can see, the raster looks very 'granular'. I would like to simplify the raster by grouping large groups of pixels and removing very small 'islands' of pixels. Is there a tool in QGIS available to do this?

EDIT: I am using the suggested Majority Filter of SAGA. In the log, I get the following error however:

QGIS version: 3.16.4-Hannover
Qt version: 5.12.8
GDAL version: 3.2.1
GEOS version: 3.9.0-CAPI-1.16.2
PROJ version: Rel. 7.2.1, January 1st, 2021
SAGA version 7.3.0 is not officially supported - algorithms may encounter issues
Processing algorithm…
Algorithm 'Majority filter' starting…
Input parameters:
{ 'INPUT' : '/home/sytze/Code/DeepLabV3Plus_implementation-single-class/my_mask.tif', 'MODE' : 0, 'RADIUS' : 1, 'RESULT' : 'TEMPORARY_OUTPUT', 'THRESHOLD' : 0 }

grid_filter "Majority Filter" -INPUT "/tmp/processing_DbxJIV/824e2db5d3434b009d4140e50b49825a/mymask.sgrd" -MODE 0 -RADIUS 1 -THRESHOLD 0 -RESULT "/tmp/processing_DbxJIV/a99c9a0147ce45679fcee5414f3d266f/RESULT.sdat" ____________________________

## #####

### ##

# ## ## #### #

##### ## #

# ## ##### #

SAGA Version: 7.3.0

Library: Filter Category: Grid File: /usr/lib/x86_64-linux-gnu/saga/libgrid_filter.so Description: Tools for the manipulation of gridded data.

Tools: [0] Simple Filter [1] Gaussian Filter [2] Laplacian Filter [3] Multi Direction Lee Filter [4] User Defined Filter [5] Filter Clumps [6] Majority/Minority Filter [7] DTM Filter (slope-based) [8] Morphological Filter [9] Rank Filter [10] Mesh Denoise [11] Resampling Filter [12] Geodesic Morphological Reconstruction [13] Binary Erosion-Reconstruction [14] Connectivity Analysis [15] Sieve Classes [16] Wombling (Edge Detection) [17] Wombling for Multiple Features (Edge Detection) [18] Simple Filter (Restricted to Polygons)

Tool Chains: Grid Filters Description: Filters for grids.

Tools: [SieveAndClump] Sieve and Clump [grid_notch_filter] Notch Filter for Grids [grid_list_simple_filter] Simple Filter for Multiple Grids

Error: select a tool type -h or --help for further information

Execution completed in 0.57 seconds Results: {'RESULT': '/tmp/processing_DbxJIV/a99c9a0147ce45679fcee5414f3d266f/RESULT.sdat'}

Loading resulting layers The following layers were not correctly generated. • /tmp/processing_DbxJIV/27317bdae6e44f098ae6f732f727637c/RESULT.sdat • /tmp/processing_DbxJIV/a99c9a0147ce45679fcee5414f3d266f/RESULT.sdat You can check the 'Log Messages Panel' in QGIS main window to find more information about the execution of the algorithm.

Sytze
  • 731
  • 6
  • 18

1 Answers1

4

SAGA majority filter can do that: Menu Processing / Toolbox / Majority filter

enter image description here

See also this answer here: https://gis.stackexchange.com/a/153908/88814

Another option is the GRASS tool r.neighbors. You might use the result togeter with your original picture in the raster calculator. For testing, I used your screenshot:

enter image description here

See result: enter image description here

If you apply raster calculator over this result with an expression like "output@1" != 0, you get a black=0 and white=1 ("boolean") raster. Again using raster calculator, you can multiply your original image with this "boolean" raster to get black values where the boolean is black and leaving the rest as it is.

enter image description here

Result of combining the two rasters with raster calculator. Running raster calculator, you have to repeat this per band and than recombine the separate RGB bands back to a multiband image: enter image description here

Before (left) and after (right): each band of the original input raster was multiplied with the "boolean" raster. The three separate files were than merged with Menu Processing / Toolbox / GDAL / Raster miscellaneous / Merge (or: Menu Raster / Miscellaneous /Merge). This generates a 3-band output raster. Be sure to make settings (min/max values for red, green, blue bands) the same as in the original to get the same look as in the original input: enter image description here

From the "boolen" raster, you can easily create contour polygons: Menu Processing / Toolbox / GDAL / Raster extraction / Countour polygons (needs GDAL 2.4.0 or later). If Contour polygons does not appear in you QGIS processing toolbox, simply select Contour and set the parameter -p, see GDAL help. In the following screenshot, I created to blue polygons from the "boolean" raster: enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208