Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <opencv2/highgui/highgui.hpp>
- using namespace std;
- using namespace cv;
- int main()
- {
- Mat src = imread("aaa.png", CV_LOAD_IMAGE_GRAYSCALE);
- src.convertTo(src, CV_32FC1);
- Mat res(src.rows + 2, src.cols + 2, CV_32FC1, Scalar(0));
- Mat srcROI(res, Rect(1, 1, src.cols, src.rows));
- src.copyTo(srcROI);
- for (int i = 1; i < res.rows - 1; ++i)
- {
- for (int j = 1; j < res.cols - 1; ++j)
- {
- int err = 0;
- if (res.ptr<float>(i)[j] < 128)
- {
- err = res.ptr<float>(i)[j];
- res.ptr<float>(i)[j] = 0;
- }
- else
- {
- err = res.ptr<float>(i)[j] - 255;
- res.ptr<float>(i)[j] = 255;
- }
- res.ptr<float>(i)[j + 1] += (err * 7 / 16.);
- res.ptr<float>(i + 1)[j - 1] += (err * 3 / 16.);
- res.ptr<float>(i + 1)[j] += (err * 5 / 16.);
- res.ptr<float>(i + 1)[j + 1] += (err / 16.);
- }
- }
- int x = 2;
- srcROI.convertTo(srcROI, CV_8UC1);
- imwrite("ED_1975.jpg", srcROI);
- }
Add Comment
Please, Sign In to add comment