Python Scipy – ndimage.interpolation.geometric_transform()函数
给定的映射函数用于为输出中的每个点查找输入中的对应坐标
Syntax: scipy.ndimage.interpolation.geometric_transform(input, mapping, order=3)
Parameters
- input : takes an array.
- mapping : accepts a tuple data structure similar to length of given output array rank.
- order : int parameter. which is a spline interpolation and the default value is 3.
Returns: Returns an n d array.
示例 1:
Python3
from scipy import ndimage
# importing numpy module for
# processing the arrays
import numpy as np
# creating an 2 dimensional array with
# 5 * 5 dimensions
a = np.arrange(25).reshape((5, 5))
print('a')
print(a)
# reducing dimensions function
def shift_func(output_coords):
return (output_coords[0] - 0.7, output_coords[1] - 0.7)
# performing geometric transform operation
ndimage.geometric_transform(a, shift_func)
Python3
from scipy import ndimage
# importing numpy module for
# processing the arrays
import numpy as np
# create 4 * 4 dim array.
b = np.arrange(16).reshape((4, 4))
# reducing dimensions function
def shift_func(output_coords):
return (output_coords[0] - 0.1, output_coords[1] - 0.2)
ndimage.geometric_transform(b, shift_func)
输出:
示例 2:
蟒蛇3
from scipy import ndimage
# importing numpy module for
# processing the arrays
import numpy as np
# create 4 * 4 dim array.
b = np.arrange(16).reshape((4, 4))
# reducing dimensions function
def shift_func(output_coords):
return (output_coords[0] - 0.1, output_coords[1] - 0.2)
ndimage.geometric_transform(b, shift_func)
输出: