MATLAB Central Fuzzy C Means Image Segmentation
Fuzzy CMeans Image Segmentation
Subject: Fuzzy CMeans Image Segmentation
From: Sekhar Barpanda
Date: 11 Jun, 2013 14:14:08
Message: 1 of 2
Reply to this message
Add author to My Watch List
View original format
Flag as spam
When I run the
following matlab code
for image segmentation
using fcm clustering
method, I got this error:
Error in I_fcm (line 46)
ccc1=sum(sum(u1.*u1.*IM))/sum(sum(u1.*u1));
The matlab code is like this: (take any blood smear image as 'blood.jpg')
% This program illustrates the Fuzzy cmeans segmentation of an image.
% This program converts an input image into two segments using Fuzzy kmeans
% algorithm. The output is stored as "fuzzysegmented.jpg" in the current directory.
% This program can be generalised to get "n" segments from an image
% by means of slightly modifying the given code.
clc;
clear all;
close all;
IM=imread('blood.jpg');
IM=double(IM);
figure(1)
imshow(uint8(IM))
[maxX,maxY]=size(IM);
IMM=cat(3,IM,IM);
%%%%%%%%%%%%%%%%
cc1=8;
cc2=250;
ttFcm=0;
while(ttFcm
> Error in I_fcm (line 46)
> ccc1=sum(sum(u1.*u1.*IM))/sum(sum(u1.*u1));
>
> The matlab code is like this: (take any blood smear image as 'blood.jpg')
>
> % This program illustrates the Fuzzy cmeans segmentation of an image.
> % This program converts an input image into two segments using Fuzzy kmeans
> % algorithm. The output is stored as "fuzzysegmented.jpg" in the current directory.
> % This program can be generalised to get "n" segments from an image
> % by means of slightly modifying the given code.
> clc;
> clear all;
> close all;
>
> IM=imread('blood.jpg');
> IM=double(IM);
> figure(1)
>
> imshow(uint8(IM))
> [maxX,maxY]=size(IM);
> IMM=cat(3,IM,IM);
> %%%%%%%%%%%%%%%%
> cc1=8;
> cc2=250;
>
> ttFcm=0;
> while(ttFcm ttFcm=ttFcm+1
>
> c1=repmat(cc1,maxX,maxY);
> c2=repmat(cc2,maxX,maxY);
> if ttFcm==1
> test1=c1; test2=c2;
> end
> c=cat(3,c1,c2);
>
> ree=repmat(0.000001,maxX,maxY);
> ree1=cat(3,ree,ree);
>
> distance=ree1c;
> distance=distance.*distance+ree1;
>
> daoShu=1./distance;
>
> daoShu2=daoShu(:,:,1)+daoShu(:,:,2);
> distance1=distance(:,:,1).*daoShu2;
> u1=1./distance1;
> distance2=distance(:,:,2).*daoShu2;
> u2=1./distance2;
>
> ccc1=sum(sum(u1.*u1.*IM))/sum(sum(u1.*u1)); %Error this line.
> ccc2=sum(sum(u2.*u2.*IM))/sum(sum(u2.*u2));
>
> tmpMatrix=[abs(cc1ccc1)/cc1,abs(cc2ccc2)/cc2];
> pp=cat(3,u1,u2);
>
> for i=1:maxX
> for j=1:maxY
> if max(pp(i,j,:))==u1(i,j)
> IX2(i,j)=1;
>
> else
> IX2(i,j)=2;
> end
> end
> end
> %%%%%%%%%%%%%%%
> if max(tmpMatrix) break;
> else
> cc1=ccc1;
> cc2=ccc2;
>
> end
>
> for i=1:maxX
> for j=1:maxY
> if IX2(i,j)==2
> IMMM(i,j)=254;
> else
> IMMM(i,j)=8;
> end
> end
> end
> %%%%%%%%%%%%%%%%%%
> figure(2);
>
> imshow(uint8(IMMM));
> tostore=uint8(IMMM);
> imwrite(tostore,'fuzzysegmented.jpg');
> end
>
> for i=1:maxX
> for j=1:maxY
> if IX2(i,j)==2
> IMMM(i,j)=200;
> else
> IMMM(i,j)=1;
> end
> end
> end
>
> %%%%%%%%%%%%%%%%%%
> IMMM=uint8(IMMM);
> figure(3);
> imshow(IMMM);
> disp('The final cluster centers are');
> ccc1
> ccc2
Subject: Fuzzy CMeans Image Segmentation
From: Sekhar Barpanda
Date: 11 Jun, 2013 14:14:08
Message: 1 of 2
Reply to this message
Add author to My Watch List
View original format
Flag as spam
When I run the
following matlab code
for image segmentation
using fcm clustering
method, I got this error:
Error in I_fcm (line 46)
ccc1=sum(sum(u1.*u1.*IM))/sum(sum(u1.*u1));
The matlab code is like this: (take any blood smear image as 'blood.jpg')
% This program illustrates the Fuzzy cmeans segmentation of an image.
% This program converts an input image into two segments using Fuzzy kmeans
% algorithm. The output is stored as "fuzzysegmented.jpg" in the current directory.
% This program can be generalised to get "n" segments from an image
% by means of slightly modifying the given code.
clc;
clear all;
close all;
IM=imread('blood.jpg');
IM=double(IM);
figure(1)
imshow(uint8(IM))
[maxX,maxY]=size(IM);
IMM=cat(3,IM,IM);
%%%%%%%%%%%%%%%%
cc1=8;
cc2=250;
ttFcm=0;
while(ttFcm
> Error in I_fcm (line 46)
> ccc1=sum(sum(u1.*u1.*IM))/sum(sum(u1.*u1));
>
> The matlab code is like this: (take any blood smear image as 'blood.jpg')
>
> % This program illustrates the Fuzzy cmeans segmentation of an image.
> % This program converts an input image into two segments using Fuzzy kmeans
> % algorithm. The output is stored as "fuzzysegmented.jpg" in the current directory.
> % This program can be generalised to get "n" segments from an image
> % by means of slightly modifying the given code.
> clc;
> clear all;
> close all;
>
> IM=imread('blood.jpg');
> IM=double(IM);
> figure(1)
>
> imshow(uint8(IM))
> [maxX,maxY]=size(IM);
> IMM=cat(3,IM,IM);
> %%%%%%%%%%%%%%%%
> cc1=8;
> cc2=250;
>
> ttFcm=0;
> while(ttFcm ttFcm=ttFcm+1
>
> c1=repmat(cc1,maxX,maxY);
> c2=repmat(cc2,maxX,maxY);
> if ttFcm==1
> test1=c1; test2=c2;
> end
> c=cat(3,c1,c2);
>
> ree=repmat(0.000001,maxX,maxY);
> ree1=cat(3,ree,ree);
>
> distance=ree1c;
> distance=distance.*distance+ree1;
>
> daoShu=1./distance;
>
> daoShu2=daoShu(:,:,1)+daoShu(:,:,2);
> distance1=distance(:,:,1).*daoShu2;
> u1=1./distance1;
> distance2=distance(:,:,2).*daoShu2;
> u2=1./distance2;
>
> ccc1=sum(sum(u1.*u1.*IM))/sum(sum(u1.*u1)); %Error this line.
> ccc2=sum(sum(u2.*u2.*IM))/sum(sum(u2.*u2));
>
> tmpMatrix=[abs(cc1ccc1)/cc1,abs(cc2ccc2)/cc2];
> pp=cat(3,u1,u2);
>
> for i=1:maxX
> for j=1:maxY
> if max(pp(i,j,:))==u1(i,j)
> IX2(i,j)=1;
>
> else
> IX2(i,j)=2;
> end
> end
> end
> %%%%%%%%%%%%%%%
> if max(tmpMatrix) break;
> else
> cc1=ccc1;
> cc2=ccc2;
>
> end
>
> for i=1:maxX
> for j=1:maxY
> if IX2(i,j)==2
> IMMM(i,j)=254;
> else
> IMMM(i,j)=8;
> end
> end
> end
> %%%%%%%%%%%%%%%%%%
> figure(2);
>
> imshow(uint8(IMMM));
> tostore=uint8(IMMM);
> imwrite(tostore,'fuzzysegmented.jpg');
> end
>
> for i=1:maxX
> for j=1:maxY
> if IX2(i,j)==2
> IMMM(i,j)=200;
> else
> IMMM(i,j)=1;
> end
> end
> end
>
> %%%%%%%%%%%%%%%%%%
> IMMM=uint8(IMMM);
> figure(3);
> imshow(IMMM);
> disp('The final cluster centers are');
> ccc1
> ccc2