seung-lab / kimimaro

Skeletonize densely labeled 3D image segmentations with TEASAR. (Medial Axis Transform)
GNU General Public License v3.0
136 stars 23 forks source link

Destroy the Preamble #24

Closed william-silversmith closed 5 years ago

william-silversmith commented 5 years ago

The Preamble used to be a fairly significant chunk of time (typically about a minute) before skeletonization proceeded in earnest.

A string of recent improvements in fastremap, cc3d, skeletontricks.get_mapping, and the edt has made it possible to execute the preamble in 15-25 seconds. If we could speed up np.unique(..., return_counts=True) and scipy.ndimage.find_objects, the preamble could be collapsed to nearly only the edt, which is parallel enabled.

william-silversmith commented 5 years ago

Progress so far:

image

The initial loading, masking, connected components, and mapping steps take about five seconds. The edt takes about 15 seconds on parallel 1, the find_objects call takes about seven seconds. It would be realistic to get this down to 22 seconds on parallel 1. This would amount to a global improvement of about 6%, but an annoyance improvement of nearly 50% when trying different things.

william-silversmith commented 5 years ago

Here's where it is at parallel 4

image

william-silversmith commented 5 years ago

It looks like scipy's find_objects is much faster on C arrays than on Fortran arrays (probably going against the grain). This, or something like it, might be the trick to collapsing find_objects down to almost nothing.

bbxs = scipy.ndimage.find_objects(labels.T)
bbxs = [ slcs[::-1]  for slcs in bbxs ]

On my laptop, the difference is from almost 8 seconds down to 1.

william-silversmith commented 5 years ago

image