title: openCV: Plotting a colormap from a matrix
body: <p>I have a 50 x 50 matrix having certain values  from 1 to 50. I need to plot a color map for the same using OpenCV . </p>
  
  <p>I have already done this in MATLAB (with help from <a href="https://stackoverflow.com/questions/15676363/matlab-how-does-one-plot-a-heatmap-from-nxn-matrix">this answer</a>):</p>
  
  <pre><code>&gt;&gt; A = randi([10,60],100,100);
  &gt;&gt; colormap('hot')
  &gt;&gt; imagesc(A)
  &gt;&gt; colorbar    
  </code></pre>
  
  <p>And the output comes like <img src="https://i.stack.imgur.com/9inAk.png" alt="this">. </p>
  
  <p>I would like to do the same  using openCV.   </p>
  
  <p>How do I proceed for this ? </p>
  
  <p>I am unable to understand  how do I implement the function of "hot"  which appears like this (see only hot) </p>
  
  <p><img src="https://i.stack.imgur.com/dP9eY.gif" alt="like this">:</p>
  
  <p>Additionally I would also be interested in putting a color bar as shown in the first image.   </p>
  
  <hr>
  
  <p><strong>Update (Final code I am running)</strong> </p>
  
  <p>Unfortunately still I am unable to plot the correct color map: Here is the MATLAB code:</p>
  
  <p>Note : A is a 10 by 100 matrix. </p>
  
  <p>A=[0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 ;
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9;
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5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 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9;
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9;
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9;
      ]</p>
  
  <p>colormap('hot'); 
   imagesc(A)
    colorbar</p>
  
  <p>And here is the output:</p>
  
  <p><img src="https://i.stack.imgur.com/uJEFQ.png" alt="enter image description here"></p>
  
  <p>Now I created a text file with same data, and my text file looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/zbhPS.jpg" alt="enter image description here"></p>
  
  <p>And used the following code to achieve the same result as of MATLAB: </p>
  
  <pre><code>   int main() 
  
  
  {
  
  
  
  
  ifstream Read("myfile.txt");
  
  vector&lt;int&gt; nums;
  while ( !Read.eof() ) {
      int n;
      Read &gt;&gt; n;
      nums.push_back(n);
  }
  // now make a Mat from the vector:
  Mat mat(nums);
  
  cout&lt;&lt;mat&lt;&lt;endl; //for testing 
  
  
  Mat mat1d(nums);
  Mat mat2d = mat1d.reshape(1, 10);
  //
  Mat image; //create an empty image. (you can leave it empty ;)
  //// Apply the colormap, but on the 2d mat, not on the 2d vector, please:
  applyColorMap( mat2d, image, COLORMAP_JET );
              // Show the result:
  imshow("colormap", image);
  waitKey(0);
  return 0;
  }
  </code></pre>
  
  <p>But the output from the above is meaningless.</p>
  
  <p>I need to match the results from MATLAB and Opencv.    </p>