1 | initial version |
Code for changing contrast of image
******code starts here********
/* compilation:
pkg-config --cflags opencv
-o basename contrast.cpp .cpp
contrast.cpp pkg-config --libs opencv
Usage: ./contrast IMAGE.EXTENSION CONTRAST_ADDING_VALUE (eg: - ./contrast cat.jpg 100) */
int main(int argc, char** argv)
{
IplImage* src;
src=cvLoadImage(argv[1],1);
int add = atoi(argv[2]);
cvAddS(src, cvScalar(add),src);
cvNamedWindow( "example", CV_WINDOW_AUTOSIZE );
cvShowImage( "example", src );
cvWaitKey();
return 0;
}
Hope this helps you :)
2 | No.2 Revision |
Code for changing contrast of image
******code starts here********
/* compilation: pkg-config
basename
pkg-config
{
IplImage* src;
src=cvLoadImage(argv[1],1);
cvAddS(src, cvScalar(add),src);
cvWaitKey();
}
Hope this helps you :)
3 | No.3 Revision |
Code for changing contrast of image
******code starts here********
/* compilation:
1. chmod +x contrast.cpp
2. g++ -ggdb `pkg-config --cflags opencv` -o `basename contrast.cpp .cpp` contrast.cpp `pkg-config --libs opencv`
Usage: ./contrast IMAGE.EXTENSION CONTRAST_ADDING_VALUE
CONTRAST_ADDING_VALUE BRIGHTNESS_ADDING_VALUE
(eg: - ./contrast cat.jpg 2 100)
*/
#include <cv.h>
#include <highgui.h>
int main(int #include <iostream>
using namespace cv;
double alpha; /**< Simple contrast control */
int beta; /**< Simple brightness control */
int main( int argc, char** argv)
argv )
{
IplImage* src;
src=cvLoadImage(argv[1],1);
int add = atoi(argv[2]);
cvAddS(src, cvScalar(add),src);
cvNamedWindow( "example", CV_WINDOW_AUTOSIZE /// Read image given by user
Mat image = imread( argv[1] );
cvShowImage( "example", src Mat new_image = Mat::zeros( image.size(), image.type() );
cvWaitKey();
/// Initialize values
std::cout<<" Basic Linear Transforms "<<std::endl;
std::cout<<"-------------------------"<<std::endl;
std::cout<<"* Enter the alpha value [1.0-3.0]: ";std::cin>>alpha;
std::cout<<"* Enter the beta value [0-100]: "; std::cin>>beta;
/// 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 );
}
}
}
/// Create Windows
namedWindow("Original Image", 1);
namedWindow("New Image", 1);
/// Show stuff
imshow("Original Image", image);
imshow("New Image", new_image);
/// Wait until user press some key
waitKey();
return 0;
}
Hope this helps you :)