15

Short:
I want to change the resolution of a raster and smooth the gray ramp like shown in the images bellow. The preference is to use GDAL, PIL or Numpy.

Description:
I'm kriging points into rasters with an output resolution of 20 meters with the High Performance Geostatistical Library. I don't want to change the output resolution because the interpolation time increase exponentially.
With this resolution the output image is ugly (pixelated and aliased). I don't know if it is conceptually correct but I want the image to be smoother like in the example bellow. It's something like 'reinterpolating' the image into a better resolution one. I'm using python so my preferences are GDAL, Python Imaging Library or Numpy. The answer could be theoretical, like pointing out the algorithm name or the concept of this kind of operation.

Source:
enter image description here

Destination:
enter image description here

EDIT Results with gdalwarp cubic spline:
enter image description here

5
  • 1
    I'm not getting results as good the 'after' image you posted with gdalwarp. Can you post the exact command that you used? Feb 3, 2015 at 0:40
  • Do you mind sharing your before and after gdawarp cubic spline code. Looks like I am not getting as clean as yours.
    – Naveen
    May 20, 2020 at 19:10
  • @pablo can you share the command you used? Sep 5, 2020 at 15:48
  • Sorry, I can't find the command that I used, I worked on this project a long time ago.
    – Pablo
    Sep 8, 2020 at 18:36
  • frankly that doesnt look at all like cubicspline or any other sampling that would do interpolation of neighboring pixels. if it were you would get a mixture of colors at the boundaries between different colors. to me this looks like the image was upscaled and then a median filter was applied, because this would preserve clear boundaries between the colors. Aug 25, 2021 at 3:19

4 Answers 4

8

1) The hard way: With a bit of coding it's (relatively) easy to implement bilinear interpolation to accomplish decent resampling.

2) The easy way: use GDAL as explained in this previous GISSE post, but in reverse (decreasing the pixel size).

1
  • 3
    It worked. The best results were with cubic spline. I've posted the results above. Thanks.
    – Pablo
    Aug 1, 2012 at 12:04
5

Use GDALReprojectImage, which is exposed in Python:

from osgeo import gdal
help(gdal.ReprojectImage)

For the smooth interpolation, use bilinear or cubic methods. This function is awkward, since it doesn't take keyword arguments, thus you need to find the position:

gdal.ReprojectImage(src_ds, dst_ds, None, None, gdal.GRA_Bilinear)

Probably the tricky part is setting up dst_ds, which needs to have a geotransform similar to src_ds, but with modified cell sizes.

2
  • +1. I'm not sure what its "cubic" method is. If it's a cubic spline, it would likely be smoother than bilinear; but if it is cubic convolution, it will be less smooth than bilinear. A cubic spline would be about ideal.
    – whuber
    Jul 31, 2012 at 21:08
  • 1
    @whuber true, there are two "cubic" algorithms options: GRA_CubicSpline (try this first) vs. GRA_Cubic (convolution).
    – Mike T
    Jul 31, 2012 at 21:38
0

To smooth out the variations, you need a low-pass filter. You could write your own using GDAL, or there's one using GRASS. I haven't tried it, but here's a guide http://wiki.awf.forst.uni-goettingen.de/wiki/index.php/Exercise_31

You may want to up-sample your raster first before applying the low-pass filter to get better resolution output.

1
  • 1
    I don't think the OP wants to smooth out the variations: otherwise, why go to the effort of kriging in the first place? All its benefits would be lost. Instead, as the images suggest, the question asks for a smooth resampling procedure to create a higher-resolution version of the results already obtained (which is a smart and efficient way to speed up kriging).
    – whuber
    Jul 31, 2012 at 16:39
-1

you can use a rank/median filter with radius=5, i.e kernel size size=11, (for each rgb channels).

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.