display a gray scale image with three different colormaps as shown in figure 1. use the subplot routine and the imshow function. in matlab

Here is an example code snippet in MATLAB to display a gray scale image with three different colormaps using subplot routine and imshow function.

main.m
% Load an example grayscale image
I = imread('cameraman.tif');

% Define three different colormaps
map1 = gray(256);  % gray-scale colormap
map2 = hot(256);   % hot colormap
map3 = cool(256);  % cool colormap

% Create a figure with three subplots
figure;
subplot(1,3,1);
imshow(I);
colormap(map1);
title('Gray colormap');

subplot(1,3,2);
imshow(I);
colormap(map2);
title('Hot colormap');

subplot(1,3,3);
imshow(I);
colormap(map3);
title('Cool colormap');
458 chars
25 lines

The code first reads in an example grayscale image using imread function. Then, it defines three different colormaps - gray, hot and cool.

Next, a figure with three subplots is created using subplot routine. In each subplot, the same grayscale image is displayed using imshow function, but with a different colormap applied using colormap function. Finally, a title is added to each subplot to indicate the name of the colormap.

This will produce a figure similar to the one shown below.

Gray scale image with different colormaps

In this example, subplot routine is used to create a grid of smaller axes in a figure, which can be used to display multiple plots or images in a single figure window. imshow function is used to display the grayscale image in each subplot. colormap function is used to change the color mapping of the image.

gistlibby LogSnag