What would be the equivalent of imagesc
in OpenCV?
To get the nice colors in imagesc you have to play around with OpenCV a little bit. In OpenCV 2.46 there ss a colormap option.
This is code I use in c++. Im sure its very similar in Python.
mydata.convertTo(display, CV_8UC1, 255.0 / 10000.0, 0);
applyColorMap(display, display, cv::COLORMAP_JET);
imshow("imagesc",display);
The image data or matrix data is stored in mydata
. I know that it has a maximum value of 10000 so I scale it down to 1 and then multiply by the range of CV_8UC1 which is 255. If you dont know what the range is the best option is to first convert your matrix in the same way as Matlab does it.
EDIT
Here is a version which automatically normalizes your data.
float Amin = *min_element(mydata.begin<float>(), mydata.end<float>());
float Amax = *max_element(mydata.begin<float>(), mydata.end<float>());
Mat A_scaled = (mydata - Amin)/(Amax - Amin);
A_scaled.convertTo(display, CV_8UC1, 255.0, 0);
applyColorMap(display, display, cv::COLORMAP_JET);
imshow("imagesc",display);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With