fixed some small but key bugs...also figured out the tqdm newline thing...use "with"
@@ -1835,9 +1835,8 @@ def invade_region(im, bd, dt=None, inv=None, thickness=3, coarseness=3,
dt = edt(im)
# Coarsen the dt to nearest integer or more
coarseness = max(1, coarseness)
- dt_coarse = np.digitize(dt, bins=np.arange(0, dt.max(), coarseness))
- dt_coarse = dt_coarse/dt_coarse.max()*np.around(dt.max(), decimals=0)
- dt_coarse = dt_coarse.astype(int)
+ dt_coarse = np.digitize(dt, bins=np.arange(1, dt.max(), coarseness))
+ dt_coarse = (dt_coarse/dt_coarse.max()*dt.max()).astype(int)
# Process the boundary image
bd = np.copy(bd > 0)
if im.ndim == 3:
@@ -1849,7 +1848,9 @@ def invade_region(im, bd, dt=None, inv=None, thickness=3, coarseness=3,
# satn_step = 0.01
# pbar = tqdm(total=100, unit='%_Saturation', disable=False)
edge = np.copy(bd)
- for _ in tqdm(range(1, max_iter)):
+ with tqdm(range(1, max_iter)) as pbar:
+ for _ in range(1, max_iter):
+ pbar.update()
# Dilate the boundary by 'thickness'
temp = spim.binary_dilation(input=bd, structure=strel(max(1, thickness)))
# temp = edt(~bd, parallel=8) <= thickness
@@ -1873,8 +1874,8 @@ def invade_region(im, bd, dt=None, inv=None, thickness=3, coarseness=3,
if npts < 100*(1 + 20*(im.ndim == 3)):
for i in range(len(pt[0])):
c = tuple([pt[j][i] for j in range(len(pt))])
- inv = insert_sphere(im=inv, c=np.array(c), r=dt[c], v=step,
- overwrite=False)
+ inv = insert_sphere(im=inv, c=np.array(c), r=int(dt[c]),
+ v=step, overwrite=False)
else: # If many points, just use a dilation on whole image
# blobs = fftmorphology(im=temp, strel=strel(r_max), mode='dilation')
blobs = edt(~temp, parallel=8) <= r_max
@@ -1894,6 +1895,7 @@ def invade_region(im, bd, dt=None, inv=None, thickness=3, coarseness=3,
break
if _ == (max_iter - 1):
print('\nMaximum number of iterations reached...exiting')
+ break
# Convert inv image such that uninvaded voxels are set to -1 and solid to 0
temp = inv == 0
inv[~im] = 0
