Strange colormap behaviour in MATLAB 2013b

조회 수: 1 (최근 30일)
Pawel Tokarczuk
Pawel Tokarczuk 2014년 5월 6일
답변: Pawel Tokarczuk 2014년 5월 6일
I want to use a colormap in a MATLAB GUI to review a large number of images from an earlier analysis. I have tested the following script and it gives me two slightly different displays:
clear all
close all
clc
fclose('all');
a = linspace(0, 255, 256);
b = imresize(a, [256, 256]);
% Smooth display here
f = figure;
imshow(b, [0, 255]);
colormap(jet);
click = waitforbuttonpress;
delete(f);
pause(0.25);
% Dark vertical stripes here
g = figure;
imshow(b, [0, 255], 'Colormap', jet);
click = waitforbuttonpress;
delete(g);
So, what is happening here, and which form is correct ?

채택된 답변

Image Analyst
Image Analyst 2014년 5월 6일
In the first case it uses a 256 index mapping while in the second case it uses 64. Actually 64 is the default as you can see just by typing cm=jet on the command line so I don't know why the first case puts up 256 colors instead of 64. Try this code:
clear all
close all
clc
workspace
fclose('all');
a = linspace(0, 255, 256);
b = imresize(a, [256, 256]);
% Smooth display here
figure;
imshow(b, [0, 255]);
c1 = colormap(jet) % Retrieve the colormap that is actually being used.
colorbar;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 .5 1]);
% Dark vertical stripes here
figure;
imshow(b, [0, 255], 'Colormap', jet(256));
colorbar;
c2 = colormap() % Retrieve the colormap that is actually being used.
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [.50 0 .5 1]);
Notice how I made the second figure smooth by specifying 256 colors instead of the default 64:
imshow(b, [0, 255], 'Colormap', jet(256));
Look in the Workspace panel at the sizes for c1 and c2 as you pass different numbers into jet() as an argument. You can use jet, jet(16), jet(64), jet(256), etc. but you can't use a number more than 256.

추가 답변 (1개)

Pawel Tokarczuk
Pawel Tokarczuk 2014년 5월 6일
Many thanks, that's clear and complete. I hadn't realized that 'jet' could take a parameter - I assumed it was a built-in function or a named global array, and always the same. Over and out.

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by