I'm trying to modify a function to create fisheye effect on image (i use a software that permit to modify every single pixel of an image).

At the moment i use this function:

float kk=width*0.5;
float ll=height*0.5;
float dx=(x-kk);
float dy=(y-ll);

float aa=atan2(dy,dx);
float rr=hypot(dy,dx);
float rs=rr*rr/hypot(kk,ll);
int px=kk+rs*cos(aa);
int py=ll+rs*sin(aa);


  • width: image width;
  • height: image height;
  • x and y: original pixel position and px and py are pixel from where i take result.

Using this fonction i substitute pixel at {x,y} with pixel at {px,py}. This work,and create a fisheye effect correctly, but i need to add a variable/parameter to control final effect.

Someone could help me to find how to add this parameter on that function ?


You could multiply rs by a parameter. This corresponds to changing the scale of how close to the center your original pixel is.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.