当前位置:
文档之家› 彩色图像处理MATLAB函数简介
彩色图像处理MATLAB函数简介
figure(2) imshow(fr) title('red component') figure(3) imshow(fg) title('green component') figure(4) imshow(fb) title('blue component')
编程应用
2 颜色空间转换矩阵的创建与应用
makecform Create a color transformation structure Syntax C = makecform(type) creates the color transformation structure C that defines the color space conversion specified by type. To perform the transformation, pass the color transformation structure as an argument to the applycform function.
‘type’ 参数
‘type’ 参数
颜色空间
应用
rgb = imread('peppers.png'); cform = makecform('srgb2lab'); lab = applycform(rgb,cform);
3 颜色空间转换函数举例
rgb2hsv Convert RGB colormap to HSV colormap cmap = rgb2hsv(M) Description converts an RGB colormap M to an HSV colormap cmap. Both colormaps are m-by-3 matrices. The elements of both colormaps are in the range 0 to 1. The columns of the input matrix M represent intensities of red, green, and blue, respectively. The columns of the output matrix cmap represent hue, saturation, and value, respectively.
1 函数简介
ind2gray ind2rgb
mat2gray rgb2gray rgb2ind
- Convert indexed image to intensity image. - Convert indexed image to RGB image (MATLAB Toolbox). - Convert matrix to intensity image. - Convert RGB image or colormap to grayscale. - Convert RGB image to indexed image.
彩色图像处理函数简介
1 函数简介
applycform
- Apply device-independent color space transformation. hsv2rgb - Convert HSV values to RGB color space (MATLAB Toolbox). iccread - Read ICC color profile. lab2double - Convert Lab color values to double. lab2uint16 - Convert Lab color values to uint16. lab2uint8 - Convert Lab color values to uint8. makecform - Create device-independent color space transform structure. ntsc2rgb - Convert NTSC values to RGB color space.
1 函数简介
dither gray2ind grayslice
- Convert image using dithering. - Convert intensity image to indexed image. - Create indexed image from intensity image by thresholding. graythresh - Compute global image threshold using Otsu's method. im2bw - Convert image to binary image by thresholding. im2double - Convert image array to double precision.
4 颜色空间转换函数的编写
function hsi=rgb2hsi(rgb) %将RGB图像转换成HSI图像 rgb=im2double(rgb); r=rgb(:,:,1); g=rgb(:,:,2); b=rgb(:,:,3);
4 颜色空间转换函数的编写
%将RGB转换成HSV hc=rgb2hsv(fc); %提取HSV分量 h=hc(:,:,1); s=hc(:,:,2); v=hc(:,:,3); figure(5) imshow(hsv2rgb(hc)) title('hsv image')
编程应用
%显示HSV分量图像 figure(6) imshow(h) title('hue component') figure(7) imshow(s) title('saturation component') figure(8) imshow(v) title('value component')
编程应用
fc=imread('peppers.png'); %提取RGB分量 fr=fc(:,:,1); fg=fc(:,:,2); fb=fc(:,:,3); figure(1) imshow(f) title('rgb image')
编程应用
编程应用
%仅对HSV图像的v分量滤波 v_filtered=imfilter(v,w,'replicate'); h=cat(3,h,s,v_filtered); f_filtered=hsv2rgb(h); f_filtered=min(f_filtered,1); figure(10) imshow(f_filtered) title('filtered hsv image')
4 颜色空间转换函数的编写
%分区转换 %RB区间(0-120) idx=find((0<=H)&(H<2*pi/3)); B(idx)=I(idx).*(1-S(idx)); R(idx)=I(idx).*(1+S(idx).*cos(H(idx))./ cos(pi/3-H(idx))); G(idx)=3*I(idx)-(R(idx)+B(idx));
4 颜色空间转换函数的编写
%GB区间(120-240) idx=find((2*pi/3<=H)&(H<4*pi/3)); R(idx)=I(idx).*(1-S(idx)); G(idx)=I(idx).*(1+S(idx).*cos(H(idx)2*pi/3)./cos(pi-H(idx))); B(idx)=3*I(idx)-(R(idx)+G(idx));
编程应用
%产生均值滤波器 w=fspecial('average',5); %对RGB图像滤波 rgb_filtered=imfilter(fc,w,'replicate'); figure(9) imshow(rgb_filtered) title('filtered RGB image')
%将RGB转换HSI num=0.5*((r-g)+(r-b)); den=sqrt((r-g).^2+(r-b).*(g-b)); theta=acos(num./(den+eps)); H=theta; h(b>g)=2*pi-H(b>g); H=H/(2*pi); num=min(min(r,g),b); den=r+g+b; den(den==0)=eps; S=1-3.*num./den; I=(r+g+b)/3; hsi=cat(3,H,S,I);
编程应用
%对h,s,v同时滤波 h_filtered=imfilter(h,w,'replicate'); s_filtered=imfilter(s,w,'replicate'); v_filtered=imfilter(v,w,'replicate'); h=cat(3,h_filtered,s_filtered,v_filtered); f_filtered=hsv2rgb(h); f_filtered=min(f_filtered,1); figure(11) imshow(f_filtered)