1

I have 2 grayscale images A and B. I am performing an affine transform (rotation and translation) on B. I am then calculating the standard deviation of (A-B*), where B* is:

B* = affine_transform(B)

I want to run gradient descent to find optimal values of θ,tx and ty such that my function f(θ,tx,ty) is minimized.

f(θ,tx,ty) = σ(A-B*) 

However I'm having trouble actually writing out the affine transform mathematically. I need to do this before I can calculate the gradient for the optimization process.

I know that the transformed points would be calculated by:

[U V 1] = [X Y 1]*[cos(θ) -sin(θ) 0; sin(θ) cos(θ) 0; tx ty 1]

where X = [x1,x2.....xn]' and Y=[y1,y2.....ym]' would be the column vectors representing the pixel indices of B.

Following this I would use some interpolation method to reassign the pixel values at their newly calculated indices. However the above index transformation step is the only part of the calculation that actually uses θ,tx or ty.

I initially assumed that I would have to partially differentiate the transformation matrix by θ,tx and ty but this gives a seemingly incorrect result:

Differentiating wrt θ:

[sin(θ) -cos(θ) 0; cos(θ) -sin(θ) 0; 0 0 0]

wrt tx:

[0 0 0; 0 0 0; 1 0 1]

wrt ty:

[0 0 0; 0 0 0; 0 1 1] 

The partial differentials wrt to tx and ty map all the pixels in the image to the same 2 indices [1,0] and [0,1] which cannot be right.

Any help in figuring out how to frame the cost function here would be highly appreciated.

  • I don't think you can take the derivative of a matrix like that. I think what you need to do is compute the derivative of the complete function (the rotation matrix applied to the vector). This function is a vector function: [u,v] = f([x,y], θ, [tx,ty]). The derivative of a vector function is the Jacobian matrix. – Cris Luengo Feb 19 '18 at 06:28

0 Answers0