Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

algorithm for scaling an image from a given pivot point

standard scaling using the center of an image as the pivot point and is uniform in all dimensions. I'd like to figure out a way to scale an image from an arbitrary pivot point such that points closer to the pivot point scale less than points away from that point.

like image 340
user257543 Avatar asked Oct 26 '22 07:10

user257543


1 Answers

Well, I don't know what framework/library you're using but you can think of it as:

  • translation to make your pivot point the center point
  • standard scaling
  • opposite transalation to make the center point the original pivot point

Translation and scaling are isomorphismes so you can represent them as matrix. Each transformation is a matrix and you can multiply them for find the combined transformation matrix. So:

  • T = transformation
  • S = scalling
  • T' = opposite transformation

If you apply T.x being x a point vector it gives you the new coordinates. The same for S.x.

So if you want to do that operations you have to do: T'. (S. (T.x))

I think you can associate operations so it's the same as (T'.S.T).x

If you are using a framework apply three operations (or combine operations and apply). If you are using crude math... go the matrix way :)

PS: If you are doing this by hand. I know that if you are scaling you will want to find the coordinates of the original point given a transformed point. So you can iterate over the resulting points (each of the pixels) and see what coordinates (or point in between) from the original image you have to use. In that case what you need is the inverse matrix. So instead of using S you want to use S^(-1). If you know that you want to apply T'.S.T you can find this resulting matrix and next find (T'.S.T)^(-1). Then you have your inverse matrix to find original points given the resulting points.

like image 163
helios Avatar answered Nov 11 '22 09:11

helios