伪彩色增强主要有密度分割法和空间域灰度级-彩色变换法。
利用密度分割法来实现图像的伪彩色增强。
clear all;
I = imread('lenna.jpg');
I = rgb2gray(I);
figure,
subplot(1,2,1);
imshow(I);
title('原始图像')
I = double(I);
c = zeros(size(I));
d = ones(size(I))*255;
pos = find(((I>=32)&(I<63))|((I>=96)&(I<127))|((I>=154)&(I<191))|((I>=234)&(I<=255)));
c(pos)=d(pos);
f(:,:,3)=c;
c = zeros(size(I));
d = ones(size(I))*255;
pos = find(((I>=64)&(I<95))|((I>=96)&(I<127))|((I>=192)&(I<233))|((I>=234)&(I<=255)));
c(pos)=d(pos);
f(:,:,2)=c;
c = zeros(size(I));
d = ones(size(I))*255;
pos = find(((I>=128)&(I<154))|((I>=154)&(I<191))|((I>=192)&(I<233))|((I>=234)&(I<=255)));
c(pos)=d(pos);
f(:,:,1)=c;
f = uint8(f);
subplot(1,2,2);
imshow(f);
title('密度分割法伪彩色增强')
运行结果如图所示:
clear all;
I = imread('lenna.jpg');
I = rgb2gray(I);
figure,
subplot(1,2,1);
imshow(I);
title('原始图像')
I = double(I);
[M,N] = size(I);
L = 256;
for i=1:M
for j=1:N
if I(i,j)<=L/4;
R(i,j)=0;
G(i,j)=4*I(i,j);
B(i,j)=L;
else
if I(i,j)<=L/2;
R(i,j)=0;
G(i,j)=L;
B(i,j)=4*I(i,j)+2*L;
else
if I(i,j)<=3*L/4
R(i,j)=4*I(i,j)-2*L;
G(i,j)=L;
B(i,j)=0;
else
R(i,j)=L;
G(i,j)=-4*I(i,j)+4*L;
B(i,j)=0;
end
end
end
end
end
for i=1:M
for j=1:N
C(i,j,1)=R(i,j);
C(i,j,2)=G(i,j);
C(i,j,3)=B(i,j);
end
end
C=uint8(C);
subplot(1,2,2);
imshow(C);
title('空间域灰度级-彩色变换法的伪彩色增强')