this is an implementation for "how to use maximum likelihood in segmentation in image processing "
Afficher commentaires plus anciens
function ML()
image=zeros(256,256);
image(256/4:3*(256/4),256/4:3*(256/4))=200;
%object1=image(256/4:3*(256/4),256/4:3*(256/4));
image(10:60,10:60)=150;
%object2=image(10:60,10:60);
image=image/255;
imshow(image);
[r c]=size(image);
s_avg = sum(sum(image))/(r*c);
SNR=10;
n_sigma=s_avg/(10^(SNR/20));
n=n_sigma*randn(size(image));
image=image+n;
figure,hist(image);
figure,imshow(image);
%-----------PDF of the intensity of a background pixel---------
backgound=image(1:50,70:150);
backgound_pdf=normpdf(backgound,0,1);
%figure,plot(backgound,backgound_pdf);
%----------PDF of the intensity of an object pixel----------
object=image(256/4:3*(256/4),256/4:3*(256/4));
object_pdf=normpdf(object,200,1);
%figure,plot(object,object_pdf);
array=[0 0];
k=1;
for i=1:size(image,1)
for j=1:size(image,2)
%if p(y|black) < p(y|object) then x=object else x=BG
if 1/(sqrt(2*pi)*n_sigma)*exp(-1*((image(i,j)-0)^2/(2*n_sigma^2)) ) <= 1/(sqrt(2*pi)*1)*exp(-1*((image(i,j)-0)^2/(2*1) ))
array(k,:)=[i j];
k=k+1;
end
end
end
map=[];
plotting(array,image,map);
end
function plotting(FParray,fseg,map)
colormap(map)
imshow(fseg);
axis off
hold on
FPSize= size(FParray,1);
for i=1:FPSize
rectangle('Position',[FParray(i,1), FParray(i,2), 1, 1],'Curvature',
[1,1],'FaceColor','r','EdgeColor','r');
end
f=getframe(gca);
[X, map] = frame2im(f);
%imwrite(X,'FeaturePoints.png','png')
end
2 commentaires
Image Analyst
le 1 Août 2012
If you think this would be generally useful to lots of other people, then the File Exchange would be the more appropriate place to post this.
Walter Roberson
le 1 Août 2012
Please review the guide to tags and retag this; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags
Réponses (0)
Catégories
En savoir plus sur Images dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!