Guest User

Untitled

a guest
Oct 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <opencv2/highgui/highgui.hpp>
  3. using namespace std;
  4. using namespace cv;
  5.  
  6. int main()
  7. {
  8. Mat src = imread("aaa.png", CV_LOAD_IMAGE_GRAYSCALE);
  9. src.convertTo(src, CV_32FC1);
  10. Mat res(src.rows + 4, src.cols + 4, CV_32FC1, Scalar(0));
  11. Mat srcROI(res, Rect(2, 2, src.cols, src.rows));
  12. src.copyTo(srcROI);
  13. for (int i = 2; i < res.rows - 2; ++i)
  14. {
  15. for (int j = 2; j < res.cols - 2; ++j)
  16. {
  17. float err = 0;
  18. if (res.ptr<float>(i)[j] < 128)
  19. {
  20. err = res.ptr<float>(i)[j];
  21. res.ptr<float>(i)[j] = 0;
  22. }
  23. else
  24. {
  25. err = (res.ptr<float>(i)[j] - 255);
  26. res.ptr<float>(i)[j] = 255;
  27. }
  28. res.ptr<float>(i)[j + 1] += (err * 8 / 42.);
  29. res.ptr<float>(i)[j + 2] += (err * 4 / 42.);
  30. res.ptr<float>(i + 1)[j - 2] += (err * 2 / 42.);
  31. res.ptr<float>(i + 1)[j - 1] += (err * 4 / 42.);
  32. res.ptr<float>(i + 1)[j] += (err * 8 / 42.);
  33. res.ptr<float>(i + 1)[j + 1] += (err * 4 / 42.);
  34. res.ptr<float>(i + 1)[j + 2] += (err * 2 / 42.);
  35.  
  36. res.ptr<float>(i + 2)[j - 2] += (err * 1 / 42.);
  37. res.ptr<float>(i + 2)[j - 1] += (err * 2 / 42.);
  38. res.ptr<float>(i + 2)[j] += (err * 4 / 42.);
  39. res.ptr<float>(i + 2)[j + 1] += (err * 2 / 42.);
  40. res.ptr<float>(i + 2)[j + 2] += (err * 1 / 42.);
  41. }
  42. }
  43. srcROI.convertTo(srcROI, CV_8UC1);
  44. imwrite("ED_1976.jpg", srcROI);
  45. }
Add Comment
Please, Sign In to add comment