Skip to main content
Solved

Fill raster NULL by average value of surrounding pixels?

  • January 31, 2023
  • 1 reply
  • 216 views

aron
Supporter
Forum|alt.badge.img+16
  • Supporter

I have a raster DTM with some erroneous transparent areas. I would like to fill these using average vales of the surrounding pixels, to keep everything nice and smooth. GRASS has the 'fill nulls' function that does this, does FME have anything similar?

Best answer by daveatsafe

Hi @aron​,

For small holes (less than 10 pixels wide), you can use the RasterConvolver on a copy of the raster to smooth the pixel values and fill in the null areas. Next, use the RasterMosaicker to fill the holes in the original raster from the smoothed one, by laying the original raster on top of the smoothed one.

Screen Shot 2023-01-31 at 2.58.55 PMThe smoothing will require custom matrix in the RasterConvolver:

Screen Shot 2023-01-31 at 2.47.54 PMPick a size to cover the largest expected hole (11x11 max), then set just the outside edge values to 1 and all the inner values to 0. This will ensure the valid outer values replace the null values in the center.

The Sorter ensures that the original image is added to the mosaic last, so only the null values will be carried over from the smoothed raster.

If you expect to see holes larger than 9 pixels, there is more complex method that can be used to fill them.

View original
Did this help you find an answer to your question?

1 reply

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • Best Answer
  • January 31, 2023

Hi @aron​,

For small holes (less than 10 pixels wide), you can use the RasterConvolver on a copy of the raster to smooth the pixel values and fill in the null areas. Next, use the RasterMosaicker to fill the holes in the original raster from the smoothed one, by laying the original raster on top of the smoothed one.

Screen Shot 2023-01-31 at 2.58.55 PMThe smoothing will require custom matrix in the RasterConvolver:

Screen Shot 2023-01-31 at 2.47.54 PMPick a size to cover the largest expected hole (11x11 max), then set just the outside edge values to 1 and all the inner values to 0. This will ensure the valid outer values replace the null values in the center.

The Sorter ensures that the original image is added to the mosaic last, so only the null values will be carried over from the smoothed raster.

If you expect to see holes larger than 9 pixels, there is more complex method that can be used to fill them.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings