MarekKowalski/DeepAlignmentNetwork

some questions about TransformParamsLayer.py

Liz66666 opened this issue · 2 comments

Hi Marek, I see your code, and I kown TransformParamsLayer.py is used to get transform parameters from S1 to S0, but I can't understand why you subtract mean value here, and what's the meaning of a and b?

def bestFit(self, transformed_shape):
destination = self.mean_shape
source = transformed_shape.reshape((-1, 2))

  destMean = T.mean(destination, axis=0)
  srcMean = T.mean(source, axis=0)

  srcVec = (source - srcMean).flatten()
  destVec = (destination - destMean).flatten()
  a = T.dot(srcVec, destVec) / T.nlinalg.norm(srcVec, 2)**2
  b = 0
  for i in range(self.mean_shape.shape[0]):
      b += srcVec[2*i] * destVec[2*i+1] - srcVec[2*i+1] * destVec[2*i] 
  b = b / T.nlinalg.norm(srcVec, 2)**2  
  
  A = T.zeros((2, 2))
  A = T.set_subtensor(A[0, 0], a)
  A = T.set_subtensor(A[0, 1], b)
  A = T.set_subtensor(A[1, 0], -b)
  A = T.set_subtensor(A[1, 1], a)
  srcMean = T.dot(srcMean, A)  
  
  return T.concatenate((A.flatten(), destMean - srcMean))

Hi,

This whole piece of code implements a method described in Appendix D of an old paper available here:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.141.3089&rep=rep1&type=pdf

Hope that clears things up.

Marek

Thanks for your replay, it really helps me 👍