用python表示几何意义上的方阵

2024-04-26 18:29:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个矩阵(ndarray),它包含了我想要在几何意义上缩放的实值,也就是在保持值尽可能相似的同时扩展矩阵的大小。可以将其视为缩放图像。你知道吗

但我的矩阵不是图像。我的实际价值在8000到50000之间。据我所知,从通常的图像角度来看,这些值不能代表任何东西。你知道吗

我在网上搜索过答案,但每个答案都建议使用PIL或类似的图像处理库,这些库使用的标准像素值不接受我的矩阵。你知道吗

那么,有没有一种方法可以在几何(或图像)意义上缩放包含任何实数的矩阵呢?你知道吗

是否有一个python库来支持这种理解或类似的列表理解?你知道吗

谢谢你。你知道吗


Tags: 方法答案图像标准pil代表矩阵像素
1条回答
网友
1楼 · 发布于 2024-04-26 18:29:22

你描述的是二维插值。Scipy在^{}中提供了一个实现

from scipy.interpolate import RectBivariateSpline

# sample data
data = np.random.rand(8, 4)
width, height = data.shape
xs = np.arange(width)
ys = np.arange(height)

# target size and interpolation locations
new_width, new_height = width*2, height*2
new_xs = np.linspace(0, width-1, new_width)
new_ys = np.linspace(0, height-1, new_height)

# create the spline object, and use it to interpolate
spline = RectBivariateSpline(xs, ys, data) #, kx=1, ky=1) for linear interpolation
spline(new_xs, new_ys)

相关问题 更多 >