views:

2208

answers:

5

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.

+3  A: 

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)
Chris Johnson
A: 

Take a look at ImageMagick. It's a image conversion and editing toolkit and has interfaces for all popular languages.

The -displace operator can create swirls with the correct displacement map.

If you are for some reason not satisfied with the ImageMagick interface, you can always take a look at the source code of the filters and go from there.

lajos
+2  A: 

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

Lou Franco
+1  A: 

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

PhiLho
+1  A: 

there has a new graphic library have many feature

http://code.google.com/p/picasso-graphic/

eric