二维矩阵插值

二维矩阵插值

1.1 使用库

使用scipy中的二维插值库

from scipy.interpolate import griddata

1.2 二维矩阵插值

def interpolation_2D(array, newSize):
	rows, cols = array.shape
	rowIndex = np.array([[i]*cols for i in np.linspace(0,100,rows)])
	colIndex = np.array([list(np.linspace(0,100,cols))] * rows)
	index = np.hstack([rowIndex.reshape(-1,1), colIndex.reshape(-1,1)])

	newRows, newCols = newSize
	newRowIndex = np.array([[i]*newCols for i in np.linspace(0,100,newRows)])
	newColIndex = np.array([list(np.linspace(0,100,newCols))] * newRows)
	newIndex = np.hstack([newRowIndex.reshape(-1,1), newColIndex.reshape(-1,1)])
	
	res = griddata(index, array.reshape(-1,1), newIndex).reshape(newSize)
	return res

1.3 结果展示

data = np.load('../data/test.npy')
res = interpolation_2D(data, (500,500))

fig, ax = plt.subplots(1,2,figsize=(12,6))
ax[0].imshow(data,cmap='jet',vmax=1.3)
ax[1].imshow(res,cmap='jet',vmax=1.3)

插值前后展示

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值