Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a custom kernel for `center_of_mass` Create a custom kernel of `center_of_mass` to use with `labeled_comprehension`. In the kernel take the ROI's intensity and 1-D positions along with a few arguments to be bound before calling `labeled_comprehension` (like the shape of the original image and the results expected type). Use these to unravel the 1-D positions back into N-D positions and computed the center of mass for the given ROI to pass back in an expected form. As `labeled_comprehension` can only handle scalars being returned for each ROI, use a structured type to pass back each coordinate of the center of mass in a different field. The structured type uses a simple naming scheme based on a string holding the index corresponding to that dimension. * Use `labeled_comprehension` in `center_of_mass` Rewrite `center_of_mass` to use `labeled_comprehension` along with a custom kernel. This simplifies the Dask graph significantly, improves the performance noticeably, and cleans up the code a bit as the whole center of mass computation is now handled by the custom kernel function. Only a little bit of bookkeeping is needed to bind a few extra arguments (since `labeled_comprehension` does not handle keyword arguments) to the custom kernel and to convert the custom structured array type (needed since `labeled_comprehension` cannot handle results with a shape) into a normal array before returning it user.
- Loading branch information