这或多或少是对从4角色插值的二维颜色渐变(256x256矩阵)的后续问题,今天jadsq深刻回答了这个问题.
对于线性渐变,前面的答案非常有效.但是,如果想要更好地控制渐变的停止颜色,这种方法似乎不太实用.在这种情况下可能有用的是在矩阵(查找表)中有一些参考色点,用于插入查找表中空位置的颜色值.我的意思可能更容易从下面的图像中读出来.
整个想法来自http://cartography.oregonstate.edu/pdf/2006_JennyHurni_SwissStyleShading.pdf第4页到第6页.我已经阅读了论文,理论上我理解发生了什么但由于我的经验不足而惨遭失败插值方法,说实话,一般数学技能.可能还有兴趣的是,他们使用S形高斯钟作为插值方法(第6页).他们认为高斯加权产生了视觉上最好的结果并且计算简单(方程1,对于每256个单元256个表,k = 0.0002).
编辑(更好的插图):
我已经将其呈现方法的其他部分放在适当位置,但填充矩阵中的空值确实是一个关键部分,并使我无法继续.再一次,谢谢你的帮助!
我现在拥有的:
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
# the matrix with the reference color elements
ref=np.full([7, 7, 3], [255,255,255], dtype=np.uint8)
ref[0][6] = (239,238,185)
ref[1][1] = (120,131,125)
ref[4][6] = (184,191,171)
ref[6][2] = (150,168,158)
ref[6][5] = (166,180,166)
# s = ref.shape
#
# from scipy.ndimage.interpolation import zoom
# zooming as in https://stackoverflow.com/a/39485650/1230358 doesn't seem to work here anymore, because we have no corner point as reference but …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个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)