title: OpenCV-2.4.8.2: imshow differs from imwrite
body: <p>I'm using OpenCV2.4.8.2 on Mac OS 10.9.5.
  I have the following snippet of code:</p>
  
  <pre><code>static void compute_weights(const vector&lt;Mat&gt;&amp; images, vector&lt;Mat&gt;&amp; weights)
  {
      weights.clear();
      for (int i = 0; i &lt; images.size(); i++) {
          Mat image = images[i];
          Mat mask = Mat::zeros(image.size(), CV_32F);
          int x_start = (i == 0) ? 0 : image.cols/2;
          int y_start = 0;
          int width = image.cols/2;
          int height = image.rows;
          Mat roi  = mask(Rect(x_start,y_start,width,height)); // Set Roi
          roi.setTo(1);
          weights.push_back(mask);
      }
  }
  
  static void blend(const vector&lt;Mat&gt;&amp; inputImages, Mat&amp; outputImage)
  {
      int maxPyrIndex = 6;
      vector&lt;Mat&gt; weights;
      compute_weights(inputImages, weights);
  
      // Find the fused pyramid:
      vector&lt;Mat&gt; fused_pyramid;
      for (int i = 0; i &lt; inputImages.size(); i++) {
          Mat image = inputImages[i];
          // Build Gaussian Pyramid for Weights
          vector&lt;Mat&gt; weight_gaussian_pyramid;
          buildPyramid(weights[i], weight_gaussian_pyramid, maxPyrIndex);
  
          // Build Laplacian Pyramid for original image
          Mat float_image;
          inputImages[i].convertTo(float_image, CV_32FC3, 1.0/255.0);
          vector&lt;Mat&gt; orig_guassian_pyramid;
          vector&lt;Mat&gt; orig_laplacian_pyramid;
          buildPyramid(float_image, orig_guassian_pyramid, maxPyrIndex);
          for (int j = 0; j &lt; orig_guassian_pyramid.size() - 1; j++) {
              Mat sized_up;
              pyrUp(orig_guassian_pyramid[j+1], sized_up, Size(orig_guassian_pyramid[j].cols, orig_guassian_pyramid[j].rows));
              orig_laplacian_pyramid.push_back(orig_guassian_pyramid[j] - sized_up);
          }
          // Last Lapalcian layer is the same as the Gaussian layer
             orig_laplacian_pyramid.push_back(orig_guassian_pyramid[orig_guassian_pyramid.size()-1]);
  
          // Convolve laplacian original with guassian weights
          vector&lt;Mat&gt; convolved;
          for (int j = 0; j &lt; maxPyrIndex + 1; j++) {
              // Create 3 channels for weight gaussian pyramid as well
              vector&lt;Mat&gt; gaussian_3d_vec;
              for (int k = 0; k &lt; 3; k++) {
                  gaussian_3d_vec.push_back(weight_gaussian_pyramid[j]);
              }
              Mat gaussian_3d;
              merge(gaussian_3d_vec, gaussian_3d);
  
              //Mat convolved_result = weight_gaussian_pyramid[j].clone();
              Mat convolved_result = gaussian_3d.clone();
  
              multiply(gaussian_3d, orig_laplacian_pyramid[j], convolved_result);
              convolved.push_back(convolved_result);
          }
  
          if (i == 0) {
              fused_pyramid = convolved;
          } else {
              for (int j = 0; j &lt; maxPyrIndex + 1; j++) {
                  fused_pyramid[j] += convolved[j];
              }
          }
      }
      // Blending
      for (int i = (int)fused_pyramid.size()-1; i &gt; 0; i--) {
          Mat sized_up;
          pyrUp(fused_pyramid[i], sized_up, Size(fused_pyramid[i-1].cols, fused_pyramid[i-1].rows));
          fused_pyramid[i-1] += sized_up;
      }
  
      Mat final_color_bgr;
      fused_pyramid[0].convertTo(final_color_bgr, CV_32F, 255);
      final_color_bgr.copyTo(outputImage);
  
      imshow("final", outputImage);
      waitKey(0);
      imwrite(outputImagePath, outputImage);
  }
  </code></pre>
  
  <p>This code is doing some basic pyramid blending for 2 images. The key issues are related to imshow and imwrite in the last line. They gave me drastically different results. I apologize for displaying such a long/messy code, but I am afraid this difference is coming from some other parts of the code that can subsequently affect the imshow and imwrite. </p>
  
  <p>The first image shows the result from imwrite and the second image shows the result from imshow, based on the code given. I'm quite confused about why this is the case.
  <img src="https://i.stack.imgur.com/riGDJ.jpg" alt="imwrite&#39;s result">
  <img src="https://i.stack.imgur.com/d6Rx6.png" alt="imshow&#39;s result"></p>
  
  <p>I also noticed that when I do these:</p>
  
  <pre><code>Mat float_image;
  inputImages[i].convertTo(float_image, CV_32FC3, 1.0/255.0);
  imshow("float image", float_image);
  imshow("orig image", image);
  </code></pre>
  
  <p>They show exactly the same thing, that is they both show the same picture in the original rgb image (in image).</p>