Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resources for image distortion algorithms

Where can I find algorithms for image distortions? There are so much info of Blur and other classic algorithms but so little of more complex ones. In particular, I am interested in swirl effect image distortion algorithm.

like image 853
Jonas Avatar asked Oct 22 '08 12:10

Jonas


3 Answers

I can't find any references, but I can give a basic idea of how distortion effects work.

The key to the distortion is a function which takes two coordinates (x,y) in the distorted image, and transforms them to coordinates (u,v) in the original image. This specifies the inverse function of the distortion, since it takes the distorted image back to the original image

To generate the distorted image, one loops over x and y, calculates the point (u,v) from (x,y) using the inverse distortion function, and sets the colour components at (x,y) to be the same as those at (u,v) in the original image. One ususally uses interpolation (e.g. http://en.wikipedia.org/wiki/Bilinear_interpolation ) to determine the colour at (u,v), since (u,v) usually does not lie exactly on the centre of a pixel, but rather at some fractional point between pixels.

A swirl is essentially a rotation, where the angle of rotation is dependent on the distance from the centre of the image. An example would be:

a = amount of rotation
b = size of effect

angle = a*exp(-(x*x+y*y)/(b*b))
u = cos(angle)*x + sin(angle)*y
v = -sin(angle)*x + cos(angle)*y

Here, I assume for simplicity that the centre of the swirl is at (0,0). The swirl can be put anywhere by subtracting the swirl position coordinates from x and y before the distortion function, and adding them to u and v after it.

There are various swirl effects around: some (like the above) swirl only a localised area, and have the amount of swirl decreasing towards the edge of the image. Others increase the swirling towards the edge of the image. This sort of thing can be done by playing about with the angle= line, e.g.

angle = a*(x*x+y*y)
like image 173
Chris Johnson Avatar answered Nov 12 '22 23:11

Chris Johnson


There is a Java implementation of lot of image filters/effects at Jerry's Java Image Filters. Maybe you can take inspiration from there.

like image 20
PhiLho Avatar answered Nov 12 '22 21:11

PhiLho


The swirl and others like it are a matrix transformation on the pixel locations. You make a new image and get the color from a position on the image that you get from multiplying the current position by a matrix.

The matrix is dependent on the current position.

here is a good CodeProject showing how to do it

http://www.codeproject.com/KB/GDI-plus/displacementfilters.aspx

like image 5
Lou Franco Avatar answered Nov 12 '22 22:11

Lou Franco