Okay, okay. I know your next question is going to be "I don't know
how to do that, can you show me every step of the way in explicit,
gory detail?"
So here it is:
(Some long lines may get split into two by the newsreader. If so,
join them to avoid syntax errors.)
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Program Files\MATLAB\R2010a\toolbox\images\imdemos';
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Image with linear "jet" colormap', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Apply a colormap
cmap = jet(256);
colormap(cmap);
% Get the individual colormaps, just for fun.
redMap = cmap(:,1);
greenMap = cmap(:,2);
blueMap = cmap(:, 3);
% Display the colorband maps, again just for fun.
subplot(2,2,2);
plot(redMap);
title('Red Map', 'FontSize', fontSize);
subplot(2,2,3);
plot(greenMap);
title('Green Map', 'FontSize', fontSize);
subplot(2,2,4);
plot(blueMap);
title('Blue Map', 'FontSize', fontSize);
figure;
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.
% Construct the new colormaps with the new spacing.
% y = logspace(a,b,n) generates n points between decades 10^a and
10^b.
newX = logspace(0, log10(256), 256);
logRedMap = interp1(1:256, redMap, newX);
logGreenMap = interp1(1:256, greenMap, newX);
logBlueMap = interp1(1:256, blueMap, newX);
% Display the new colormaps
subplot(2,2,2);
plot(logRedMap);
title('Red Map', 'FontSize', fontSize);
subplot(2,2,3);
plot(logGreenMap);
title('Green Map', 'FontSize', fontSize);
subplot(2,2,4);
plot(logBlueMap);
title('Blue Map', 'FontSize', fontSize);
% Display the image again.
subplot(2,2,1);
imshow(grayImage, []);
title('Image with log colormap', 'FontSize', fontSize);
% Apply the new colormap to the gray scale image.
logMap = [logRedMap; logGreenMap; logBlueMap]';
colormap(logMap);
|