0

I am trying to apply post-processing (Classification Sieve) in GEE to my classified raster, just as we apply in QGIS (used 4x4) or (8x8). Remove unwanted and noise pepper effects from the classification raster by assigning these pixels to the majority/Neighborhood class. I have followed the previously asked a similar question Similar Question Asked Earlier that says to use:

image.reduce neighborhood(ee.Reducer.mode(), ee.Kernel.circle(1))
image.focalMode(3);

However, I am not receiving the required result. Please see the screenshot attached below before applying these techniques (Classified Raster) and the second screenshot (Post Classified Raster) after applying different values, e.g., ee.kernel.circle(10), which is merely changing these pixel edges into a rounded form.

I want to eliminate these single pixels from the image and assign other single-categorized pixels to the majority class. I have also tried the kernel-weighted mode, it also does the same thing. Any suggestion?

Classified Raster Post Classified Raster

1 Answer 1

1

I am almost sure that you are observing this behavior only in the map display area inside GEE. Remember that sometimes the information showed in the map display area is only an approximation of the real data (related to the use of pyramids and the zoom level of the current display). This is one of the cases where the approximation can be really misguiding. Nonetheless, if you export your data, you can see that both methods are working as expected. Here is a quick example.

comparison

https://code.earthengine.google.com/e4e4bb18635cc758b326178037806894

var lulc = ee.ImageCollection("MODIS/061/MCD12Q1"),
    geometry = 
    /* color: #98ff00 */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.Polygon(
        [[[-99.47945744553105, 25.655253955168092],
          [-99.47945744553105, 25.623683184547172],
          [-99.44306523361699, 25.623683184547172],
          [-99.44306523361699, 25.655253955168092]]], null, false);

var im = lulc.first();

Map.addLayer(im, {bands:'LC_Type1',min: 1, max:17}, 'im');

var imClean = im.reduceNeighborhood({
  reducer: ee.Reducer.mode(), 
  kernel:ee.Kernel.circle(1)
  });
var imClean2 = im.focalMode({
  radius:3,
  kernelType: 'circle',
  units: 'pixels'
});

Map.addLayer(imClean, {bands:'LC_Type1_mode',min: 1, max:17}, 'imClean');
Map.addLayer(imClean2, {bands:'LC_Type1',min: 1, max:17}, 'imClean2');

Export.image.toDrive({
  image: im,
  description: 'imorig',
  folder: 'stackOverflow',
  region:geometry,
  scale:500,
  crs: 'EPSG:4326'
});
Export.image.toDrive({
  image: imClean,
  description: 'imClean',
  folder: 'stackOverflow',
  region:geometry,
  scale:500,
  crs: 'EPSG:4326'
});
Export.image.toDrive({
  image: imClean2,
  description: 'imClean2',
  folder: 'stackOverflow',
  region:geometry,
  scale:500,
  crs: 'EPSG:4326'
});
1
  • 1
    You can also force the projection on the output before displaying and not have to Export the results. Nov 2, 2023 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.