How to use the functions of convertTo, applyColorMap, imshow to replicate matlab output?
<p>Here is the code in Matlab and the result picture I get using Matlab. For some purposes, I need to convert Matlab code into C++. I have done the conversion of data structure in C++, and then I need to deal with the part of showing the picture. I decided to use OpenCV library to replace the image processing in Matlab. I have found that some functions like <code>convertTo</code>, <code>applyColorMap</code> and <code>imshow</code> in OpenCV can replace the function <code>imagesc</code> in Matlab. So, I imitate the code online I searched. But it doesn't work.</p>

<p>Here is my code in C++:</p>

<pre><code>for (cutNumber = 1; cutNumber &lt;= 9; cutNumber++)
{
    momentString = "dBT";
    DataSelect* BaseData_Select = select(theObj,cutNumber,momentString);
    int ncols = BaseData_Select-&gt;allLength / BaseData_Select-&gt;dataLength;
    // 对应matlab auto.m第138行。下面是绘制dBZ的B显图
    Mat mydata(BaseData_Select-&gt;dataLength, ncols, CV_32F);
    for (int i = 0; i &lt; BaseData_Select-&gt;dataLength; i++)
    {
        for (int j = 0; j &lt; ncols; j++)
        {
            int temmmp = i*ncols+ j;
            mydata.at&lt;float&gt;(i, j) = BaseData_Select-&gt;data[i*ncols + j];
        }
    }
    double Amin = *min_element(mydata.begin&lt;float&gt;(), mydata.end&lt;float&gt;()); // Amin is -19
    double Amax = *max_element(mydata.begin&lt;float&gt;(), mydata.end&lt;float&gt;()); // Amax is 64
    cv::minMaxIdx(mydata, &amp;Amin, &amp;Amax);
    cv::Mat adjMap;
    float scale = 255 / (Amax - Amin);
    mydata.convertTo(adjMap, CV_8UC1, scale, -Amin*scale);
    cv::Mat resultMap;
    applyColorMap(adjMap, resultMap, cv::COLORMAP_AUTUMN);
    cv::imshow("Out", resultMap);
    cv::imwrite("output.bmp", resultMap);
}
</code></pre>

<p>Here is the code dealing with images in Matlab.</p>

<pre><code>figure(H_figure_PHIDP);
subplot(3,3,Cut_Number);
imagesc(PHIDP.Data);
colormap('default');
caxis([ -20 60]);
ylim([Sphere_Distance_Cell-Sphere_Distance_Cell_Extend Sphere_Distance_Cell+Sphere_Distance_Cell_Extend])
xlim([Sphere_Center_Ray-Sphere_Azimuth_Cell_Extend Sphere_Center_Ray+Sphere_Azimuth_Cell_Extend])
xlabel('径向数目');
ylabel('距离库');
</code></pre>

<p>The result picture running on Matlab which is I want to get using OpenCV functions.</p>

<p><img src="https://i.stack.imgur.com/gjfIa.png" alt="enter image description here"></p>

<p>And my result picture in C++ is the following picture which is the wrong picture absolutely.</p>

<p><img src="https://i.stack.imgur.com/ZmVgW.png" alt="enter image description here"></p>

<p>Could any one help me to solve this problem?</p>