Here is the effect of applying modal filtering to the classification applied to the Eau d’Heure lakes image. This filtering did indeed remove most of the isolated pixels that interfered with a reading of the image, but also changed all of the groups of pixels’ shapes by softening their outlines.
One possible alternative is to use filters that allow you to specify the exact context in which a pixel must be reassigned to another class. This can be done using the dilation and erosion filters of mathematical morphology. These filters are applied to a binary mask of the class that one wants to process. In a 3x3 mobile window, dilation consists in enlarging the class’s mask by assigning the mask’s value to any pixel that is immediately next to it. The reverse operation, erosion, is then performed and the difference between the resulting and original masks enables one to single out the pixels that must be reassigned to a new class. As the illustration shows, dilation and erosion can be performed using larger windows.