Figure,rgbcube(0,0,10); %从正面观察彩色立方体
figure,rgbcube(10,0,10); %从侧面观察彩色立方体
figure,rgbcube(10,10,10); %从对角线观察彩色立方体
![](https://img-blog.csdnimg.cn/2019051909562978.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519095640795.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519095707556.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
f=imread('你的图');
imshow(f);
%rgb图像转换成8色索引图像,不采用抖动方式
[X1,map1]=rgb2ind(f,8,'nodither');
figure,imshow(X1,map1);
%采用抖动方式转换到8色索引图像
[X2,map2]=rgb2ind(f,8,'dither');
figure,imshow(X2,map2);%显示效果要好一些
g=rgb2gray(f);%f转换为灰度图像
g1=dither(g);%将灰色图像经过抖动处理,转换打二值图像
figure,imshow(g); %显示灰度图像
figure,imshow(g1);%显示抖动处理后的二值图像
![](https://img-blog.csdnimg.cn/2019051909581837.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/2019051909583126.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519095847314.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519095929431.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519095933568.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
f=imread('你的图');%
ntsc_img=rgb2ntsc(f); %转换到NTSC彩色空间
hsi_img=rgb2hsi(f);
subplot(241),imshow(f),title('原图')
subplot(242),imshow(ntsc_img(:,:,1)),title('ntsc亮度');
subplot(243),imshow(ntsc_img(:,:,2)),title('ntsc色差');
subplot(244),imshow(ntsc_img(:,:,3)),title('ntsc饱和度');
%转换到HIS彩色空间
subplot(245),imshow(f),title('原图')
subplot(246),imshow(hsi_img(:,:,1)),title('hsi亮度');
subplot(247),imshow(hsi_img(:,:,2)),title('hsi色差');
subplot(248),imshow(hsi_img(:,:,3)),title('hsi饱和度');
![](https://img-blog.csdnimg.cn/20190519100019431.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
F=imread('你的图');
G=ice('image',f); %打开ice窗口对图像进行调整
%在窗口中执行以下操作:
%a)得到图像的补色
%b)拖动映射曲线,对图像显示效果进行修改
%c)在颜色通道中选中某一颜色,然后对映射曲线进行修改
f2=imread('你的图');
figure,imshow(f2);
%在CMYK彩色空间内打开图像
g2=ice('image',f2,'space','CMYK');
%f2的图像色彩偏红,拖动映射曲线,
%调整映射参数,使图像的色彩看起来比较正常。
![](https://img-blog.csdnimg.cn/20190519100119423.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100133938.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100147603.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100154348.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100235667.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100253463.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100321651.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100334917.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/2019051910035454.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100422406.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
fc=imread('你的图');
imshow(fc);
h=rgb2hsi(fc); %转换到HIS彩色空间
H=h(:,:,1); %色度分量
S=h(:,:,2); %饱和度分量
I=h(:,:,3); %亮度分量
w=fspecial('average',25); %25×25的方形平滑算子
I_filtered=imfilter(I,w,'replicate'); %对亮度分量进行平滑操作
H=cat(3,H,S,I_filtered); %将H、S、I三个分量重新组合起来
f=hsi2rgb(h); %转换到RGB彩色空间,hsi3rgb函数代码参见6.6节
f=min(f,1); %f的值控制在[0,1]之间
figure,imshow(f,[ ]);
fb=imread('你的图);
lapmask=[1 1 1;1 -8 1;1 1 1]; %拉普拉斯算子
%图像锐化后与原图像相减
fen=imsubtract(fb,imfilter(fb,lapmask,'replicate'));
figure,imshow(fen); %显示差值图像
![](https://img-blog.csdnimg.cn/20190519100513493.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100533225.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100546844.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
F=imread('你的图'); %f如图6-1所示
%直接计算彩色边缘VG,并得到对单独彩色平面的二维梯度求和形成的梯度PPG
[VG,A,PPG]=colorgrad(f); %代码请见第6.6节
imshow(VG,[ ]); %显示彩色梯度图像
figure,imshow(A,[ ]); %显示彩色梯度对应的角度图像
figure,imshow(PPG,[ ]); %显示分量梯度图像
g=VG-PPG; %计算两种梯度方法得到的梯度之差
figure,imshow(g,[ ]); %显示差值图像
![](https://img-blog.csdnimg.cn/20190519100622542.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100631821.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100642765.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/2019051910065279.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
f=imread('你的图'); %f如图6-4所示
mask=roipoly(f); %手工选定图中红色区域
%取得选定区域图像的红色分量
red=immultiply(mask,f(:,:,1));
figure,imshow(red,[ ]);
green=immultiply(mask,f(:,:,2));
%取得选定区域图像的绿色分量
figure,imshow(green,[ ]);
blue=immultiply(mask,f(:,:,3)); %取得选定区域图像的蓝色分量
figure,imshow(blue,[ ]);
g=cat(3,red,green,blue); %取得选定区域的RGB图像
figure,imshow(g);
[M,N,K]=size(g); %选定区域的大小
I=reshape(g,M*N,3); %对g中的像素进行重排,按列序拉成一行
idx=find(mask); %找到mask中的像素在重排后的图像g中位置
I=double(I(idx,1:3)); %转换到double类型
[C,m]=covmatrix(I); %计算协方差矩阵C主对角线上的元素,即方差
d=diag(C);
sd=sqrt(d)' %求得这些元素的平方根,即均方差
%用欧式距离对图像进行彩色分割,阈值为25
E25=colorseg('euclidean',f,25,m); %代码请见6.6节
figure,imshow(E25,[]);
%用马氏距离对图像进行彩色分割,阈值为25
M25=colorseg('mahalanobis' , f , 25 , m);
figure , imshow(M25 , [ ]);
![](https://img-blog.csdnimg.cn/20190519100729355.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100735640.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100802747.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100807268.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100825682.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20190519100830332.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/2019051910084992.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZpdmVyeWE=,size_16,color_FFFFFF,t_70)