I have a categorical raster I use for a land use map. The categorical raster is further being polygonized and then adjusted in a graphical software for the target map. The raster datas' resolution is borderline for the target map scale, so we do not any generalization before hand and try to retain as much detail as possible.
But, in order to prevent polygons of the same class touching at an edge, we need to remove these cell constellations in the underlying raster.


Boundary Clean with sort type "ascending" removes some of these configurations, while retaining detail, but some diagonal connections remain.

Majority filtering with 8 neighbors is also retaining some of these vertical connections.
I thought about looking at a moving window of 4 cells where "if 2 cells have the same value and are diagonal to each other and the other two cells have another value" it will randomly assign one of the other two cells the value of the two cells being connected over a diagonal, creating a cushion that will not result in dangling connections after polygonization. If the other two cells also have a shared value then it will randomly choose which connection is being cushioned.

Has somebody already implemented something like this? I guess this cushioning could also introduce new isolated diagonal connections...