1、);rgb1=im2double(rgb);r=rgb1(:, :,1);g=rgb1(:,2);b=rgb1(:,:,3);I=(r+g+b)/3;tmp1=min(min(r,g),b);tmp2=r+g+b;tmp2(tmp2=0)=eps;S=1-3.*tmp1./tmp2;tmp1=0.5*(r-g)+(r-b);tmp2=sqrt(r-g).2+(r-b).*(g-b);theta=acos(tmp1./(tmp2+eps);H=theta;H(bg)=2*pi-H(bg);H=H/(2*pi);H(S=0)=0;例9.3I=imread(i_peppers_gray.bmpGS8
2、=grayslice(I,8);GS64=grayslice(I,64);subplot(1,3,1),imshow(I),titlesubplot(1,3,2),subimage(GSB,hot(8),titlesubplot(1,3,3),subimage(GS64,hot(64),title例6.4i_boat.bmpI=double(I);m,n=size(I);L=256;for i=1:mif j=1:nif I(i,j)L/4R(i,j)=0;G(i,j)=4*I(i,j);B(i,j)=L;else if I(i,j)g)=2*pi-H1(bH1(S=0)=0;I=histeq
3、(I1);hsi=cat(3,H1,S,I);H=hsi(:,1)*2*pi;S=hsi(:I=hsi(:R=zeros(size(hsi,1),size(hsi,2);G=zeros(size(hsi,1),size(hsi,2);B=zeros(size(hsi,1),size(hsi,2);ind=find(H=0)&(H=4*pi/3)&2*pi);H(ind)=H(ind)-pi*4/3;G(ind)=I(ind).*(1.0-S(ind);B(ind=I(ind.*(1.0+S(ind).8cos(H(ind).(H(ind)./cos(pi/3.0-H(ind);R(ind)=1
4、.0-(G(ind)+B(ind);RGB=cat(3,R,G,B);例9.6flower608.jpgfR=rgb(;fG=rgb(:fB=rgb(;w=fspecial(averagefR_filtered=imfilter(fR,w);fG-filtered=imfilter(fG,w);fB-filtered=imfilter(fB,w);rgb_filtered=cat(3,fR_filtered,fG_filtered,fB_filtered);例9.8fR=rgb(:fB=rgb(:labMatrix=1 1 1;1-8 1; 1 1 1;fR_tmp=imfilter(fR,l
5、apMatrix,replicatefG_tmp=imfilter(fG,lapMatrix,fB_tmp=imfilter(fB,lapMatrix,rgb_tmp=cat(3,fR_tmp,fB_tmp);rgb_sharped=imsubtract(rgb_tmp);例9.10 S1=(S0.3*(max(max(S(:);F=S1.*H;例9.11r1=r(129:256,86:170);r1_u=mean(mean(r1(:);m,n=size(r1);sd1=0.0;m;sd1=sd1+(r1(i,j)-r1_u)*(r1(i,j)-r1_u);r1_d=sqrt(sd1/(m*n
6、);r2_d=zeros(size(rgb1,1),size(rgb1,2);ind=find(rr1_u-1.25*r1_d)&(rr1_u+1.25*r1_d);r2(ind)=1;例9.12 rgb=imread(lena.jpgsob=fspecial(sobelRx=imfilter(double(rgb(:,1),sob,Ry=imfilter(double(rgb(:,1),sob,Gx=imfilter(double(rgb(:,2),sob,Gy=imfilter(double(rgb(:,2),sobBx=imfliter(double(rgb(:,3),sob,By=im
7、fliter(double(rgb(:,3),sobr_gradiant=mat2gray(max(Rx,Ry);g_gradiant=mat2gray(max(Gx,Gy);b_grandiant=mat2gray(max(Bx,By);rgb_grandiant=rgb2gray(cat(3,r_grantiant,g_grantiant,b_grandiant);gxx=Rx.2+Gx.2+Bx.2;gyy=Ry.2+By.2;+Gx.2;theta=0.5*(atan(2*gxy./(gxx-gyy+eps);G1=0.5*(gxx+gyy)+(gxx-gyy).*cos(2*theta)+2*gxy.*sin(2*theta);theta=0.5*(gxx+gyy)+(gxx-gyy).*cos(2*theta)+2*gxy.*sin(2*theta);G2=0.5*(gxx+gyy)+(gxx-gyy).*cos(2*theta)+2*gxy.*sin(2*theta);G1=G1.0.5;G2=G2.0.5;rgb_vectorgradiant=mat2gray(max(G1,G2);diff=abs(rgb_vectorgradiant-rgb_gradiant);