Skip to main content

Module geometric

Module geometric 

Source
Expand description

Geometric transforms with B-spline interpolation, following scipy.ndimage: spline_filter, map_coordinates, affine_transform, shift, zoom and rotate.

Every geometric transform has the same core: for each output pixel, compute where it comes from in the input (generally between pixels) and interpolate there. Interpolation of order k fits a piecewise polynomial of degree k that is k − 1 times differentiable: order 0 takes the nearest pixel, order 1 is bilinear, and order 3 (the default) is the cubic B-spline. For orders above 1 the spline must pass through the pixels, which requires solving for its coefficients first: the prefilter, a pair of recursive filters per pole, run along each axis.

See the book entry Rank filters, derivative filters and geometric transforms.

Functions§

affine_transform
The affine transform (SciPy’s affine_transform): output pixel o takes the input value at matrix · o + offset, interpolated. Note the direction: the matrix maps output coordinates to input coordinates, so to rotate an image by θ the matrix is the rotation by −θ.
map_coordinates
Interpolates image at arbitrary points (row, column) (SciPy’s map_coordinates), with spline order 0 to 5. Coefficients from spline_filter are combined with B-spline weights over the (k + 1) × (k + 1) neighbourhood of each point. In Constant mode, points outside the image (beyond −0.5 … n − 0.5… precisely, outside [0, n − 1]) take the constant, as in SciPy.
rotate
Rotates the image by angle degrees about its centre (SciPy’s rotate, axes (1, 0)): a positive angle turns the content anticlockwise on the screen. With reshape the output grows to hold the whole rotated image.
shift
Shifts the image by (rows, columns) pixels: output o takes input o − shift.
spline_filter
B-spline coefficients of image for interpolation of the given order (SciPy’s spline_filter with the boundary condition that mode implies). Returns the coefficients and the padding added at each side.
zoom
Resizes the image by factors (rows, columns) (SciPy’s zoom with grid_mode=False): the output has round(n · factor) pixels along each axis, and its first and last pixels sample the input’s first and last pixels exactly.