Question

i have a 128x128 array of elevation data (elevations from -400m to 8000m are displayed using 9 colors) and i need to resize it to 512x512. I did it with bicubic interpolation, but the result looks weird. In the picture you can see original, nearest and bicubic. Note: only the elevation data are interpolated not the colors themselves (gamut is preserved). Are those artifacts seen on the bicubic image result of my bad interpolation code or they are caused by the interpolating of discrete (9 steps) data?

http://i.stack.imgur.com/Qx2cl.png

Was it helpful?

Solution

There must be something wrong with the bicubic code you're using. Here's my result with Python:

Bicubic resize

The black border around the outside is where the result was outside of the palette due to ringing.

Here's the program that produced the above:

from PIL import Image
im = Image.open(r'c:\temp\temp.png')

# convert the image to a grayscale with 8 values from 10 to 17
levels=((0,0,255),(1,255,0),(255,255,0),(255,0,0),(255,175,175),(255,0,255),(1,255,255),(255,255,255))
img = Image.new('L', im.size)
iml = im.load()
imgl = img.load()
colormap = {}
for i, color in enumerate(levels):
    colormap[color] = 10 + i
width, height = im.size
for y in range(height):
    for x in range(width):
        imgl[x,y] = colormap[iml[x,y]]

# resize using Bicubic and restore the original palette
im4x = img.resize((4*width, 4*height), Image.BICUBIC)
palette = []
for i in range(256):
    if 10 <= i < 10+len(levels):
        palette.extend(levels[i-10])
    else:
        palette.extend((i, i, i))
im4x.putpalette(palette)
im4x.save(r'c:\temp\temp3.png')

Edit: Evidently Python's Bicubic isn't the best either. Here's what I was able to do by hand in Paint Shop Pro, using roughly the same procedure as above.

Bicubic in Paint Shop Pro

OTHER TIPS

While bicubic interpolation can sometimes generate interpolating values outside the original range (can you verify if this is happening to you?) It really seems like you may have a bug, but it is hard to say without looking at the code. As a general rule the bicubic solution should be smoother than the nearest neighbor solution.

Edit: I take that back, I see no interpolating values outside the original range in your images. Still, I think the strange part is the "jaggedness" you get when using bicubic, you may want to double check that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top