#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc,char** argv)
{
Mat img1, img2,img3,img1_1;
img1 = imread("D://images//4.jpg");
if (img1.empty())
{
cout <<"could not load images......" << endl;
return 0;
}
namedWindow("win1",CV_WINDOW_AUTOSIZE);
imshow("win1",img1);
img1.copyTo(img1_1);
//namedWindow("win1_1", CV_WINDOW_AUTOSIZE);
//imshow("win1_1", img1_1);
cvtColor(img1,img2,CV_BGR2GRAY);
namedWindow("win2", CV_WINDOW_AUTOSIZE);
imshow("win2", img2);
int height = img2.rows;
int width = img2.cols;
for (int row=0;row<height;row++)
{
for (int col=0;col<width;col++)
{
int px_value = img2.at<uchar>(row,col);
//cout << px_value<< endl;
img2.at<uchar>(row, col) = 255 - px_value;
}
}
namedWindow("win3", CV_WINDOW_AUTOSIZE);
imshow("win3", img2);
img3.create(img1_1.size(), img1_1.type());
int height_3 = img1_1.rows;
int widht_3 = img1_1.cols;
int channels_3 = img1_1.channels();
/*
for (int row = 0; row < height_3; row++)
{
for (int col=0;col<widht_3;col++)
{
if (channels_3==1)
{
int px_value = img1_1.at<uchar>(row,col);
img1_1.at<uchar>(row, col) = 255 - px_value;
}
else if (channels_3==3)
{
int b = img3.at<Vec3b>(row, col)[0];
int g = img3.at<Vec3b>(row, col)[1];
int r = img3.at<Vec3b>(row,col)[2];
img3.at<Vec3b>(row, col)[0] = 255 - b;
img3.at<Vec3b>(row, col)[1] = 255 - g;
img3.at<Vec3b>(row, col)[2] = 255 - r;
}
}
}
*/
bitwise_not(img1_1,img3);
namedWindow("win4", CV_WINDOW_AUTOSIZE);
imshow("win4", img3);
waitKey(0);
return 0;
}