problem with jet colormap

6 views (last 30 days)
joanna
joanna on 21 Nov 2012
I have 7 images displayed on each axes in my GUI but i only want one image to be shown in colormap format. Instead of displaying only for one axes, the colormap command actually changed all my images to colormap format.
axes(handles.axes14)
imagesc(abs(stressdiff)),title('Stress distribution'),xlabel('Pixel'),ylabel('Pixel'),colorbar, colormap(jet);
how can i solve this problem?

Answers (4)

John Petersen
John Petersen on 21 Nov 2012
Have you tried,
imagesc(......,'Parent',handles.axes14)

Matt Fig
Matt Fig on 21 Nov 2012
That's what a colormap does....
>> help colormap
colormap Color look-up table.
colormap(MAP) sets the current figure's colormap to MAP.
......

Walter Roberson
Walter Roberson on 21 Nov 2012
See the FEX contribution freezeColors

Image Analyst
Image Analyst on 21 Nov 2012
Edited: Image Analyst on 22 Nov 2012
Check out the documentation:
How do I use multiple colormaps in a single figure?
There's a slight problem with their demo in that they conveniently have the input image be so few gray levels that they can make the colormap in the 0-255 range without altering the gray levels. In general you can't do that, so I made up a more general demo where the image is nearly the full 256 gray levels and still works (their demo doesn't work in that case).
% Boilerplate cleanup code:
clc;
clearvars;
close all;
imtool close all; % Close all imtool figures.
workspace;
format longg;
format compact;
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% The colormap can only be 256 rows long (otherwise it repeats - you can't assign them).
% So make each image only a portion of the 256 gray levels.
% Define a colormap that consists of 4 separate colormaps.
% So make each colormap section 256/4 = 64 rows long.
numberOfImages = 4;
cmap = [gray(256/numberOfImages);...
jet(256/numberOfImages);...
copper(256/numberOfImages);...
winter(256/numberOfImages)];
% Apply the colormap to the figure.
colormap(cmap);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% if there are 4 images, each needs to be displayed in 256/4 or 64 gray levels.
% Use imadjust() to map the original gray image into that range.
% Generate the first image.
subplot(2, 2, 1);
% Map into 0-63.
firstImage = imadjust(grayImage, [], [0 1/numberOfImages]);
% Display image mapped into the new intensity range.
image(firstImage);
title('Gray Colormap', 'FontSize', fontSize);
colorbar;
% Generate the other images such that
subplot(2, 2, 2);
% Map into 64-127.
secondImage = imadjust(grayImage, [], [1/numberOfImages 2/numberOfImages]);
% Display image mapped into the new intensity range.
image(secondImage);
title('Jet Colormap', 'FontSize', fontSize);
colorbar;
subplot(2, 2, 3);
% Map into 128-191.
thirdImage = imadjust(grayImage, [], [2/numberOfImages, 3/numberOfImages]);
% Display image mapped into the new intensity range.
image(thirdImage);
title('Hot Colormap', 'FontSize', fontSize);
colorbar;
subplot(2, 2, 4);
% Map into 192-255.
fourthImage = imadjust(grayImage, [], [3/numberOfImages, 4/numberOfImages]);
% Display image mapped into the new intensity range.
image(fourthImage);
title('Winter Colormap', 'FontSize', fontSize);
colormap(cmap)
colorbar;

Community Treasure Hunt

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

Start Hunting!