在OpenCV中等效于imagesc [英] What is the equivalent of imagesc in OpenCV

查看:204
本文介绍了在OpenCV中等效于imagesc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相当于 imagesc 在OpenCV中?

What would be the equivalent of imagesc in OpenCV?

推荐答案

要在imagesc中获得漂亮的颜色,您必须使用OpenCV.在OpenCV 2.46中,有一个colormap选项.

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.

这是我在c ++中使用的代码.我确定它在Python中非常相似.

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);

图像数据或矩阵数据存储在mydata中.我知道它的最大值为10000,因此我将其缩小为1,然后乘以CV_8UC1的范围即255.如果您不知道该范围是最好的选择,则是

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.

编辑

这是一个自动规范您的数据的版本.

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);

这篇关于在OpenCV中等效于imagesc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆