【问题标题】:MATLAB: How to scale values to colorbar and return RGB 3 column matrixMATLAB:如何将值缩放到颜色条并返回 RGB 3 列矩阵
【发布时间】:2014-10-04 08:55:34
【问题描述】:

我有一个长度为 500 的数组 (A),其中包含 0 到 0.25 之间的值/p>

但是我想让 matlab 告诉我它为 A 中的每个值赋予的 rgb 值是什么。即大小为 500x3 的矩阵

我该怎么做,看起来应该很容易。

【问题讨论】:

    标签: image matlab rgb colorbar


    【解决方案1】:

    您可以通过键入:cm = jet(number_of_colors) 获取颜色图 jet 的颜色图 rgb 值。 现在您只需要在颜色映射矩阵中为每个值找到正确的索引...

    clear all
    number_of_colors = 100;
    cm = jet(number_of_colors);  % choose colorbar (jet)
    
    values = rand(1,500)*50 + 20; % your data
    
    values_min = min(values); % range of the colorbar
    values_max = max(values);  
    
    % Calculate the respective index in the colormap for every value
    idx_in_colorbar = floor(1+ (values - values_min) / (values_max -values_min) * (number_of_colors-1));
    
    matrix_with_rgb = cm(idx_in_colorbar,:)
    

    【讨论】:

      【解决方案2】:

      Matlab 实际上对数据的缩放有点不同, 所以正确的公式是:

      idx_in_colorbar = floor(1+ (values - values_min) / (values_max -values_min) * (number_of_colors)); idx_in_colorbar(idx_in_colorbar > number_of_colors) = number_of_colors;

      在此处查看更多信息:https://edoras.sdsu.edu/doc/matlab/techdoc/ref/caxis.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-04-03
        • 2016-04-06
        • 2011-09-18
        • 2011-03-04
        • 2019-09-09
        • 2012-11-03
        相关资源
        最近更新 更多