PDA

查看完整版本 : [求助]关于flood_fill算法的疑问


bohr1982
2008-12-17, 11:33
我下了一个flood_fill(种子染色算法)做填充。可是区域大点matlab就跳出来了。好像是堆栈溢出了。咋办呢?

function flood_fill(xc,yc,x,y,new,old,width,height)
% flood fills area of matrix
% (xc,yc) = start point of flood fill
% (x,y) = current test location
% new = new value to be filled
% old = old value to replace

global fill;
global call;

call = call + 1;

if (x<2 || x>=width)
x = xc;
end

if (y<2 || y>=height)
y = yc;
end

if (fill(y,x) == old)
fill(y,x) = new;
flood_fill(xc,yc,x+1,y,new,old,width,height);
flood_fill(xc,yc,x,y+1,new,old,width,height);
flood_fill(xc,yc,x-1,y,new,old,width,height);
flood_fill(xc,yc,x,y-1,new,old,width,height);
end


:ft: