资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
% 二维最大熵阈值分割法 % filename,pathname=uigetfile; img=imread(strcat(pathname,filename); figure(1); subplot(221); imshow(img); subplot(222); imhist(img(:,1); subplot(223); imhist(img(:,2); subplot(224); imhist(img(:,3); % 这个地方出现了一个问题就是为什么 MidValue=img(i,j-1,1) +img(i-1,j,1)+img(i % +1,j,1)+img(i,j+1,1)最大值为 256,难道是默认的一个 BYTE 类型 吗? p=zeros(256,256); m,n,k=size(img); for i=2:m-1for j=2:n-1MidValue=img(i,j-1,1)/4+img(i-1,j,1)/4+img(i+1,j,1)/4+img(i,j+1,1)/4;MidValue=round(MidValue);p(img(i,j,1)+1,MidValue+1)=p(img(i,j,1)+1,MidValue+1)+1;end; end; %图像的四个角,只有 2 领域的点儿 p(img(1,1,1)+1,round(img(1,2,1)/2+img(2,1,1)/2)+1)=p(img(1,1,1)+1,round(img(1,2,1)/2+img( 2,1,1)/2)+1)+1; p(img(1,n,1)+1,round(img(1,n-1,1)/2+img(2,n,1)/2)+1)=p(img(1,n,1)+1,round(img(1,n- 1,1)/2+img(2,n,1)/2)+1)+1; p(img(m,1,1)+1,round(img(m-1,1,1)/2+img(m,2,1)/2)+1)=p(img(m,1,1)+1,round(img(m- 1,1,1)/2+img(m,2,1)/2)+1)+1; p(img(m,n,1)+1,round(img(m,n-1,1)/2+img(m-1,n,1)/2)+1)=p(img(m,n,1)+1,round(img(m,n- 1,1)/2+img(m-1,n,1)/2)+1)+1; %图像周围的一圈,只有 3 领域的点儿 for j=2:n-1MidValue=img(1,j-1,1)/3+img(1,j+1,1)/3+img(2,j,1)/3;MidValue=round(MidValue);p(img(1,j,1)+1,MidValue+1)= p(img(1,j,1)+1,MidValue+1,1)+1; end; for j=2:n-1MidValue=img(m,j-1,1)/3+img(m,j+1,1)/3+img(m-1,j,1)/3;MidValue=round(MidValue);p(img(m,j,1)+1,MidValue+1)= p(img(m,j,1)+1,MidValue+1)+1; end; for i=2:m-1MidValue=img(i-1,1,1)/3+img(i+1,1,1)/3+img(i,2,1)/3;MidValue=round(MidValue);p(img(i,1,1)+1,MidValue+1)= p(img(i,1,1)+1,MidValue+1)+1; end; for i=2:m-1MidValue=img(i-1,n,1)/3+img(i+1,n,1)/3+img(i,n-1,1)/3;MidValue=round(MidValue);p(img(i,n,1)+1,MidValue+1)= p(img(i,n,1)+1,MidValue+1)+1; end; p=p/(m*n);% 忽略噪音的影响 % pa=0; ha=0; hn=0; s=10; t=10; Qst=0; temp_t=10; temp_s=10; for i=1:256for j=1:256if(p(i,j)0)hn=hn+log2(p(i,j)*p(i,j)*(-1);end;end; end;for t=10:256for s=10:256ha=0;pa=0;for i=1:tfor j=1:spa=pa+p(i,j);end;end;for i=1:tfor j=1:sif(p(i,j)0)ha=ha+log2(p(i,j)*p(i,j)*(-1);end;end;end;if(pa0temp_t=t;temp_s=s;end; end;end; end;for i=1:mfor j=1:nif(img(i,j,1)temp_s)img(i,j,1)=255;img(i,j,2)=255;img(i,j,3)=255;elseimg(i,j,1)=0;img(i,j,2)=0;img(i,j,3)=0;end;end; end; figure(2); imshow(img);
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号