2

I want to shear an image along the y-axis, but keeping a given x value in the same height. If I use a shear matrix as:

[1, 0, 0] 
[s, 1, 0] 

with s = the shear factor with the function "warpAffine", I do get my sheared image, but it's always with origin at 0,0. I need to have my origin at another x (and maybe even y).

So I think I should combine translation matrices, to translate the image to the left, perform the shear and translate the image back to the right, but I am unsure how to combine these matrices, since:

[1, 0, dx]   [1, 0, 0]     [1, 0, -dx] 
[0, 1, dy] * [s, 1, 0]  *  [0, 1, -dy] 

obviously won't work.

How can I perform a shearing operation on a chosen origin other than 0,0?

Andriy M
  • 76,112
  • 17
  • 94
  • 154
mjepson
  • 871
  • 1
  • 9
  • 21

1 Answers1

1

you are correct that you should combine those transforms. To combine them convert all of them to 3x3 matrices by adding [0,0,1] as the 3rd row. Then you can multiply all 3 matrices. When you finish the bottom row will still be [0,0,1], you can then remove it and use the resulting 2x3 matrix as your combined transform.

Hammer
  • 10,109
  • 1
  • 36
  • 52
  • Sometimes things can be so easy, yet for some reason you just won't see it unless someone shows you ... Thanks! – mjepson Dec 31 '12 at 15:22