Array to RBG values?

24 views (last 30 days)
Pavel Inchin
Pavel Inchin on 24 Jul 2018
Answered: Walter Roberson on 24 Jul 2018
I have 3 arrays: 1. latitude 2. longitude 3. value at that position
I need to get RGB for every value from array "3" in order to after that represent it as hex color string to put into KMZ.
How can I find RGB triple for every value in array "3" (setting particular colormap). I know that I can get RGB from imagesc, but it is not clear how to work if my data is presented as arrays.
Thanks

Accepted Answer

Walter Roberson
Walter Roberson on 24 Jul 2018
As you mention imagesc, I will presume that you want the minimum value to map to the first color in the colormap, and the max value to map to the last color in the colormap.
cmap = jet(107); %define colormap and number of entries, max 256
mg = mat2gray(ValueArray);
mgint = im2uint8(mg);
rgb = ind2rgb(mgint, cmap);
hexstr = reshape(cellstr(num2str(reshape(rgb, [], 3), '%02x')), size(rgb,1), size(rgb,2));
The result will be a cell array with the same number of rows and columns as the image, and each entry will be a character vector length 6 of hex digits, in the order R, G, B

More Answers (0)

Products


Release

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!