Created
September 13, 2015 11:00
-
-
Save saifthe1/6868be7744e2aeeb852b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "opencv2/highgui/highgui.hpp" | |
#include <iostream> | |
using namespace cv; | |
using namespace std; | |
int truncate(int value) | |
{ | |
if(value<0) | |
value = 0; | |
else if(value > 255) | |
value = 255; | |
return value; | |
} | |
int main( int argc, const char** argv ) | |
{ | |
Mat img = imread("Image.png", CV_LOAD_IMAGE_COLOR); | |
if (img.empty()) | |
{ | |
cout << "Image cannot be loaded..!!" << endl; | |
return -1; | |
} | |
CV_Assert(img.depth() == CV_8U); | |
unsigned char *input = (unsigned char*) (img.data); | |
/// new matrix | |
Mat outputImg(img.rows,img.cols,CV_8U); | |
unsigned char *output = (unsigned char*) (outputImg.data); | |
for(int i = 0; i < img.rows; ++i){ | |
for(int j = 0; j < img.cols;++j){ | |
int b = input[i*img.step+j*3]; | |
int g = input[i*img.step+j*3+1]; | |
int r = input[i*img.step+j*3+2]; | |
output[i*outputImg.step+j] = static_cast<unsigned char>(truncate(b+70)); | |
output[i*outputImg.step+j+1] = static_cast<unsigned char>(truncate(g+70)); | |
output[i*outputImg.step+j+2] = static_cast<unsigned char>(truncate(r+70)); | |
} | |
} | |
// cout << "Size of Matrix " << img.size() << " and " << newImg.size() << endl; | |
// cout << "Rows of Matrix " << img.size().width << endl; | |
// cout << "Coloums of Matrix " << img.size().height << endl; | |
// cout << "Values " << img.total() << endl; | |
//Mat imgH = img + Scalar(75, 75, 75); //increase the brightness by 75 units | |
//img.convertTo(imgH, -1, 1, 75); | |
//Mat imgL = img + Scalar(-75, -75, -75); //decrease the brightness by 75 units | |
//img.convertTo(imgL, -1, 1, -75); | |
namedWindow("Original Image", CV_WINDOW_AUTOSIZE); | |
namedWindow("High Brightness", CV_WINDOW_AUTOSIZE); | |
// namedWindow("Low Brightness", CV_WINDOW_AUTOSIZE); | |
imshow("Original Image", img); | |
imshow("High Brightness", outputImg); | |
// imshow("Low Brightness", imgL); | |
waitKey(0); | |
destroyAllWindows(); //destroy all open windows | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment