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. 1.#include "pnm_env.h"

  2. 2.

  3. 3.#define SGN(x) (((x) > 0) - ((x) < 0))

  4. 4.

  5. 5.int main()

  6. 6.{

  7. 7.    fRgbImg img = pnm(stdin);

  8. 8.    fRgbImg res(img.GetWidth(),img.GetHeight());

  9. 9.

  10. 10.    img.SetOrigin(img.GetWidth()/2,img.GetHeight()/2);

  11. 11.    res.SetOrigin(res.GetWidth()/2,res.GetHeight()/2);

  12. 12.

  13. 13.    for (int y=res.GetYmin(); y < res.GetYmax(); y++){

  14. 14.        for (int x=res.GetXmin(); x < res.GetXmax(); x++){

  15. 15.

  16. 16.            float tx = SGN(x)*sqrtf((float)abs(x))*sqrtf((float)img.GetWidth()/2);

  17. 17.            float ty = SGN(y)*sqrtf((float)abs(y))*sqrtf((float)img.GetHeight()/2);

  18. 18.

  19. 19.            res.Pix(x,y) = img.bPix(tx,ty);

  20. 20.        }

  21. 21.    }

  22. 22.

  23. 23.    pnm((bRgbImg) res).Write(stdout);

  24. 24.

  25. 25.    return 0;

  26. 26.}


  [PREV]                                   [NEXT]