小编Yas*_*sie的帖子

Python - 双线性图像插值

我正在尝试编写一个Python函数,它将图像作为输入并执行双线性图像插值来调整图像大小.我已经取得了相当的成功,因为图像确实调整了大小,但是这个过程在输出中引入了黑洞,我似乎无法弄清楚它们是如何或为什么存在的.

我见过的问题对我没什么帮助(numpy和python中图像的简单,高效的双线性插值)

代码:

def img_interp(img, scale = 1.5):

    angle_rad = pi * angle_deg / 180.0;

    rows, cols, colours = img.shape

    n_rows = int(round(rows * scale, 0))
    n_cols = int(round(cols * scale, 0))

    enlarged_img = np.ones((n_rows, n_cols, colours))

    for i in range(n_rows - 1):
        for j in range(n_cols - 1):
            x_coord = j / scale
            y_coord = i / scale

            xc = int(ceil(x_coord))
            xf = int(floor(x_coord))
            yc = int(ceil(y_coord))
            yf = int(floor(y_coord))

            W_xc = xc - x_coord
            W_xf = …
Run Code Online (Sandbox Code Playgroud)

python numpy image-processing

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

image-processing ×1

numpy ×1

python ×1