Then you can probably use something like this:
. def boxesArea(m, foreground=1, background=0):
. maxr = len(m)
. maxc = len(m[0])
. newCol = 2
. oldCol = foreground
. for r,row in enumerate(m):
. for c,e in enumerate(row):
. if e == oldCol:
.
def floodFill4(m, r, c, newCol, oldCol):
stack = [ (r, c) ]
while stack:
r, c = stack.pop()
if c >=0 and c < maxc and r >=0 and r< maxr and m[r][c]==oldCol:
m[r][c] = newCol
stack += [ (r+1, c), (r-1, c), (r, c+1), (r, c-1) ]
--
http://mail.python.org/mailman/listinfo/pyth
Bearophile,I have written the floodfill in python with stack. But i
think I am making something wrong I dont get what i need.Need your
opinion.the code follows
def connected(m, foreground=1, background=0):
def floodFill4(m, r,c, newCol, oldCol):
if newCol == oldCol:
print "
In my first post you can find two URLs with better flood filling
algorithms. You can also modify the easy recursive function, using a
list-based stack intead of recursive calls.
Bye,
Bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Just was wondering how to integrate the floodfill with the stack.I
guess it will get rid of recursion problem. You mean read all the
elements of the array to a stack and then push and pop based on
conditions?
--
http://mail.python.org/mailman/listinfo/python-list
bearphile, Is there a way I could do the floodfill rather iteratively
than recursive. It somehow breaks although I made some optimisations to
the code.
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED]:
> hi Bearphile! That really gives me an idea.Thanks much for that. Yes
as
> you said the algorithm reaches a maximium recursion depth for larger
> sets i tried.
You can improve the little flood filling function, avoiding the "bad"
Python recursivity.
> Do you see where I am he
On 24 Apr 2005 09:44:49 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>Richter,yes what I am looking for is for cluster with rectangular
>bounding boxes as you explained in the first figure.
>
Sorry, not your fault, but I'm still not clear on diagonal
connection/separation.
E.g., (removin
hi Bearphile! That really gives me an idea.Thanks much for that. Yes as
you said the algorithm reaches a maximium recursion depth for larger
sets i tried.I still have a question. if
m = [[0,0,0,0],[0,1,1,0,0],[0,0,1,0,0],[0,0,0,0]]
all it does is count the number of 1's and return us the number in
Richter,yes what I am looking for is for cluster with rectangular
bounding boxes as you explained in the first figure.
--
http://mail.python.org/mailman/listinfo/python-list
On 23 Apr 2005 13:17:55 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>If I have
>
>ex: x = [[1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0],
> [1,1,1,0,1,1,0,0,0,0,0,1,1,1,1,0,0,0],
> [1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,0,0,0],
> [0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0]]
>what I wan
I hope this is what you need, sometimes understanding the question is
one of the hardest parts :-)
If you can use a graph data structure, you can create a graph, and then
you can find the lenght of all its connected components (indentations
reduced to 2 spaces):
. def mat2graph(g, m, good=None, w
If I have
ex: x = [[1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0],
[1,1,1,0,1,1,0,0,0,0,0,1,1,1,1,0,0,0],
[1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,0,0,0],
[0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0]]
what I want is a boundingbox over the region where we find clusters of
1's.So for instance in th
13 matches
Mail list logo