标签:imwrite class 直方图 namespace out char sign vector stream
#include <opencv2\highgui\highgui.hpp> #include <iostream> #include<vector> using namespace cv; using namespace std; double gray[256]; int main(){ Mat img = imread("123.jpg", 0); // namedWindow("MyWindow"); // imshow("MyWindow", img); std::vector<uchar> array(img.rows*img.cols); if (img.isContinuous()) {array.assign(img.datastart, img.dataend);} cout << array.size(); for (int i = 0; i < img.rows*img.cols; i++)++gray[(int)array[i]]; for (int i = 0; i < 256; i++) { gray[i] /= (img.rows*img.cols); gray[i] = int(255 * gray[i]+0.5); if (i > 0)gray[i] = (gray[i] + gray[i - 1]); } for (int i = 0; i < img.rows*img.cols; i++)array[i] = gray[array[i]]; Mat now((int)img.rows,(int)img.cols, 0); for (int i = 0; i < img.rows; i++) for (int j = 0; j < img.cols; j++) now.at<uchar>(i, j) = array[i*img.cols+j]; // namedWindow("MyWindow1"); // imshow("MyWindow1", now); // waitKey(0); imwrite("1123.jpg", now); system("pause"); return 0; }
标签:imwrite class 直方图 namespace out char sign vector stream
原文地址:http://www.cnblogs.com/goudanli/p/7894859.html