MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB图像处理] 求助(急):全局阈值分割方法的matlab代码出错 (https://www.labfans.com/bbs/showthread.php?t=20701)

天天向上1221 2014-10-31 16:18

求助(急):全局阈值分割方法的matlab代码出错
 
我是一名MATLAB菜鸟,自己编了一个程序是关于全局阈值图像分割的。但是运行结果不对,自己找不到原因,望各位大神帮帮忙,看小弟的程序哪里错了!不甚感激!
代码如下:
f=imread('rice.png');
t=mean(f(:));
T=0;
t1=t;
countda=0;
countxiao=0;
da=0;
xiao=0;
[m,n]=size(f);
while~(abs(t1-T)<0.5)
for i=1:m
for j=1:n
if f(i,j)<t
xiao=xiao+f(i,j);
countxiao=countxiao+1;
else
da=da+f(i,j);
countda=countda+1;
end
end
end
t1=t;
T=0.5*((xiao/countxiao)+(da/countda));
t=T;
end
g = im2bw(f, T/255);
subplot(121);
imshow(f)
subplot(122);
imshow(g);
运行结果出现一张全白的图像!这是什么原因呢?


所有时间均为北京时间。现在的时间是 05:21

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.