Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How not to crop image when using ThinPlateSplineShapeTransformer

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")
click to hide/show revision 2
retagged

updated 2018-03-09 06:02:03 -0600

berak gravatar image

How not to crop image when using ThinPlateSplineShapeTransformer

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")

How not to crop image when using ThinPlateSplineShapeTransformer

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")

Some more information after realizing that this is quite important as it is kindly been mentioned to me. With respect the user case, I have some remote sensing sea-ice images. My goal is to apply suitable vectors at specified random points (first case e.g. only at the corners) in order to investigate how the ice features moves with the time. Since I want to allow them to be very flexible with the movement I think the TPS method is the most appropriate one for that. Hope that helps a bit more..