Exclude isolated single pixels from a binary mask

I’ve another idea what you can do.

You can first run a low-pass 3x3 filter and afterwards you use the bands to filter out the low values.
In the image on the left white is 255 and black is zero.
In the right image after low-pass the values vary between 0 and 255 lowest non-zero is ~15.
The single pixel has a value of 63.75. So in a second step i can ouse a band maths expression to set all values below 64 to zero and all other to one.

pins_lp3 < 64 ? 0 : 1

By doing this I get the result at the bottom. And only the single pixel is removed.

So your graph could look like this.
image
What you need to know is that the output name of the band which is filtered is the same as the input.
So, you have to use this name in the expression.

2 Likes