为什么离散数据的双三次插值看起来很难看?

时间:2022-09-30 00:20:54

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?

我有一个128x128的高程数据数组(从-4 -4到8000m的高度显示为9个颜色),我需要调整它的大小为512x512。我用双三次插值,但是结果看起来很奇怪。在图中你可以看到原始的,最近的和双三次的。注意:只有高程数据被插值而不是颜色本身(色域被保留)。这些工件是在我糟糕的插值代码的双三次图像结果上看到的,还是由离散(9步)数据的插值引起的?

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

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

2 个解决方案

#1


2  

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

您所使用的双三次代码一定有问题。下面是我对Python的结果:

为什么离散数据的双三次插值看起来很难看?

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.

编辑:显然Python的双ubic也不是最好的。下面是我在Paint Shop Pro中的手工操作,使用了与上面大致相同的步骤。

为什么离散数据的双三次插值看起来很难看?

#2


0  

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.

当双三次插值时,有时可以在原始的范围之外生成插值(你能验证这是否发生在你身上吗?)看起来您可能有bug,但是如果不查看代码就很难说了。一般来说,双三次溶液应该比最近邻溶液更光滑。

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.

编辑:我收回这句话,我在你的图像中看不到超出原始范围的插值。尽管如此,我认为奇怪的部分是你在使用双三次曲面时得到的“锯齿”,你可能想要仔细检查一下。

#1


2  

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

您所使用的双三次代码一定有问题。下面是我对Python的结果:

为什么离散数据的双三次插值看起来很难看?

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.

编辑:显然Python的双ubic也不是最好的。下面是我在Paint Shop Pro中的手工操作,使用了与上面大致相同的步骤。

为什么离散数据的双三次插值看起来很难看?

#2


0  

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.

当双三次插值时,有时可以在原始的范围之外生成插值(你能验证这是否发生在你身上吗?)看起来您可能有bug,但是如果不查看代码就很难说了。一般来说,双三次溶液应该比最近邻溶液更光滑。

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.

编辑:我收回这句话,我在你的图像中看不到超出原始范围的插值。尽管如此,我认为奇怪的部分是你在使用双三次曲面时得到的“锯齿”,你可能想要仔细检查一下。