% pseudocoloring of a gray scale image
clear;close all
for k=1:256
  for j=1:256
     if (k>=1 && k<50)
       x(k,j)=0;
     elseif (k>=50 && k<100)
       x(k,j)=55;
     elseif (k>=100 && k<150)
       x(k,j)=105;
     elseif (k>=150 && k<200)
       x(k,j)=155;
     else
       x(k,j)=255;
     end
   end
end
x=mat2gray(x); % a gray scale image
mycolourmap1=[0 0 1;1 0 1;1 1 0;1 0 0;0 1 0];
mycolourmap2=[1 1 0;0 1 0;0 0 1;1 1 1;1 0 1];
mycolourmap3=[1 0 0;0 1 0;0 0 1;1 1 0;1 0 1];
x5=grayslice(x,5); % an indexed image, its values
% are indices to a color map

subplot(2,2,1)
subimage(x) % image display
axis off

subplot(2,2,2)
subimage(x5,mycolourmap1)
axis off

subplot(2,2,3)
subimage(x5,mycolourmap2)
axis off

subplot(2,2,4)
subimage(x5,mycolourmap3)
axis off