def checkCycle(image): # check if number of cycles in the donut image after thinning is 1 skel = Skeleton(image) skel.setThinningOutput(mode="constant") thinned_blob = skel.skeletonStack label_img, countObjects = ndimage.measurements.label(thinned_blob, structure=np.ones((3, 3, 3), dtype=bool)) assert countObjects == 1, "number of cycles in single donut is {}".format(countObjects)
def checkSameObjects(image): # check if number of objects are same in input and output of thinning label_img, countObjects = ndimage.measurements.label(image, structure=ndimage.generate_binary_structure(image.ndim, 2)) skel = Skeleton(image) skel.setThinningOutput(mode="constant") thinned_blob = skel.skeletonStack label_img, countObjectsn = ndimage.measurements.label(thinned_blob, structure=ndimage.generate_binary_structure(image.ndim, 2)) assert (countObjectsn == countObjects), ("number of objects in input " "{} is different from output {}".format(countObjects, countObjectsn)) return thinned_blob
def get_thinnedRandomBlob(): # get random convex blob xs = np.random.uniform(-1, 1, size=50) ys = np.random.uniform(-1, 1, size=50) zs = np.random.uniform(-1, 1, size=50) xyzs = list(zip(xs, ys, zs)) hullz = ConvexHull(xyzs) xf, yf, zf = np.mgrid[-1:1:100j, -1:1:10j, -1:1:10j] blob = np.ones(xf.shape, dtype=bool) for x, y, z, c in hullz.equations: mask = (xf * x) + (yf * y) + (zf * z) - c < 0 blob[mask] = 0 blob = blob.astype(bool) skel = Skeleton(blob) skel.setThinningOutput() thinned_blob = skel.skeletonStack return thinned_blob
def checkAlgorithmPreservesImage(image): skel = Skeleton(image) skel.setThinningOutput(mode="constant") thinned_blob = skel.skeletonStack assert np.array_equal(image, thinned_blob)