def cmp(labels, ans, types=TYPES, anisotropy=1.0): for dtype in types: print(dtype) labels = np.array(labels, dtype=dtype) ans = np.array(ans, dtype=np.float32) result = edt.edtsq(labels, anisotropy=anisotropy, black_border=False) assert np.all(result == ans)
def cmp(labels, ans, types=TYPES, anisotropy=(1.0, 1.0, 1.0)): for dtype in types: print(dtype, anisotropy) labels = np.array(labels, dtype=dtype) ans = np.array(ans, dtype=np.float32) print(labels) print(ans) result = edt.edtsq(labels, anisotropy=anisotropy, black_border=True, order='C') assert np.all(result.T == ans) # written in human understandable order so needs transpose
def cmp(labels, ans, types=TYPES, anisotropy=(1.0, 1.0)): for parallel in (1, 2): for dtype in types: print(dtype) labels = np.array(labels, dtype=dtype) ans = np.array(ans, dtype=np.float32) result = edt.edtsq(labels, anisotropy=anisotropy, black_border=True, parallel=parallel) print(result) assert np.all(result == ans)
import time import numpy as np from scipy import ndimage import edt labels = np.ones(shape=(512, 512, 512), dtype=np.uint32) start = time.time() res = edt.edtsq(labels, anisotropy=(1, 1, 1)) print('Multi-label EDT: ', time.time() - start, ' sec.') binlabels = labels.astype(np.bool) start = time.time() res = edt.edtsq(binlabels, anisotropy=(1, 1, 1)) print('Binary EDT: ', time.time() - start, ' sec.') start = time.time() ndimage.distance_transform_edt(labels) print('ndimage EDT: ', time.time() - start, ' sec.')
def test_numpy_anisotropy(): labels = np.zeros(shape=(128, 128, 128), dtype=np.uint32) labels[1:-1, 1:-1, 1:-1] = 1 resolution = np.array([4, 4, 40]) res = edt.edtsq(labels, anisotropy=resolution)