简体   繁体   中英

To map RGB to Parula in Matlab

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 ie 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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM