Dear all,
I am using the python bindings to cv and I perform a thin plate spline transformation using cv2.createThinPlateSplineShapeTransformer()
My problem is how to display the whole image in the case of warping beyond the matrix dimensions. If i do so then the image is cropped. Hope the following example code will illustrate this issue and help to find an answer. Unfortunately seems that I can not attach an example file...
import cv2
import numpy as np
import matplotlib.pyplot as plt
tps = cv2.createThinPlateSplineShapeTransformer()
pnt1 = [30,0]
pnt2 = [2900,120]
pnt3 = [2600,2600]
pnt4 = [0,2600]
pnt5 = [10,190]
pnt6 = [10,240]
sshape = np.array([[0,0],[2600,0],[2600,2600],[0,2600],[10,190],[10,240]],np.float32)
tshape = np.array([pnt1, pnt2, pnt3, pnt4, pnt5, pnt6],np.float32)
sshape = sshape.reshape(1,-1,2)
tshape = tshape.reshape(1,-1,2)
matches = list()
matches.append(cv2.DMatch(0,0,0))
matches.append(cv2.DMatch(1,1,0))
matches.append(cv2.DMatch(2,2,0))
matches.append(cv2.DMatch(3,3,0))
matches.append(cv2.DMatch(4,4,0))
matches.append(cv2.DMatch(5,5,0))
tps.estimateTransformation(tshape,sshape,matches)
img = cv2.imread('test.tiff', 1)
out_img = tps.warpImage(img)
fig, ax = plt.subplots()
ax.set_xlim([-100,3000])
ax.set_ylim([-100,3000])
plt.imshow(out_img)
plt.savefig("warped")