def translationalThermalReg(im1,im2):
import cv2,numpy
#get dimensions
s1=im1.shape
s2=im2.shape
#check sizes agree as a sanity check for inputs
if s1!=s2:
raise TypeError('Array Inputs are of different sizes!')
#Select translation model in CV
warp_model = cv2.MOTION_AFFINE
#Define 2x3 Warp Matrix
warp_matrix = numpy.eye(2, 3, dtype=numpy.float32)
#Number of iterations allowed to converge on solution
num_it=10000
#Terminal Threshold
termTh = 1e-9
#Define Stopping Criteria
criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, num_it, termTh)
#Ensure images are of datatype float32 (for compatibility with transformation convergence)
im1=im1.astype(numpy.float32)
im2=im2.astype(numpy.float32)
#Find Ideal Transform given input parameters
(cc, warp_matrix) = cv2.findTransformECC(im1,im2,warp_matrix, warp_model, criteria)
#Apply Transform
aligned = cv2.warpAffine(im2, warp_matrix, (s1[1], s1[0]), flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP);
print('Calculated Affine Warp Matrix:')
print(warp_matrix)
return aligned, warp_matrix
#Test Harness for debugging and testing of functions
评论列表
文章目录