import matplotlib.pyplot as plt
import numpy as np
from matplotlib.image import _resample
from matplotlib.transforms import Affine2D
np.random.seed(19680801)
grid = np.random.rand(4, 4)
scale_factor = 10
out_dimensions = (grid.shape[0]*scale_factor, grid.shape[1]*scale_factor)
fig, axs = plt.subplots(nrows=3)
transform = Affine2D().scale(scale_factor, scale_factor)
# Have to get an image to be able to resample
# Resample takes an _ImageBase or subclass, which require an Axes
img = axs[0].imshow(grid, interpolation='spline36', cmap='viridis')
interpolated = _resample(img, grid, out_dimensions, transform=transform)
axs[0].imshow(grid, cmap='viridis')
axs[1].imshow(grid, interpolation='spline36', cmap='viridis')
axs[2].imshow(interpolated, cmap='viridis')
2条答案
按热度按时间20jt8wwn1#
matplotlib C++ resampling code与matplotlib.image.resample函数接口,您可以自己导入和调用该函数。
rkue9o1l2#
作为Yannick Copin的回答的补充,其中写道
matplotlibC ++重采样代码与matplotlib.image.resample函数接口,您可以自己导入和调用该函数。
下面是使用私有函数
matplotlib.image._resample
进行插值的可视化演示