灰度图假彩色合成
clear;
clc;
f=imread('fae.bmp');%imshow(f);
[M,N]=size(f);L=255;
f=double(f);
f1=floor(f/64);
R=f1;G=f1;B=f1;
for i=1:M
for j=1:N
switch f1(i,j)
case 0
R(i,j)=0;G(i,j)=4*f(i,j);B(i,j)=L;
case 1
R(i,j)=0;G(i,j)=L;B(i,j)=-4*f+2*L;
case 2
R(i,j)=4*f-2*L;G(i,j)=L;B(i,j)=0;
case 3
R(i,j)=L;G(i,j)=4*f+4*L;B(i,j)=0;
end
end
end
g(:,:,1)=R;g(:,:,2)=G;g(:,:,3)=B;
g=uint8(g);figure;imshow(g);