📄 julei2.m
字号:
%rgb颜色聚类法分割
I = imread('fang.bmp');
r=I(:,:,1);figure,imhist(r);figure,imshow(r);
g=I(:,:,2);figure,imhist(g);figure,imshow(g);
b=I(:,:,3);figure,imhist(b);figure,imshow(b);
%各颜色分量显示
[y,x,z]=size(I) ;
d1=zeros(y,x);
d2=d1;
myi=double(I);
I0=zeros(y,x);
for i=1:x
for j=1:y
d1(j,i)=sqrt((myi(j,i,1)-130)^2+(myi(j,i,2)-125)^2+(myi(j,i,3)-125)^2);
d2(j,i)=sqrt((myi(j,i,1)-150)^2+(myi(j,i,2)-190)^2+(myi(j,i,3)-150)^2);
if(d1(j,i)>=d2(j,i))
I0(j,i)=1;
end
end
end
J=I0;
se=strel('rectangle',[10 5]);
IM=imclose(J,se);
%figure(1),subplot(121),imshow(I0);subplot(122),imshow(~I0);
%figure(2),subplot(131);imhist(r);title('R');
% subplot(132);imhist(g);title('G');
% subplot(133);imhist(b);title('B');
%figure(3),subplot(131);imshow(r);title('R颜色分量图像');
% subplot(132);imshow(g);title('G颜色分量图像');
% subplot(133);imshow(b);title('B颜色分量图像');
%figure(4),imshow(~I0);
BWoutline=bwperim(~I0);
A=r;
A(BWoutline)=255;
%figure, imshow(A), title('r效果图');
BWoutline=bwperim(~I0);
B=g;
B(BWoutline)=255;
%figure, imshow(A), title('g效果图');
BWoutline=bwperim(~I0);
C=b;
C(BWoutline)=255;
%figure, imshow(C), title('b效果图');
k=cat(3,A,B,C);
figure,imshow(k);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -