Interpolating Raster Data
Almost all operations on rasters involve interpolation. Interpolation is the process of computing the value of a raster at a particular point location and at a particular scale.
In some scenarios, you need to up-sample – where you interpolate values at a higher resolution than the source raster data. In other scenarios, you need to down-sample – where you acquire values at a lower resolution than the raster source data. Often, you just need to shift-sample – where you acquire a value at the same or similar scale to the raster source data, but at locations that are shifted away from the cell centres.
The most familiar process is up-sampling. There are three commonly used methods.
The “Nearest neighbour” method does not interpolate. This method finds what cell boundary the point location is in and assigns the cell value to that location. Consequently, there will be instantaneous changes in raster value at the cell edges. When rendering, color assignment is constant across the cell and changes instantaneously at the cell edge. If this method is used for hill shading, then the edges of the cells will be visible and a rectilinear grid pattern across the image. Within each cell, there will be no shading (as there is no slope).
The “Bi-Linear” method performs a linear interpolation between four cell centres that surround the point location. This is not a smooth interpolation and abrupt changes in slope will be observed along the row and column lines that join the cell centres, and along the diagonals joining cell centres. This method does not under or overshoot the source raster values.
The “Bi-Cubic” method performs a cubic interpolation between four cell centres that surround the point location and draws from 16 cells about the location in total. This is a smooth interpolation that may result in values that either under or overshoot the source raster values.
In MapInfo Pro, these methods are selectable from the “Raster” ribbon via the “Raster Quality” control. To select the up-sampling method for a raster, firstly select raster in the Explorer window, then choose the Raster Quality. On this control, you will see the following options – None, Nearest Neighbour, Bilinear, Cubic Spline (Local), Cubic Spline (Global). This differs from the list of methods I have given above and requires some explanation.
If you choose “None” then the raster engine will not do any interpolation. MapInfo Pro will render the raster from data acquired from the base resolution level. It will not generate or use underviews. The image will then need to be interpolated as you zoom in and this is controlled from the Map Options dialog. You need a very good reason to use this mode. Unfortunately, it is the default!
If you choose any of the other methods, then the raster engine will generate underviews by employing an up-sampling method and then render from the underview data. It will apply this interpolation method to both color and to hill shading. Nearest neighbour and Bilinear correspond to the methods described above. However, there are two cubic interpolators – local and global. The local method uses the method described above – interpolating values from 16 cells surrounding the point location. The global method interpolates cubic splines for the entire tile in one hit. There is little performance difference between these two approaches to bi-cubic interpolation, but there are differences in quality. The global interpolator is smoother, and you will see this visually and if you compute derivatives of the raster slope. However, the global interpolator is more prone to “ringing” in the splines. You will see ringing where there is an abrupt change to constant slope. For example, if you have a terrain raster that has zero values for the ocean. At the change in slope at the edge of the ocean, you can generate ringing splines that will look like ripples spreading out into the ocean.
When down-sampling there are more options.
“Averaging” is used in the MapInfo Pro raster engine. In this engine, overview levels are always half the resolution of the previous level, and the cells of an overview level always align perfectly with the cells of the previous level. So, we can assign the average value of four cells in the previous level to the cell in the level above it. If cells do not align, then you can use area-weighted averaging. QGIS/GDAL offer this option.
“Mode” is used in the MapInfo Pro raster engine for “by reference” fields and for bands that contain non-combinable data (like bit-wise error codes for example). In this case, you need to choose a value to assign to the interpolated cell from the values of the underlying cell. The value that appears most often is chosen.
“Convolution filtering” is a more sophisticated way of acquiring an average value. If your cells do not align perfectly then it is necessary to use this method. You can choose kernels that enhance edges, for example.
“Statistical” methods would be applied in rare and specific situations. For example, you can compute the root mean square.
Finally, you can use any of the up-sampling methods (nearest neighbour, bilinear, bicubic). I do not recommend it.
Interpolation is most visibly employed when you generate underview resolution levels. These are down-sampled from the base resolution level on demand. The data may then be used in rendering or processing.
It is also employed when you generate overview resolution levels. These are up-sampled from the base resolution level upwards, usually recursively. Overviews are generated whenever you write an MRR, whenever you open a new legacy raster and generate a PPRC cache, or whenever you generate an OVR file within QGIS/GDAL.
Rendering may employ two interpolation operations. Firstly, the system will choose an appropriate resolution level from which to source the raster data. These will have been generated by either up-sampling or down-sampling. This level is chosen so that a pixel on the screen is the same size or larger than a cell in the raster. It will then be necessary to interpolate from the raster cell centres to the pixel centres. This is called “shifting” and will either use nearest neighbour or bilinear.
Virtual rasters work in the same way as the rendering engine. To provide virtual raster data the engine will acquire source raster tiles at an appropriate resolution level and then shift them, if necessary, to align with the virtual raster cells.
Raster processing will generally operate on the base level resolution data without interpolation. However, some processing routines allow you to target other resolution levels that have been generated by interpolation.
Point inspection can be a more complex process than it at first appears. For example, you may want to report the value of the raster at the cursor location on screen. You might choose to report the base level data with no interpolation (nearest neighbour). However, if you are zoomed out this may be inefficient. In that case, you might choose to target an appropriate resolution level that has been generated by interpolation. You may have to shift interpolate to acquire the value at the cursor location. You might also want to report the same values that have been used to render the raster that the user is interrogating, which aligns with what they are seeing. In this case, you need to match the rendering engine interpolation settings.
The field type and band type of the raster will impact the allowable interpolation methods. If you have a by-reference field (classified or image palette) then interpolation is not possible. The MapInfo Pro raster engine will always use nearest neighbour for this data. On the other hand, continuous and image fields can be interpolated using all available techniques.
Bands that use a decimal (floating point) data type can use all the interpolation methods, but bands that use integer data types cause problems. Color data types need to be treated differently. To interpolate an RGB value, you first need to split it into components, interpolate those, and then recombine the components.
Some bands contain data that cannot be interpolated. For example, Landsat scenes are supplied with a band that contains information about each pixel in the scene expressed in a bitmask. Such data cannot be interpolated.
When a raster engine generates underviews it may be forced to use a decimal (floating point) data type, even if the band data type is integer. Otherwise, the data will be quantised to integer values.
When a raster engine generates overviews should it use the same data type as the base level? If you average four integer cell values, the result may be decimal. If you force the result into an integer you lose some accuracy. You also have to make a decision about rounding off. For the record, MRR uses the same data type in the overview pyramid as in the base level.
Cubic interpolation causes underflow and overflow. In other words, it may produce values that are higher than the highest source value or lower than the lowest source value. This may be undesirable.
Cubic interpolation of integer data, and especially of color data, needs to be clipped to ensure that overflow does not roll the integer. When this occurs white might flip to black. This is an issue in QGIS.
Splines can ring in the presence of an abrupt change in slope, especially visible when it is adjacent to a region with constant slope. The splines become ripples that pass through the control points but over and undershoot in-between.
On the edge of a raster (regardless of where it is), the interpolation methods can produce edge effects. A good raster engine will interpolate values off the edge of the raster to try to eliminate edge effects, whilst terminating any interpolation outside of the valid cell boundary.
Different combinations of interpolation can cause odd effects. For example, if you use nearest neighbour interpolation for hill shading, you will create a rectilinear pattern effect. The only changes in slope are on the cell edges and these are highlighted by the hill shading. It can be useful if you want to see where the cell boundaries are. You can also see some odd effects if you use nearest neighbour for shift interpolation. Bilinear is the best choice for this.
If you have an image raster, then the interpolation methods available will depend on whether it is an Image or Image Palette field. Zoom in and you will find out soon enough – image palette fields do not support interpolation. If you want smooth color interpolation, you can force the raster engine to load the raster as an Image field instead. It can then be interpolated.