this is an implementation for "how to use maximum likelihood in segmentation in image processing "
이전 댓글 표시
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
Image Analyst
2012년 8월 1일
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
2012년 8월 1일
Please review the guide to tags and retag this; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!