Problem using ind2rgb and CDataMapping

6 ビュー (過去 30 日間)
Shay
Shay 2012 年 7 月 31 日
Hi, I have a matrix (M) with values ranging from 0 to 5000 that I want to save as an RGB image.
When plotting the image using imagesc(M,'cdatamapping','scaled'); i see exactly what i want.
However, using rgbM=ind2rgb(M,jet); (I tried different sized colormaps, didnt help)
rgbM now has only 2~3 colors and plotting it looks completely different.
I can't find help for this seemingly simple problem online... Any tips on how it should be done?

採用された回答

Teja Muppirala
Teja Muppirala 2012 年 7 月 31 日
You need to call IND2RGB with a colormap that is as big as your data. Something like this:
M = round(5000*rand(300,300));
imagesc(M,'cdatamapping','scaled');
rgbM = ind2rgb(M - min(M(:)) + 1, jet(range(M(:))+1));
figure;
image(rgbM);
  1 件のコメント
Syed
Syed 2013 年 1 月 14 日
Surprisingly, this doesn't work for 1D images.
x = round(64 * (0.01:0.01:0.99));
figure(1); clf(1);
subplot(211); imagesc(x, 'cdatamapping', 'scaled'); colormap jet;
subplot(212); image(ind2rgb(x - min(x(:)) + 1, jet(range(x(:)) + 1)));
Look at how the spectrum changes in the latter half of the image (the reds):

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

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 7 月 31 日
I recommend using the File Exchange contribution freezecolors. That will convert your colormapped image into an RGB image; you can then get() the CData of the image as your rgbM array.
  1 件のコメント
Shay
Shay 2012 年 7 月 31 日
Tried freezeColors, it changed the color mapping on the displayed image and the same problem occurs (only shows 2~3 colors).
I should maybe add that i am doing all this in a matlab GUI with 3 axes, not sure if that matters.

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


Image Analyst
Image Analyst 2012 年 7 月 31 日
編集済み: Image Analyst 2012 年 7 月 31 日
Or you can try mat2gray and jet(256)
newImage = mat2gray(oldImage);
imshow(newImage);
colormap(jet(256));

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by