To map RGB to Parula in Matlab

后端 未结 1 1951
时光取名叫无心
时光取名叫无心 2021-01-21 05:09

There are functions such as rgb2hsv, rgb2ind, rgb2lab and rgb2xyz in converting RGB colormap to another one - in Matlab R2014b where the colo

1条回答
  •  -上瘾入骨i
    2021-01-21 05:40

    This is not really possible, because Parula does not contain all the possible RGB values. If you think about it, every Matlab colormap is just a subset of the RGB ensemble. In mathematical terms rgb2hsv is an isomorphism, but there cannot be such isomorphism between RGB and a colormap (even the hsv colormap, which does not take all possible HSV values).

    Then for a given RGB triplet you can try to find the nearest RGB triplet inside the Parula colormap. Something like:

    cm = parula(256);
    RGB = rand(1,3);
    
    d2 = (cm(:,1)-RGB(1)).^2 + (cm(:,2)-RGB(2)).^2 + (cm(:,3)-RGB(3)).^2;
    [~, mi] = min(d2);
    

    and cm(mi,:) will be the nearest color to RGB in Parula according to this metric. But of course, this is an imperfect solution.

    0 讨论(0)
提交回复
热议问题