Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of imagesc in OpenCV

What would be the equivalent of imagesc in OpenCV?

like image 425
Rahul Avatar asked Jan 12 '23 07:01

Rahul


1 Answers

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);
like image 159
twerdster Avatar answered Jan 14 '23 19:01

twerdster