Using Serval to Fix Rasters

Andrew Middleton
3 min readApr 18, 2022

I’m making some more dive maps and this time I’m looking at the Channel Islands. In my bathymetry rasters I’m running into this weird series of holes in the seabed that are just too uniform to be anything other than anomalies in the data collection and processing. Sometimes there are arrays of what look like stubble- little Lego bumps of different values that show up in neat little rows. This could be because this region that I’m interested in is huge and the data set I’m using from NOAA is a mashup of a bunch of different surveying expeditions.

See what I mean? Those bumps don’t look natural. They look like they’re from errors arising from resizing the image pixels.

Those bumps can be over 100 meters tall! In the context of the ocean it’s not that big a deal but my shallow water map (that ONLY goes to like -1000 meters) means that comparatively small changes in elevation show up in my color ramps. My poor GPU also has to crank out all the extra contour lines that I end up deleting. If I ran a generalization algorithm to just smooth the whole DEM, I’d lose valuable detail in the regions that I want to remain accurate and high resolution.

I ran GDAL’s Slope analysis on the first DEM and set it to be semitransparent before setting it on top. This technique is great for making steep drop-offs like the Mugubu Canyon really pop but it also highlights these unsightly anomalies because they’re very steep even if they have small ranges in actual elevation values.

I’d much prefer to airbrush these individual regions out. Now, my old strategy is a bit clunky. As you may recall, I once exported rasters with .WLD files and then manually airbrushed anomalies out before opening them in QGIS again and saving the file as a GEOTIFF. It was a whole hassle and when I saw how lumpy this new raster was, I knew I needed a new solution.

I had used Lutra Consulting’s free Serval plugin for QGIS in the past but at the time it was a way to assign new values to individual pixels and certainly not for selectively smoothing out or updating large areas.

The latest update offers substantially improved capability on the right end of the plugin toolbar. Now instead of editing pixels I can edit whole areas at once!

I even experimented with selecting a region and multiplying the elevation values by .9 as a way to proportionally make the hole shallower which was a very cool feature even if it didn’t solve my problem like I had hoped.

After playing around a bit, here’s what my process looks like for a single big hole that needs to get patched. I clipped the range of colors substantially to maximize contrast for clarity.

Step 0. The hole.
Step 1. I created a virtual polygon vector around the deepest part of the hole to select the region and then I used the paint bucket tool to assign them all a value that I chose from the surroundings with the color picker.
Step 2. I made a larger virtual polygon selection area and then ran a 3x3 smoothing tool over the whole area.

There’s a little bit of a coffee cup ring effect left but I think I’m going to leave it. The deepest parts have been eliminated and when I run my slope analysis, I won’t get those big ugly spots. When I run a contour line plot, I won’t get tons of spurious little lines which is going to save me a little bit of processing power. This was a very quick process that won’t require me scrapping my whole raster. Hats off to the Lutra Consulting development team!

--

--