• entries
    18
  • comments
    56
  • views
    36478

Liquify and Image warping

Sign in to follow this  

1014 views

[size=2]As a first go at a journal entry, just a simple topic:
For a feature for my little 3d painting app, I wanted to be able to warp source images to make them fit better onto 3d models. Never having done image warping before I quickly came to what I presume is the basis for how most people do it...

For a given source image, I created a corresponding sized 2d array of 2D vector floats, I'll call a 'vector map':

grid_zpsjkuagamp.png

Each vector represents a displacement (in pixel space) to find the source pixel for each destination pixel in the resulting image.

So the process to create the final image is as follows:


  1. [font=arial]Loop through all the destination pixels[/font]


  2. [font=arial]For each xy, look up the corresponding vector in the vector map.[/font]


  3. [font=arial]Add the vector to xy, to get a float source xy.[/font]


  4. [font=arial]Look up the source pixel from the source image (using texture filtering if desired)[/font]


  5. [font=arial]Copy the source pixel to the xy destination.[/font]



Here is an example, using a simple circle brush, with vector direction and magnitude depending on distance from the centre:


liquify_zpsyan9p0ss.png

And here is a more subtle brush just pushing in the direction of mouse drag:
liquify2_zpsrb5unkrb.jpg

It also occurs to me that it is fairly easy to extend this vector map to use systems such as a guidance mesh, or anchor and pull points. These could perhaps be done faster by other more direct methods, but as this is not CPU critical in my case it would fit the bill, and is very flexible.

Sign in to follow this  


1 Comment


Recommended Comments

Nice! Just FYI, in mathematics a function that maps each coordinate point to a vector is called a vector field :)

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now