Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. Color3d v;
  2. Color3d mt = Color3d(0.0, 0.0, 0.0);
  3. Color3d st = Color3d(0.0, 0.0, 0.0);
  4. for(int y=0; y<target.rows; y++) {
  5. for(int x=0; x<target.cols; x++) {
  6. v = target.at<Color3d>(y, x);
  7. v = mRGB2LMS * v;
  8. for(int c=0; c<3; c++) v(c) = v(c) > eps ? log10(v(c)) : log10(eps);
  9.  
  10. target.at<Color3d>(y, x) = mLMS2lab * v;
  11. mt = mt + target.at<Color3d>(y, x);
  12. st = st + target.at<Color3d>(y, x) * target.at<Color3d>(y, x);
  13. }
  14. }
  15.  
  16. Color3d mr = Color3d(0.0, 0.0, 0.0);
  17. Color3d sr = Color3d(0.0, 0.0, 0.0);
  18. for(int y=0; y<refer.rows; y++) {
  19. for(int x=0; x<refer.cols; x++) {
  20. v = refer.at<Color3d>(y, x);
  21. v = mRGB2LMS * v;
  22. for(int c=0; c<3; c++) v(c) = v(c) > eps ? log10(v(c)) : log10(eps);
  23.  
  24. refer.at<Color3d>(y, x) = mLMS2lab * v;
  25. mr = mr + refer.at<Color3d>(y, x);
  26. sr = sr + refer.at<Color3d>(y, x) * refer.at<Color3d>(y, x);
  27. }
  28. }
  29.  
  30. for(int y=0; y<target.rows; y++) {
  31. for(int x=0; x<target.cols; x++) {
  32. for(int c=0; c<3; c++) {
  33. double val = target.at<double>(y, x*3+c);
  34. target.at<double>(y, x*3+c) = (val - mt(c)) / st(c) * sr(c) + mr(c);
  35. }
  36. }
  37. }
  38.  
  39. // Transform back from lab to RGB
  40. for(int y=0; y<target.rows; y++) {
  41. for(int x=0; x<target.cols; x++) {
  42. v = target.at<Color3d>(y, x);
  43. v = mlab2LMS * v;
  44. for(int c=0; c<3; c++) v(c) = v(c) > -5.0 ? pow(10.0, v(c)) : eps;
  45.  
  46. target.at<Color3d>(y, x) = mLMS2RGB * v;
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement