• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

MATLAB图像分析程序

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
1.迭代法
I=imread('rice.png');
ZMax=max(max(I));
ZMin=min(min(I));
TK=(ZMax+ZMin)/2;
bCal=1;
iSize=size(I);
while(bCal)
iForeground=0;
iBackground=0;
ForegroundSum=0;
BackgroundSum=0;
for i=1:iSize(1)
for j=1:iSize(2)
tmp=I(i,j);
if(tmp>=TK)
iForeground=iForeground+1;
ForegroundSum=ForegroundSum+double(tmp);
else
iBackground=iBackground+1;
BackgroundSum=BackgroundSum+double(tmp);
end
end
end
ZO=ForegroundSum/iForeground;
ZB=BackgroundSum/iBackground;
TKTmp=uint8((ZO+ZB)/2);
if(TKTmp==TK)
bCal=0;
else
TK=TKTmp;
end
end
disp(strcat('迭代后的域值:',num2str(TK)));
newI=im2bw(I,double(TK)/255);
subplot(121),imshow(I)
subplot(122),imshow(newI)
运行结果:迭代后的域值:131
2.大津法
%大津法
I=imread('coins.png');
subplot(131),imshow(I);
title('原始图像')
level=graythresh(I);
BW=im2bw(I,level);
subplot(132),imshow(BW)
title('graythresh计算阈值')
disp(strcat('graythresh计算灰度阈值:',num2str(uint8(level*255))))
iMax=max(max(I));
iMin=min(min(I));
T=double(iMin:iMax);
iSize=size(I);
muxSize=iSize(1)*iSize(2);
for i=1:length(T)
TK=T(1,i);
iForeground=0;
iBzckground=0;
ForegroundSum=0;
BzckgroundSum=0;
for j=1:iSize(1)
for k=1:iSize(2)
tmpData=I(j,k);
if(tmpData>=TK)
iForeground=iForeground+1;
ForegroundSum=ForegroundSum+double(tmpData);
else
iBackground=iBackground+1;
BackgroundSum=BackgroundSum+double(tmpData);
end
end
end
w0=iForeground/muxSize;
w1=iBackground/muxSize;
u0=ForegroundSum/iForeground;
u1=BackgroundSum/iBackground;
T(2,i)=w0*w1*(u0-u1)*(u0-u1);
end
oMax=max(T(2,:);
idx=find(T(2,:)>=oMax);
T=uint8(T(1,idx));
disp(strcat('简化大津法计算灰度阈值:',num2str(T)))
BW=im2bw(I,double(T)/255);
subplot(133),imshow(BW)
title('简化大津法计算灰度阈值')运行结果:
graythresh计算灰度阈值:126

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
delphi 10.3 FastReport 多设备跨平台 打印之解决方法发布时间:2022-07-18
下一篇:
Delphi格式化输出函数(1):Format发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap