title: Using saturate_cast or not
body: <p>This is a simple program to change contrast and brightness of an image. I have noticed that there is a an another program with one simple difference:<code>saturate_cast</code> is added to code.
  And I don't realize what is the reason of doing this and there is no need to converting to unsigned char or <code>uchar</code> both code (with <code>saturate_cast&lt;uchar&gt;</code> and to not use this) are outputting the same result. I appreciate if anyone help.</p>
  
  <p>Here it is code :</p>
  
  <pre><code>#include "opencv2/imgcodecs.hpp"
  #include "opencv2/highgui/highgui.hpp"
  #include &lt;iostream&gt;
  #include "Source.h"
  
  
  using namespace cv;
  
  double alpha;
  int beta;
  int main(int, char** argv)
  {
      /// Read image given by user
      Mat image = imread(argv[1]);
      Mat image2 = Mat::zeros(image.size(), image.type());
  
  
  
  /// Initialize values
          std::cout &lt;&lt; " Basic Linear Transforms " &lt;&lt; std::endl;
          std::cout &lt;&lt; "-------------------------" &lt;&lt; std::endl;
          std::cout &lt;&lt; "* Enter the alpha value [1.0-3.0]: ";std::cin &gt;&gt; alpha;
          std::cout &lt;&lt; "* Enter the beta value [0-100]: "; std::cin &gt;&gt; beta;
      for (int x = 0; x &lt; image.rows; x++)
          {
              for (int y = 0; y &lt; image.cols; y++)
              {
                  for (int c = 0; c &lt; 3; c++)
                  {
                      image2.at&lt;Vec3b&gt;(x, y)[c] =
  
                    saturate_cast&lt;uchar&gt;(alpha*(image.at&lt;Vec3b&gt;(x, y)[c]) + beta);
  
          }
      }
  
      /// Create Windows
      namedWindow("Original Image", 1);
      namedWindow("New Image", 1);
  
      /// Show stuff
      imshow("Original Image", image);
      imshow("New Image", image2);
  
  
      /// Wait until user press some key
      waitKey();
      return 0;
  }
  </code></pre>