BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / matlab / #9064同步于 2012/5/22
Matlab机器人发帖

请问下面图像分割程序使用的是二维最大熵法?

rogerhan
2012/5/22镜像同步0 回复
上代码。。 —— %% 该 maximum_mean_2d.m 实现了对灰度图像应用二维最大熵算法实现分割. function [a] = maxmean(path) f=imread(path); %f=imread('lena.gif'); %转灰度 if isrgb(f)==1 a=rgb2gray(f); else a=f; end count=imhist(a); [m,n]=size(a); N=m*n; L=256; count=count/N;%每一个像素的分布概率 for i=1:L if count(i)~=0 st=i-1; break; end end st; for i=L:-1:1 if count(i)~=0 nd=i-1; break; end end nd; f=count(st+1:nd+1); %f=每个灰度的概率 size(f) E=[]; for Th=st:nd-1 %设定初始分割阈值为Th,迭代 av1=0; av2=0; Pth=sum(count(1:Th+1)); %第一类平均相对熵 for i=0:Th av1=av1-count(i+1)/Pth*log(count(i+1)/Pth+0.00001); end %第二类平均相对熵 for i=Th+1:L-1 av2=av2-count(i+1)/(1-Pth)*log(count(i+1)/(1-Pth)+0.00001); end E(Th-st+1)=av1+av2;%总信息熵 end position=find(E==(max(E))); th=st+position-1;%th即为使得总信息熵最大的阈值 % 以th二值化图像 for i=1:m for j=1:n if a(i,j)>th a(i,j)=255; else a(i,j)=0; end end end figure imshow(a);
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。