Skip to content

Instantly share code, notes, and snippets.

@b-oern
Created May 26, 2013 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b-oern/5654045 to your computer and use it in GitHub Desktop.
Save b-oern/5654045 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main( int argc, char** argv ) {
Mat image;
image = imread( argv[1], 1 );
if( argc != 2 || !image.data ) {
printf( "No image data \n" );
return -1;
}
Mat new_image = Mat::zeros( image.size(), image.type() );
double alpha = 1.5;
double beta = 75;
/// Do the operation new_image(i,j) = alpha*image(i,j) + beta
for( int y = 0; y < image.rows; y++ ) {
for( int x = 0; x < image.cols; x++ ) {
for( int c = 0; c < 3; c++ ) {
new_image.at<Vec3b>(y,x)[c] = saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta );
}
}
}
imwrite("alpha.jpg", new_image);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment