// Finally, find the minimum distance per child
min_dist = centrosome.cpmorphology.fixup_scipy_ndimage_result(
scipy.ndimage.minimum(dist, clabel, numpy.arange(len(ccounts)))
)
// Account for unparented children
dist = numpy.array([numpy.NaN] * len(mask))
After Change
// Sort the points by label //
reverse_column_order = range(children.dimensions)[::-1]
coordinates = perim_loc[:, reverse_column_order].transpose().tolist()
coordinates.append(perim_idx)
idx = numpy.lexsort(coordinates)
perim_loc = perim_loc[idx, :]
perim_idx = perim_idx[idx]
// Get counts and indexes to each run of perimeter points
counts = scipy.ndimage.sum(
numpy.ones(len(perim_idx)), perim_idx, numpy.arange(1, perim_idx[-1] + 1)
).astype(numpy.int32)
indexes = numpy.cumsum(counts) - counts
// For the children, get the index and count of the parent
ccounts = counts[parents_of_masked]
cindexes = indexes[parents_of_masked]
// Now make an array that has an element for each of that child"s perimeter points
clabel = numpy.zeros(numpy.sum(ccounts), int)
// cfirst is the eventual first index of each child in the clabel array
cfirst = numpy.cumsum(ccounts) - ccounts
clabel[cfirst[1:]] += 1
clabel = numpy.cumsum(clabel)
// Make an index that runs from 0 to ccounts for each child label.
cp_index = numpy.arange(len(clabel)) - cfirst[clabel]
// then add cindexes to get an index to the perimeter point
cp_index += cindexes[clabel]
// Now, calculate the distance from the centroid of each label to each perimeter point in the parent.
dist = numpy.sqrt(numpy.sum((perim_loc[cp_index, :] - ccenters[clabel, :]) ** 2, 1))
// Finally, find the minimum distance per child
min_dist = scipy.ndimage.minimum(dist, clabel, numpy.arange(len(ccounts)))
// Account for unparented children
dist = numpy.array([numpy.NaN] * len(mask))