-
-
Save horsto/4d91473e257c8dba0aa4b7a9eb65ff66 to your computer and use it in GitHub Desktop.
Scikit image piecewise affine transform problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://forum.image.sc/t/equivalent-for-matlabs-piecewiselineartransformation2d/51035 | |
## Matlab: | |
# tform = fitgeotrans(moved_points,fixed_points, 'pwl'); | |
## 'pwl' refers to "PiecewiseLinearTransformation2D" | |
############################################################ | |
import numpy as np | |
from skimage.transform import PiecewiseAffineTransform, warp | |
# Load data | |
grid_picture = np.load('grid_picture.npy') | |
original_points = np.load('original_points.npy') | |
transformed_points = np.load('transformed_points.npy') | |
# Piecewise affine transform | |
tform = PiecewiseAffineTransform() | |
status = tform.estimate(transformed_points, original_points) | |
if not status: | |
raise ValueError('PiecewiseAffineTransform ran into an error during fitting') | |
# Unwarp image | |
grid_picture_unwarped = warp(grid_picture, tform, order=2, | |
preserve_range=False, output_shape=[256,256]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment