图像处理第五章代码
5.1
f=imread(‘D:\1\1.tif’);
[x1,map1]=rgb2ind(f,8,‘nodither’);
[x2,map2]=rgb2ind(f,8,‘dither’);
g=rgb2gray(f);
g1=dither(g);
subplot(3,3,1),imshow(‘D:\作业\tp\DIP3E_CH06_Original_Images\DIP3E_Original_Images_CH06\1.tif’)
subplot(3,3,2),imshow(x2,map1)
subplot(3,3,3),imshow(x2,map2)
subplot(3,3,4),imshow(g)
subplot(3,3,5),imshow(g1)
5.2
path=(‘D:\1\2.tif’);
%% RGB
I=imread(path);
figure();
subplot(111);
imshow(I);%显示原始彩色图像title(‘原始图像’);
%% HSI颜色空间
iHsi=rgb2hsi(I);
figure();
hsi_H=iHsi(:,:,1); %色调
hsi_S=iHsi(:,:,2); %饱和度
hsi_I=iHsi(:,:,3); %亮度
subplot(131);imshow(hsi_H);title(‘H(色调)’);
subplot(132);imshow(hsi_S);title(‘S(饱和度)’);
subplot(133);imshow(hsi_I);title(‘I(亮度)’);
5.3
L = linspace(40,80,1024); %构建线性斜坡
radius = 70;
theta = linspace(0,pi,1024);
a = radiuscos(theta);
b = radiussin(theta); %设置平面中的彩色极角
L=repmat(L,100,1);
a=repmat(a,100,1);
b=repmat(b,100,1);
lab_scale = cat(3,L,a,b); %制作一幅彩色标尺图像
cform = makecform(‘lab2srgb’);
rgb_scale = applycform(lab_scale,cform);
imshow(rgb_scale) %显示彩色标尺
5.4
f=imread(‘D:\作业\tp\DIP3E_CH06_Original_Images\DI