2

I want to increase the contrast of the bellow picture, with opencv c++.

enter image description here

I use histogram processing techniques e.g., histogram equalization (HE), histogram specification, etc. But I don't reaches to good result such as bellow images:

enter image description here

What ideas on how to solve this task would you suggest? Or on what resource on the internet can I find help?

3 Answers3

4

I found a useful subject on OpenCV for changing image contrast :

#include <cv.h>
#include <highgui.h>
#include <iostream>

using namespace cv;

double alpha; /**< Simple contrast control */
int beta;  /**< Simple brightness control */

int main( int argc, char** argv )
{
 /// Read image given by user
 Mat image = imread( argv[1] );
 Mat new_image = Mat::zeros( image.size(), image.type() );

 /// 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;
}

See: Changing the contrast and brightness of an image!

  • this a linear transformation and it doesn't reaches to good result such as images in top. –  Jun 06 '16 at 07:17
  • @AlirezaAlipourBloordokani have any method else linear transformation? can this help you? See:[the fastest way to increase color image contrast...](http://stackoverflow.com/questions/19363293/whats-the-fastest-way-to-increase-color-image-contrast-with-opencv-in-python-c) – BattleTested_закалённый в бою Jun 06 '16 at 07:43
  • I use all techniques but they don't reach to good result such as images in top. I need a powerful algorithm ..... –  Jun 06 '16 at 08:27
  • @AlirezaAlipourBloordokani i can offer you, to reading an Image Processing book. because it analysis all methods such as : Artificial Intelligence. perhaps this can help you. – BattleTested_закалённый в бою Jun 06 '16 at 08:35
  • I read "OpenCV 2 Computer Vision Application Programming Cookbook" and "Learning OpenCV ", but they can not help me. –  Jun 06 '16 at 08:42
  • @ Mohammadreza Panahi I see http://stackoverflow.com/questions/19363293/whats-the-fastest-way-to-increase-color-image-contrast-with-opencv-in-python-c but I can't convert to c++. Could you help me convert it to c++? –  Jun 06 '16 at 11:11
  • @AlirezaAlipourBloordokani if you haven't any solution, you must use of a common method, that every body use of it. i hope you to be succeed! – BattleTested_закалённый в бою Jun 06 '16 at 11:13
2

I'm no expert but you could try to reduce the number of colours by merging grays into darker grays, and light grays into whites.

E.g.:

  • Find the least common colour in <0.0, 0.5) range, merge it towards black.
  • Find the least common colour in <0.5, 1.0> range, merge it towards white.

This would reduce the number of colours and help create a gap between brigher darker colours maybe.

hauron
  • 4,550
  • 5
  • 35
  • 52
  • 1
    This could be better achieved by using a cluster algorithm such as k-means. Here is a tutorial: https://www.pyimagesearch.com/2014/07/07/color-quantization-opencv-using-k-means-clustering/ – richar8086 Dec 02 '17 at 11:50
2

This might be late, but you can try createCLAHE() function in openCV. Works fine for me.

Jiawei Sun
  • 53
  • 3
  • 6