MATLAB聚类分割程序 图像聚类分割

MATLAB聚类分割程序
2008-04-08 20:33

clc,clear;
I=imread('egg4.bmp');
I1=I(:,:,1);
I2=I(:,:,2);
I3=I(:,:,3);
[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)-10)^2+(myI(j,i,2)-10)^2+(myI(j,i,3)-10)^2) ;
     d2(j,i)=sqrt((myI(j,i,1)-180)^2+(myI(j,i,2)-180)^2+(myI(j,i,3)-180)^2) ;
     if d1(j,i)>= d2(j,i)
       I0(j,i)=1;
    end
end
end
figure(1);
subplot(221);imshow(I); title('a 原始图像');
subplot(222);imshow(I1);title('b R分量');
subplot(223);imshow(I2);title('c G分量');
subplot(224);imshow(I3);title('d B分量');
figure(2);
subplot(131);imhist(I1); title(' R分量直方图');
subplot(132);imhist(I2); title(' G分量直方图');
subplot(133);imhist(I3); title(' B分量直方图');
figure(3);
subplot(221);imshow(I0);title('聚类分割后的图像');


RGB2=imadjust(RGB1,[0.6 0.8],[0 1] ,0.8);
figure(1);
subplot(221);imshow(RGB1);
subplot(222);imshow(RGB2);
I=rgb2gray(RGB2);
figure(2);
subplot(221);imshow(I);title('a 灰度图像');
subplot(222);imhist(I);title('b 直方图');
[m n]=size(I);
for i=1:m                     % 进行灰度变化
     for j=1:n
       if I(i,j)<=10
           I(i,j)=0;
        elseif I(i,j)<=80
            I(i,j)=(255-0)/(80-10)*(I(i,j)-10)+10;
        else
           I(i,j)=255;
        end
     end
end
                      % 显示变换后的结果
subplot(223);imshow(I);title('c 灰度变换');
I=im2double(I);
subplot(224);imhist(I);title('d 变换后直方图');

J=imadjust(I,[0.2 0.8],[0 1],0.8);
figure(3);
subplot(221);imshow(J);title('a 对比度调整');
I2=medfilt2(J,[5 5]);
subplot(222);imshow(I2);title('b 中值滤波');
I3=decorrstretch(I2);
subplot(223);imshow(I3);title('c 去相关拉伸');

[m n]=size(I2);
for i=1:m
for j=1:n
   if I2(i,j)>0.001&I2(i,j)<0.95 I2(i,j)=1;
   else I2(i,j)=0;   
   end   
end
end

subplot(224);imshow(I2);title('d 图像二值化');

评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值