
334 A Computational Introduction to Digital Image Processing, Second Edition
Python
In : def zs
_
fun(x,parity):
...: n = np.reshape(x,[3,3])
...: n[1,1] = 0
...: B = n.sum()
...: X = sk.measure.label(n,background=0).max()+1
...: out = (B>=2) and (B<=6) and (X==1)
...: if parity==0:
...: out = out & (x[1]==0 or x[3]==0 or (x[5]==0 and x[7]==0))
...: elif parity==1:
...: out = out & (x[5]==0 or x[7] ==0 or (x[1]==0 and x[3]==0))
...: return out
The functions will be applied using the ndimage.generic
_
filter method:
Python
In : from scipy.ndimage import generic
_
filter as gfilt
In : L = zeros((12,10)); L[1:11,1:6]=1; L[6:11,6:9]=1;
In : prev = np.copy(L)
In : curr ...