map from value to colormap

51 ビュー (過去 30 日間)
Guy Eyal
Guy Eyal 2014 年 7 月 31 日
編集済み: KSSV 2020 年 6 月 23 日
I use pcolor to create a figure out of some matrix of data.
h=pcolor(X,Y,M);
Is it possible to receive for a specific index in the matrix in which color (RGB values) pcolor used (assuming a constant colormap)?
Or should i ask it - If I have a colormap and caxis - is there any function that will give me the color of a value (mapping from value to rgb value in the colormap)?
Thanks

採用された回答

Arun Mathew Iype
Arun Mathew Iype 2014 年 7 月 31 日
Please check the solution provided at the below link by Jason D. Yeatman which does the exact thing that you want http://web.stanford.edu/~jyeatman/AFQ/doc/utilities/vals2colormap.html#_top
function rgb = vals2colormap(vals, colormap, crange)
0002 % Take in a vector of N values and return and return a Nx3 matrix of RGB
0003 % values associated with a given colormap
0004 %
0005 % rgb = AFQ_vals2colormap(vals, [colormap = 'jet'], [crange])
0006 %
0007 % Inputs:
0008 % vals = A vector of values to map to a colormap or a cell array of
0009 % vectors of values
0010 % colormap = A matlab colormap. Examples: colormap = 'autumn';
0011 % colormap = 'jet'; colormap = 'hot';
0012 % crange = The values to map to the minimum and maximum of the colormap.
0013 % Defualts to the full range of values in vals.
0014 %
0015 % Outputs:
0016 % rgb = Nx3 matrix of rgb values mapping each value in vals to the
0017 % corresponding rgb colors. If vals is a cell array then rgb
0018 % will be a cell array of the same length
0019 %
0020 % Example:
0021 % vals = rand(1,100);
0022 % rgb = AFQ_vals2colormap(vals, 'hot');
0023 %
0024 % Copyright Jason D. Yeatman, June 2012
  3 件のコメント
Hamidreza Heydarian
Hamidreza Heydarian 2019 年 1 月 12 日
編集済み: KSSV 2020 年 6 月 23 日
Image Analyst
Image Analyst 2019 年 1 月 12 日
編集済み: Image Analyst 2019 年 1 月 12 日
Maybe not a bad thing considering the bad programming practices they used. For example, calling an input argument colormap when colormap is the name of a built in function. So how can you use the colormap function to get the arrays? I'm almost certain you can't do
cmap = colormap(colormap);
Assuming you just put in the string directly, you can probably do pretty much the same thing by doing this:
grayImage = imread('pout.tif');
subplot(2,2,1);
imshow(grayImage);
fontSize = 14;
title('Gray Scale Image', 'FontSize', fontSize);
subplot(2,2,2);
imhist(grayImage);
grid on;
title('Histogram', 'FontSize', fontSize);
% Define range of gray levels that the colormap should go between.
grayLevelRange = [75, 150]; % Whatever you want.
cmap = jet(256);
% Specify color for gray levels below the specified range.
cmap1 = repmat(cmap(1,:), [grayLevelRange(1), 1]);
% Let the middle part be remapped such that the full colormap
% covers the specified gray level range.
cmap2 = imresize(cmap, [abs(grayLevelRange(2) - grayLevelRange(1) + 1), 3]);
% Specify color for gray levels above the specified range.
cmap3 = repmat(cmap(end, :), [255 - grayLevelRange(2), 1]);
% Combine to form a new colormap.
cmap = [cmap1; cmap2; cmap3];
% Apply the colormap to the gray scale image to form an RGB image.
rgbImage = ind2rgb(grayImage, cmap);
% Display the RGB image.
subplot(2, 2, 3);
imshow(rgbImage);
title('RGB Color-Mapped Image', 'FontSize', fontSize);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by