CLIP - Additional Examples
CLIP - Additional Examples
The following example uses the pixel operators “Pix” and “bPix” to perform a non-linear warping of an image. The operator “Pix(x,y)” simply points to the (x,y) pixel relative to the origin of the image and can be an assigned to. On the other hand “bPix(u,v) accepts floating-point coordinates (u,v) that can have any value. If the value relative to the image origin is within the image boundaries then a bilinear interpolated pixel value will be returned. Otherwise, an extrapolated edge value will be returned. This will prevent creating strong new edges at the extrapolated areas.
1.#include "pnm_env.h"
2.
3.#define SGN(x) (((x) > 0) - ((x) < 0))
4.
5.int main()
6.{
7. fRgbImg img = pnm(stdin);
8. fRgbImg res(img.GetWidth(),img.GetHeight());
9.
10. img.SetOrigin(img.GetWidth()/2,img.GetHeight()/2);
11. res.SetOrigin(res.GetWidth()/2,res.GetHeight()/2);
12.
13. for (int y=res.GetYmin(); y < res.GetYmax(); y++){
14. for (int x=res.GetXmin(); x < res.GetXmax(); x++){
15.
16. float tx = SGN(x)*sqrtf((float)abs(x))*sqrtf((float)img.GetWidth()/2);
17. float ty = SGN(y)*sqrtf((float)abs(y))*sqrtf((float)img.GetHeight()/2);
18.
19. res.Pix(x,y) = img.bPix(tx,ty);
20. }
21. }
22.
23. pnm((bRgbImg) res).Write(stdout);
24.
25. return 0;
26.}