python - error while printing connected components in a gray scale image -


import sys pil import image import imagefilter import numpy import pil.image numpy import array stack=[] z=0     def main():     connected(drblur)//image in list of lists [[],[],[],[],....[]] def connected(rdrblur):     table={}     #print len(rdrblur),len(rdrblur[0])     item in rdrblur:         item.insert(0,0)         item.append(0)     #print len(rdrblur),len(rdrblur[0])     rdrblur.insert(0,[0]*len(rdrblur[0]))     rdrblur.append([0]*len(rdrblur[0]))     copy=[]     item in rdrblur:         copy.append(item[:])     global z     count=0      in range(1,len(rdrblur)-1):         j in range(1,len(rdrblur[0])-1):             if (i,j) not in stack:                 if rdrblur[i][j]==copy[i][j]:                     z=0                     times=dfs(i,j,str(count),rdrblur,copy)                     table[count]=(rdrblur[i][j],times+1)                     count=count+1     stack1=[]     #print table     item in table.values():         stack1.append(item)      #print stack1     table2={}     item in stack1:         if item[0] not in table2.keys():             table2[item[0]]={'coherent':0,'incoherent':0}     item in stack1:         if item[1]>900:             table2[item[0]]['coherent']=table2[item[0]]['coherent']+item[1]          else:             table2[item[0]]['incoherent']=table2[item[0]]['incoherent']+item[1]     print tablel2 def dfs(x,y,co,b,c):     dx = [-1,-1,-1,0,0,1,1,1]     dy = [-1,0,1,-1,1,-1,0,1]     global z     #print x,y,co     c[x][y]=co     stack.append((x,y))     #print dx ,dy     in range(8):         nx = x+(dx[i])         ny = y+(dy[i])         #print nx,ny         if b[x][y] == c[nx][ny]:             dfs(nx,ny,co,b,c)             z=z+1     return z     if __name__ == '__main__':   main() 

error: file "c:\users\abhi\desktop\cbir-p\cvv\test.py", line 125, in dfs dfs(nx,ny,co,b,c) runtimeerror: maximum recursion depth exceeded

i trying find connected components in image using python.i have used recursive dfs find connected components . code works fine 6*6 matrix gives error when used image .in above code drblur list of lists has image intensities .

please me.

the error pretty clear.

you have 2 alternatives. can increase allowable recursion depth (you can find out how here), summary:

sys.setrecursionlimit(limit)¶ 

or can change dfs iterative instead of recursive (you can find out how in graph algorithms text book).


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -