Sei sulla pagina 1di 6

FuzzyCMeansImage

Segmentation
Subject:FuzzyCMeansImageSegmentation
From:SekharBarpanda
Date:11Jun,201314:14:08
Message:1of2
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam
WhenIrunthefollowingmatlabcodeforimagesegmentationusingfcm
clusteringmethod,Igotthiserror:
ErrorinI_fcm(line46)
ccc1=sum(sum(u1.*u1.*IM))/sum(sum(u1.*u1))
Thematlabcodeislikethis:(takeanybloodsmearimageas
'blood.jpg')
%ThisprogramillustratestheFuzzycmeanssegmentationofan
image.
%Thisprogramconvertsaninputimageintotwosegmentsusing
Fuzzykmeans
%algorithm.Theoutputisstoredas"fuzzysegmented.jpg"inthe
currentdirectory.
%Thisprogramcanbegeneralisedtoget"n"segmentsfromanimage
%bymeansofslightlymodifyingthegivencode.
clc
clearall
closeall
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<15)
ttFcm=ttFcm+1

c1=repmat(cc1,maxX,maxY)
c2=repmat(cc2,maxX,maxY)
ifttFcm==1
test1=c1test2=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))%Errorthisline.
ccc2=sum(sum(u2.*u2.*IM))/sum(sum(u2.*u2))

tmpMatrix=[abs(cc1ccc1)/cc1,abs(cc2ccc2)/cc2]
pp=cat(3,u1,u2)

fori=1:maxX
forj=1:maxY
ifmax(pp(i,j,:))==u1(i,j)
IX2(i,j)=1

else
IX2(i,j)=2
end
end
end
%%%%%%%%%%%%%%%
ifmax(tmpMatrix)<0.0001
break
else

cc1=ccc1
cc2=ccc2

end
fori=1:maxX
forj=1:maxY
ifIX2(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
fori=1:maxX
forj=1:maxY
ifIX2(i,j)==2
IMMM(i,j)=200
else
IMMM(i,j)=1
end
end
end
%%%%%%%%%%%%%%%%%%
IMMM=uint8(IMMM)
figure(3)
imshow(IMMM)
disp('Thefinalclustercentersare')
ccc1
ccc2

Subject:FuzzyCMeansImageSegmentation
From:allgroup
Date:10Apr,201411:58:07

Message:2of2
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam
hi
YourImageMustBegrayscale
ifyourimagewasRGBthisErrorGenerate

"SekharBarpanda"<109ee0255@nitrkl.ac.in>wroteinmessage
<kp7bbg$lab$1@newscl01ah.mathworks.com>...
>WhenIrunthefollowingmatlabcodeforimagesegmentationusing
fcmclusteringmethod,Igotthiserror:
>
>ErrorinI_fcm(line46)
>ccc1=sum(sum(u1.*u1.*IM))/sum(sum(u1.*u1))
>
>Thematlabcodeislikethis:(takeanybloodsmearimageas
'blood.jpg')
>
>%ThisprogramillustratestheFuzzycmeanssegmentationofan
image.
>%Thisprogramconvertsaninputimageintotwosegmentsusing
Fuzzykmeans
>%algorithm.Theoutputisstoredas"fuzzysegmented.jpg"inthe
currentdirectory.
>%Thisprogramcanbegeneralisedtoget"n"segmentsfroman
image
>%bymeansofslightlymodifyingthegivencode.
>clc
>clearall
>closeall
>
>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<15)
>ttFcm=ttFcm+1
>
>c1=repmat(cc1,maxX,maxY)
>c2=repmat(cc2,maxX,maxY)
>ifttFcm==1
>test1=c1test2=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))%Errorthisline.
>ccc2=sum(sum(u2.*u2.*IM))/sum(sum(u2.*u2))
>
>tmpMatrix=[abs(cc1ccc1)/cc1,abs(cc2ccc2)/cc2]
>pp=cat(3,u1,u2)
>
>fori=1:maxX
>forj=1:maxY
>ifmax(pp(i,j,:))==u1(i,j)
>IX2(i,j)=1
>
>else
>IX2(i,j)=2
>end
>end
>end
>%%%%%%%%%%%%%%%
>ifmax(tmpMatrix)<0.0001
>break
>else
>cc1=ccc1

>cc2=ccc2
>
>end
>
>fori=1:maxX
>forj=1:maxY
>ifIX2(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
>
>fori=1:maxX
>forj=1:maxY
>ifIX2(i,j)==2
>IMMM(i,j)=200
>else
>IMMM(i,j)=1
>end
>end
>end
>
>%%%%%%%%%%%%%%%%%%
>IMMM=uint8(IMMM)
>figure(3)
>imshow(IMMM)
>disp('Thefinalclustercentersare')
>ccc1
>ccc2

Potrebbero piacerti anche