使用matlab颜色方案将浮点数转换为RGB [英] Use matlab colour scheme to convert float to RGB

查看:2491
本文介绍了使用matlab颜色方案将浮点数转换为RGB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个float,例如 0.568 (float被保证为 0 - > 1 ) 。是否有一种方法将它转换为RGB值(在双 [1.0,1.0,1.0] 或int [255 255 255]

If i have a float, for example 0.568 (float is guaranteed to be 0 -> 1). Is there a way to convert that to RGB values (in double [1.0, 1.0, 1.0] or int [255 255 255]) under the current matlab colour scheme (ie. normal, hot, hsv, etc)?

推荐答案

您可以尝试这:

f = 0.568; % your float

cm = colormap % returns the current color map

colorID = max(1, sum(f > [0:1/length(cm(:,1)):1])); 

myColor = cm(colorID, :) % returns your color

f = 0.568 的结果为

myColor =

    0.8125    1.0000    0.1875

这篇关于使用matlab颜色方案将浮点数转换为RGB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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