0

我想用双线性插值调整图像大小。我找到了新的强度值,但我不知道我该如何使用它..代码如下这是我写的..在python中用双线性插值调整图像大小

def resizeImageBI(im,width,height): 
    temp = np.zeros((height,width),dtype=np.uint8) 
    ratio_1 = float(im.size[0] - 1)/ float(width - 1) 
    ratio_0 = float(im.size[1] - 1)/float(height - 1) 
    xx,yy = np.mgrid[:height, :width] 
    xmap = np.around(xx * ratio_0) 
    ymap = np.around(yy * ratio_1) 

for i in xrange(0, height): 
    for j in xrange(0,width): 
     temp[i][j]=im.getpixel((ymap[i][j], xmap[i][j])) * getNewIntensity(i,j,ratio_1,ratio_0) 

return Image.fromarray(temp) 

首先得到可变图像宽度比和高度比

lena.png 0.5 1 

Orginal image is here

That is output accorting to written code

回答

0

我不知道,如果你想手工做这个作为一个练习...

如果没有,有scipy.mics.imresize,可以做你想做的事

+0

我知道有一个这样的功能,但正如你所说的尝试锻炼 –