As answered by @MrXsquared, SAGA handles it efficiently in a much simpler way. Alternatively, another way to achieve this in QGIS version 3.x is:
Make sure GRASS 7
plugin is installed.
From Processing
> Toolbox
> Search for r.neighbors
In the r.neighbors
window, select the raster layer from the dropdown menu.
Set the Neighborhood Operation
to mode
Set the Neighborhood Size
to the desired filter size (e.g. 4) and click Run
A way to get this working in older QGIS version(v2.x):
Make sure Raster Terrain Analysis
plugin is installed.
Open Raster calculater in QGIS to apply a majority filter. In QGIS Go to "Raster" > "Raster Analysis" > "Raster Calculator"
or simply "Raster" > "Raster Calculator"
(based on your QGIS version) and under expression section to apply a 4x4 Majority Filter
to the raster, use the below expression:
con(majority_filter(rastername, 4, 4), rastername, nodata())
Similarly in ArcGIS you can use "Majority Filter"
tool, which is located in the "Spatial Analyst" toolbox which basically does the same thing by specifying the input layer, kernel size, and the output file name.