user390507
user390507

Reputation: 133

Image Warp Filter - Algorithm and Rasterization

I'd like to implement a Filter that allows resampling of an image by moving a number of control points that mark edges and tangent directions. The goal is to be able to freely transform an image as seen in Photoshop when you use "Free Transform" and chose Warpmode "Custom". The image is fitted into a some kind of Spline-Patch (if that is a valid name) that can be manipulated.

I understand how simple splines (paths) work but how do you connect them to form a patch? And how can you sample such a patch to render the morphed image? For each pixel in the target I'd need to know what pixel in the source image corresponds. I don't even know where to start searching...

Any helpful info (keywords, links, papers, reference implementations) are greatly appreciated!

Upvotes: 2

Views: 3269

Answers (1)

beta vulgaris
beta vulgaris

Reputation: 433

This document will get you a good insight into warping: http://www.gson.org/thesis/warping-thesis.pdf

However, this will include filtering out high frequencies, which will make the implementation a lot more complicated but will give a better result.

An easy way to accomplish what you want to do would be to loop through every pixel in your final image, plug the coordinates into your splines and retrieve the pixel in your original image. This pixel might have coordinates 0.4/1.2 so you could bilinearly interpolate between 0/1, 1/1, 0/2 and 1/2.

As for splines: there are many resources and solutions online for the 1D case. As for 2D it gets a bit trickier to find helpful resources. A simple example for the 1D case: http://www-users.cselabs.umn.edu/classes/Spring-2009/csci2031/quad_spline.pdf

Here's a great guide for the 2D case: http://en.wikipedia.org/wiki/Bicubic_interpolation

Based upon this you could derive an own scheme for splines for the 2D case. Define a bivariate (with x and y) polynomial and set your constraints to solve for the coefficients of the polynomial. Just keep in mind that the borders of the spline patches have to be consistent (both in value and derivative) to avoid ugly jumps.

Good luck!

Upvotes: 3

Related Questions