在Matlab中将RGB映射到Parula [英] To map RGB to Parula in Matlab
问题描述
在将RGB颜色映射转换为另一个颜色映射时,有诸如 rgb2hsv , rgb2ind , rgb2lab 和 rgb2xyz - 在Matlab R2014b中,其中引入了色彩映射
然而,我找不到任何解决方案将RGB色彩映射转换为 Parula ,即当前默认的颜色映射Matlab。
我可以设置色彩映射与图,但不能转换图像如下。
我开始认为Parula的好处与HSV相比,在一部分去除黑色和它的邻居颜色在图片中,例如是Gnuplot关于色彩映射的变体。
如何将这段代码转换为Matlab?
这是不可能的,因为 Parula
不包含所有可能的RGB值。如果你想到它,每个Matlab色彩映射只是RGB集合的一个子集。在数学术语中, rgb2hsv
是一个同构,但是在RGB和色彩映射之间不能有同构性(即使是 hsv
,这不会解决所有可能的HSV值)。
然后对于给定的RGB三元组,您可以尝试找到Parula色图中最近的RGB三元组。像:
cm = parula(256)
RGB = rand(1,3);
d2 =(cm(:,1)-RGB(1))。^ 2 +(cm(:,2)-RGB )-RGB(3))。
[〜,mi] = min(d2);
和 cm(mi,:)
根据此度量,是Parula中最接近RGB的颜色。但当然,这是一个不完美的解决方案...
最好,
There are functions such as rgb2hsv, rgb2ind, rgb2lab and rgb2xyz in converting RGB colormap to another one - in Matlab R2014b where the colormap Parula is introduced. However, I cannot find any solution to convert the RGB colormap to Parula i.e. the current default colormap of Matlab. I can set the colormap to be with the figure, but not convert the image as follows. I started to think the benefits of Parula in contrast to HSV in one part of removing black and its neighbor colors in a picture, for example here.
Pseudocommand
im = imread('http://i.stack.imgur.com/cFOSp.png');
hsv = rgb2parula(im); % Pseudocommand similar for HSV: hsv = rgb2hsv(im);
imshow(hsv);
which gives
which is one reason for the quantization noise in later stages of image processing and bad morphological removal, as indicated in the previous thread.
How can you map RGB to Parula in Matlab?
User-made Parulas
I think we need a customized Parula because the function rgb2parula is not available. Proposal here which a variant for Gnuplot about the colormap. How can you convert this piece of code to Matlab?
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 tacke 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 ...
Best,
这篇关于在Matlab中将RGB映射到Parula的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!