Hi Serge


Have a look at the attached version.



Stéfan




import skimage.transform
import matplotlib.pyplot as plt

from skimage import data
import numpy as np

src_im = data.checkerboard()
src = np.array([[(0,0),(100,0),(110,0)],[(0,110),(100,110),(110,110)]])
dst = np.array([[(0,0),(50,0),(70,0)],[(0,20),(60,50),(100,100)]])

src = src.astype(float)
dst = dst.astype(float)

#revert to 1D list
src = src.reshape((-1,2))
dst = dst.reshape((-1,2))

#Perform transform
affine = skimage.transform.AffineTransform()
affine.estimate(src, dst)

# Shape of middle image, our registration target
r, c = src_im.shape

# Note that transformations take coordinates in (x, y) format,
# not (row, column), in order to be consistent with most literature
corners = np.array([[0, 0],
                    [0, r],
                    [c, 0],
                    [c, r]])

# Warp the image corners to their new positions
warped_corners = affine(corners)

# The overall output shape will be max - min
corner_min = np.min(warped_corners, axis=0)
corner_max = np.max(warped_corners, axis=0)
output_shape = (corner_max - corner_min)

# Ensure integer shape with np.ceil and dtype conversion
output_shape = np.ceil(output_shape[::-1]).astype(int)

# This in-plane offset is the only necessary transformation for the middle image
offset = skimage.transform.SimilarityTransform(translation=-corner_min)
shifted_transform = (affine + offset).inverse

dst_arr = skimage.transform.warp(src_im, shifted_transform,
                                 output_shape=output_shape,
                                 order=1, mode='constant', cval=0,
                                 clip=False, preserve_range=False)

f, (ax0, ax1) = plt.subplots(1, 2)
ax0.imshow(src_im, cmap='gray')
ax1.imshow(dst_arr, cmap='gray')
plt.show()
_______________________________________________
scikit-image mailing list
scikit-image@python.org
https://mail.python.org/mailman/listinfo/scikit-image

Reply via email to