From: Alex L. <ale...@gm...> - 2006-06-10 17:19:20
|
Not sure, but my Google desktop search of "medfilt" (the name of Matlab function) brought me to: info_signal.py - N-dimensional order filter. medfilt -N-dimensional median filter If it's true, then it is the 2D median filter. Regarding the neighbouring cells, I found the iterator on 2D ranges on the O'Reily Cookbook by Simon Wittber very useful for my PyPIV (Particle Image Velocimetry, which works by correlation of 2D blocks of two successive images): http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/334971 def blocks(size, box=(1,1)): """ Iterate over a 2D range in 2D increments. Returns a 4 element tuple of top left and bottom right coordinates. """ box = list(box) pos = [0,0] yield tuple(pos + box) while True: if pos[0] >= size[0]-box[0]: pos[0] = 0 pos[1] += box[1] if pos[1] >= size[1]: raise StopIteration else: pos[0] += box[0] topleft = pos bottomright = [min(x[1]+x[0],x[2]) for x in zip(pos,box,size)] yield tuple(topleft + bottomright) if __name__ == "__main__": for c in blocks((100,100),(99,10)): print c for c in blocks((10,10)): print c HIH, Alex |