Advertisement
Guest User

Another G'MIC code for implementing DCCI2X algorithm

a guest
Oct 27th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. scale_dcci2x_new : -check "${1=1.15}>=0 && ${2=5}>=0" -skip ${3=0}
  2. -e[^-1] "Double xy-dimensions of image$?, using DCCI2x algorithm."
  3. -v - -repeat $! -l[$>]
  4. -r {2*w-(!$3)},{2*h-(!$3)},1,100%,4
  5.  
  6. # Estimate diagonal values.
  7. -f "init(
  8. const threshold = $1;
  9. const exponent = $2;
  10. interpolation = 0;
  11. boundary = 1;
  12. drp() = -j(-3,-3) + 9*j(-1,-1) + 9*j(1,1) - j(3,3);
  13. urp() = -j(3,-3) + 9*j(1,-1) + 9*j(-1,1) - j(-3,3);
  14. );
  15. if (x%2==0 || y%2==0,i,
  16. d1 = sum(abs([
  17. j(-1,-3) - j(-3,-1), j(1,-3) - j(-1,-1), j(3,-3) - j(1,-1),
  18. j(-1,-1) - j(-3,1), j(1,-1) - j(-1,1), j(3,-1) - j(1,1),
  19. j(-1,1) - j(-3,3), j(1,1) - j(-1,3), j(3,1) - j(1,3)
  20. ]));
  21. d2 = sum(abs([
  22. j(-3,-3) - j(-1,-1), j(-1,-3) - j(1,-1), j(1,-3) - j(3,-1),
  23. j(-3,-1) - j(-1,1), j(-1,-1) - j(1,1), j(1,-1) - j(3,1),
  24. j(-3,1) - j(-1,3), j(-1,1) - j(1,3), j(1,1) - j(3,3)
  25. ]));
  26. ratio = (1 + d1)/(1 + d2);
  27. value = ratio>threshold ? drp(): # Up-right edge
  28. ratio<(1/threshold) ? urp(): # Down-right edge
  29. (w1 = 1/(1 + d1^exponent); w2 = 1/(1 + d2^exponent); (drp()*w1 + urp()*w2)/(w1 + w2)); # Smooth area
  30. value/=16)"
  31.  
  32. # Estimate remaining values.
  33. -f "init(
  34. const threshold = $1;
  35. const exponent = $2;
  36. interpolation = 0;
  37. boundary = 1;
  38. hp() = -j(-3,0) + 9*j(-1,0) + 9*j(1,0) - j(3,0);
  39. vp() = -j(0,-3) + 9*j(0,-1) + 9*j(0,1) - j(0,3);
  40. );
  41. if ((x%2) + (y%2)!=1,i,
  42. d1 = sum(abs([
  43. j(-1,-2) - j(1,-2),
  44. j(-2,-1) - j(0,-1), j(0,-1) - j(2,-1),
  45. j(-3,0) - j(-1,0), j(-1,0) - j(1,0), j(1,0) - j(3,0),
  46. j(-2,1) - j(0,1), j(0,1) - j(2,1),
  47. j(-1,2) - j(1,2)
  48. ]));
  49. d2 = sum(abs([
  50. j(-2,-1) - j(-2,1),
  51. j(-1,-2) - j(-1,0), j(-1,0) - j(-1,2),
  52. j(0,-3) - j(0,-1), j(0,-1) - j(0,1), j(0,1) - j(0,3),
  53. j(1,-2) - j(1,0), j(1,0) - j(1,2),
  54. j(2,-1) - j(2,1)
  55. ]));
  56. ratio = (1 + d1)/(1 + d2);
  57. value = ratio>threshold ? vp() : # Horizontal edge
  58. ratio<(1/threshold) ? hp() : # Vertical edge
  59. (w1 = 1/(1 + d1^exponent); w2 = 1/(1 + d2^exponent); (vp()*w1 + hp()*w2)/(w1 + w2)); # Smooth area
  60. value/=16)"
  61. -endl -done -v +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement