In ENVI there's a Majority/Minority Analysis function that allows you to to change spurious/"wrongly classified" pixels within a large single class to that class (it also allows you to enter kernel size and the weight of the center pixel in the kernel).
I have a classified image but I want to fix the "salt-and-pepper" effect of pixels the output image has.
Is there a Majority analysis function post-classification in Google Earth Engine?
What are sample scripts, if ever? And/or where would I start reading up on it? I can't seem to figure out where it is in the Earth Engine tutorial.
If there isn't are there any work-arounds to it? I'm trying to only use freely available software. Is there a function in QGIS perhaps?
Best Answer
Here is an article by the Earth Engine team that does a little explaining on morphological operations within Earth Engine
Fo your case, you may be able to get away with using
image.focal_mode()
(or some combination of morphological ops) for a straightforward clean up of your classes, the Earth Engine team provide a great example of how to do this for land cover image cleanup.However, it sounds like you may want to do some more advanced neighborhood operations by using a filter weight. Here is an example of how you can use weights to clean up a land cover classification:
As you can see, you just create a kernel using whichever weights you want as a list and then apply it on the image using
.reduceNeighborhood()
. I hope this helps!