基础
彩色空间(又被称作彩色模型,可以相互转换):
RGB
CMY(青、深红、黄)、CMYK (青、深红、 黄、黑)
HSI(色调、饱和度、亮度)
伪彩色图像:对灰度值赋以彩色的处理
索引图像:有两个分量: 整数数据矩阵 X 和彩色映射矩阵 map
“抖动” :是印刷和出版行业常用的一种处理手段, 在由点组成的印刷页上给出色调变化的直观印象。以损失空间分辨率为代价, 从而达到更好的颜色分辨率;
函数表示
NTSC 彩色空间:用于模拟电视。优势是灰度信息和彩色数据是分离
yiq_image = rgb2ntsc(rgb_image),rgb_image = ntsc2rgb(yiq_image)
YCbCr 彩色空间:用于数字视频。 亮度信息用单独的分量 Y 来表示, 彩色信息是用两个色差分量 Cb 和 Cr 来存储的。
ycbcr_image = rgb2ycbcr(rgb_image),rgb_image = ycbcr2rgb(ycbcr_image)
HSV 彩色空间:用来从颜色轮或调色板中挑选颜色
hsv_image = rgb2hsv(rgb_image),rgb_image = hsv2rgb (hsv_image)
CMY 和 CMYK 彩色空间:颜料的原色。
cmy_image = imcompliment(rgb_image),rgb_image = imcompliment(cmy_image)
HSI 彩色空间:
hsi = rgb2hsi(rgb),rgb = hsi2rgb(hsi)
函数用法
[X, map] = gray2ind(gray_image, n)
gray_image = ind2gray(X,map)
[X, map] = rgb2ind(rgb_image, n, dither_option)
rgb_image = ind2rgb(X, map)
gray_image = rgb2gray (rgb_image)
X = grayslice(gray_image, n) 使用阈值对灰度图像进行阈值处理,产生索引图像
函数处理
f=imread('604.tif');
[x1,map1]=rgb2ind(f,8,'nodither');%不抖动
subplot(2,2,1),imshow(x1,map1)
[x2,map2]=rgb2ind(f,8,'dither');%抖动
subplot(2,2,2),imshow(x2,map2)
g=rgb2gray(f);%灰度图像
g1=dither(g);%抖动
subplot(2,2,3),imshow(g)
subplot(2,2,4),imshow(g1)
独立于设备的彩色空间
sRGB 彩色空间
CIE 和 sRGB 彩色空间之间的转换
makecform 和 applycform
基础知识
1) 颜色变换(也叫彩色映射)
f=imread('f.tif');
g=ice('image',f);
彩色图像的补色效果
伪彩色映射(只变换blue颜色分量)
色彩平衡
f2 = ice(' image' ,f1, ' space' , ' cmy' ); %使用cmy扫描过滤紫红色
基于直方图映射
根据CDF调整线条,结果显示,颜色更亮一些
2) 单独彩色平面的空间处理
3) 颜色向量的处理
Z = spline(x,y,xi) 三次样条内插
彩色图像的空间滤波
1、平滑(使用了滤波器)
%彩色平滑
f=imread('0622.tif');
subplot(2,2,1),imshow(f)
h=rgb2hsi(f);
H=h(:,:,1);
S=h(:,:,2);
I=h(:,:,3);
w=fspecial('average',25);%滤波器
H_filtered=imfilter(H,w,'replicate');%只对色调分量平滑
h=cat(3,H_filtered,S,I);%组合
f=hsi2rgb(h);%还原RGB
subplot(2,2,2),imshow(f),title('只对色调分量平滑')
S_filtered=imfilter(S,w,'replicate');%只对饱和度分量平滑
h=cat(3,H,S_filtered,I);%组合
f=hsi2rgb(h);%还原RGB
subplot(2,2,3),imshow(f),title('只对饱和度分量平滑')
I_filtered=imfilter(I,w,'replicate');%只对亮度分量平滑
h=cat(3,H,S,I_filtered);%组合
f=hsi2rgb(h);%还原RGB
subplot(2,2,4),imshow(f),title('只对亮度分量平滑')
2、锐化(使用拉普拉斯滤波器)
%彩色锐化
fb=imread('0625.tif');
subplot(1,2,1),imshow(fb),title('原图');
lapmask = [1 1 1;1 -8 1;1 1 1];%拉普拉斯滤波模板
fb=tofloat(fb);
fen=fb-imfilter(fb,lapmask,'replicate');
subplot(1,2,2),imshow(fen),title('锐化图');
图片有模糊的原图,锐化后,变清晰。
直接在 RGB 矢量空间中处理
1、使用梯度的彩色边缘检测
梯度计算:[VG,A,PPG] = colorgrad(f,T)
%彩色边缘检测
f=imread('0628.tif');
subplot(2,2,1),imshow(f),title('原图');
[VG,A,PPG] = colorgrad(f);
subplot(2,2,2),imshow(VG),title('VG');
subplot(2,2,3),imshow(A),title('A');
subplot(2,2,4),imshow(PPG),title('PPG');
2、分割图像
S = colorseg(method, f, T, parameters)
%RGB彩色图像分割
f=imread('0630.tif');
%手动截取感兴趣区域
mask=roipoly(f);
red=immultiply(mask,f(:,:,1));
green=immultiply(mask,f(:,:,2));
blue=immultiply(mask,f(:,:,3));
g=cat(3,red,green,blue);
figure,imshow(g);
[M,N,K]=size(g);
I=reshape(g,M*N,3);
idx=find(mask);
I=double(I(idx,1:3));
[C,m]=covmatrix(I);
d = diag(C);
sd = sqrt(d); %ROI 中彩色像素的颜色分量的标准差
E25 = colorseg('mahalanobis',f,25,m);
imshow(E25)