I am trying to write a Python function that takes an image as input and interpolates a bilinear image to resize the image. I had a reasonable success, as the image changed, but the process introduces black holes in the output, which I can not understand how and why they are there.
The questions I saw didn’t help me much ( Simple, efficient bilinear interpolation of images in numpy and python )
The code:
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 = x_coord - xf W_yc = yc - y_coord W_yf = y_coord - yf enlarged_img[i, j, :] = 255 - np.around(W_xc * (W_yc * img[yf, xf, :] + W_yf * img[yc, xf, :]) + W_xf * (W_yc * img[yf, xc, :] + W_yf * img[yc, xc, :]), 0) return enlarged_img
Image results: https://www.dropbox.com/s/ji0frbzcuyxd11u/results.png?m=
There are probably better ways to do this than what I did, but I would really appreciate it if someone could take a look and tell me what I did wrong or what else I need to do. Thanks!
python numpy image-processing
Yassie
source share