Guest User

Untitled

a guest
Oct 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 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 + 2, src.cols + 2, CV_32FC1, Scalar(0));
  11. Mat srcROI(res, Rect(1, 1, src.cols, src.rows));
  12. src.copyTo(srcROI);
  13. for (int i = 1; i < res.rows - 1; ++i)
  14. {
  15. for (int j = 1; j < res.cols - 1; ++j)
  16. {
  17. int 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 * 7 / 16.);
  29. res.ptr<float>(i + 1)[j - 1] += (err * 3 / 16.);
  30. res.ptr<float>(i + 1)[j] += (err * 5 / 16.);
  31. res.ptr<float>(i + 1)[j + 1] += (err / 16.);
  32.  
  33. }
  34. }
  35. int x = 2;
  36. srcROI.convertTo(srcROI, CV_8UC1);
  37. imwrite("ED_1975.jpg", srcROI);
  38. }
Add Comment
Please, Sign In to add comment