1 | initial version |
#include<opencv2/highgui/highgui.hpp>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <cmath>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat M = imread("scenetext03.jpg",CV_LOAD_IMAGE_COLOR);
double MAX_blue = 0.0;
double MAX_green = 0.0;
double MAX_red = 0.0;
cout << "M.rows " << M.rows << "\n"; cout << "M.cols " << M.cols << "\n";
for (unsigned int i = 0; i < M.rows; i++)
{
for (int unsigned j = 0; j < M.cols; j++)
{
Vec3b data = M.at<Vec3b>(i, j);
if (abs(data.val[0]) > MAX_blue) MAX_blue = pow(abs(data.val[0]), 2);
if (abs(data.val[1]) > MAX_green) MAX_green = pow(abs(data.val[1]), 2);
if (abs(data.val[2]) > MAX_red) MAX_red = pow(abs(data.val[2]), 2);
}
}
for (int i = 0; i < M.rows; i++)
{
for (int j = 0; j < M.cols; j++)
{
M.at<Vec3b>(i,j)[0] = pow(abs(M.at<Vec3b>(i,j)[0]), 2) / MAX_blue * 255;
M.at<Vec3b>(i,j)[1] = pow(abs(M.at<Vec3b>(i,j)[1]), 2) / MAX_blue * 255;
M.at<Vec3b>(i,j)[2] = pow(abs(M.at<Vec3b>(i,j)[2]), 2) / MAX_green * 255;
}
}
namedWindow("Intensity", WINDOW_AUTOSIZE);
imshow("Intensity", M);
waitKey();
destroyAllWindows(); //destroy all open windows
return 0;
}