Rank: 2989 based on 13 downloads (last 30 days) and 1 file submitted
photo

James Goodwin

E-mail

Personal Profile:
Professional Interests:

 

Watch this Author's files

 

Files Posted by James
Updated   File Tags Downloads
(last 30 days)
Comments Rating
22 Jun 2004 Flood Fill Flood Fill code for matrix. Author: James Goodwin code for matrix, flood, data exploration, flood fill, graphics, graphical data 13 2
  • 2.0
2.0 | 2 ratings
Comments and Ratings on James' Files View all
Updated File Comment by Comments Rating
17 Mar 2010 Flood Fill Flood Fill code for matrix. Author: James Goodwin Beugeling, Trevor

Although this code is a good example of recursion, it has a bug which can give incorrect flood-fill results.

The termination conditions need to be changed to:

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

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

Also note that these conditions mean that the border of the matrix will not be evaluated. If you wish to fill right to the edges of the matrix, the conditions need to be adjusted accordingly.

22 Feb 2007 Flood Fill Flood Fill code for matrix. Author: James Goodwin Banerjee, Jyotirmoy

Available stack space may not be enough as it applies recursion
Increase the recursion limit using
  N = 200;
  set(0,'RecursionLimit',N);
note -> if you increase N to a very large value then you may get segmentation fault

you can instead use imfill cmd in matlab

% Add this to make it 8 connected
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);

    flood_fill(xc,yc,x+1,y+1,new,old,width,height);

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

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

    flood_fill(xc,yc,x-1,y-1,new,old,width,height);

end

Top Tags Applied by James
code for matrix, data exploration, flood, flood fill, graphical data
Files Tagged by James
Updated   File Tags Downloads
(last 30 days)
Comments Rating
22 Jun 2004 Flood Fill Flood Fill code for matrix. Author: James Goodwin code for matrix, flood, data exploration, flood fill, graphics, graphical data 13 2
  • 2.0
2.0 | 2 ratings

Contact us at files@mathworks.com