19

Can any point to image warping algorithms? Specifically for bulge effect?

tshepang
  • 12,111
  • 21
  • 91
  • 136
random
  • 10,238
  • 8
  • 57
  • 101

2 Answers2

24

See if I understood what you want. Suppose your image coordinates go from 0 to 1.

If you do:

r = Sqrt[(x - .5)^2 + (y - .5)^2]
a = ArcTan[x - .5, y - .5]
rn = r^2.5/.5 

And then remap your pixels according to:

  x -> rn*Cos[a] + .5 
  y -> rn*Sin[a] + .5  

You get:

enter image description here

You may adjust the parameters to get bigger or smaller bulges.

Edit

Let's see if I understood your comment about warping. The following images are generated using

rn = r^k {k: 1 ... 2}: 

enter image description here

Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
  • 4
    You don't really need to go into trigonometry. `Cos[a] = (x - .5)/r` and `Sin[a] = (y - .5)/r` – Markus Jarderot Feb 20 '11 at 12:04
  • Check the algorithm in this link - http://davis.wpi.edu/~matt/courses/morph/2d.htm Can we have an algorithm like this for bulge effect? – random Feb 21 '11 at 09:48
  • Thanks belisarius. I now need to implement it by adding a mesh to a Sprite in Android and applying the deformation to it. We have a library called andEngine which we can utilize. I have created another thread to proceed further: http://stackoverflow.com/questions/5078240/image-transformation-using-sprite – random Feb 22 '11 at 13:32
  • @user193545 Can't help you wih that one. Good luck! – Dr. belisarius Feb 22 '11 at 13:39
  • See also my followup to this answer [here](http://stackoverflow.com/questions/5542942/looking-for-fast-image-distortion-algorithms/5555920#5555920) – BlueRaja - Danny Pflughoeft Apr 05 '11 at 17:28
  • Can you explain as briefly with any example – arunkumar.p Jul 20 '11 at 10:53
  • I am unable to get above effect by using your alogorithm. – Vivek Kumar Srivastava Sep 12 '11 at 07:15
  • @belisarius Can you help me with detecting the Objects shape witin an image ? – Ajay Sharma Jan 23 '12 at 05:05
  • @Ajay May be. Post a question and ping me again :) – Dr. belisarius Jan 23 '12 at 09:53
  • @belisarius I'm interested in garnering a deeper understanding of the math involved in the image warp you describe above; I've opened a thread over at math.stackexchange.com to that end: http://math.stackexchange.com/questions/266250/explanation-of-this-image-warping-bulge-filter-algorithm I'd really appreciate your input! Thanks very much! – CCJ Dec 28 '12 at 05:30
14

GLSL code version:

uniform sampler2D tex;

void main()
{
 vec2 cen = vec2(0.5,0.5) - gl_TexCoord[0].xy;
 vec2 mcen = - // delete minus for implosion effect
      0.07*log(length(cen))*normalize(cen);
 gl_FragColor = texture2D(tex, gl_TexCoord[0].xy+mcen);
}

original:

enter image description here

explosion:

enter image description here

implosion:

enter image description here

cheers!

Agnius Vasiliauskas
  • 10,935
  • 5
  • 50
  • 70