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

Some examples #34

Closed chaoyuxie closed 4 years ago

chaoyuxie commented 5 years ago

Hi, very nice library! I was doing a neuronal skeleton extraction recently. I used this library, it was very useful and the speed is fast. But, I have a question. if i have two 3d images, and the images are adjacent. in your comment "skels = ... # a set of skeletons produced from the same label id" does it mean i get the first image's skeketon and then get the other image's skeleton, and after that, extract the two skeletons with the same label and use the code skel = PrecomputedSkeleton.simple_merge(skels).consolidate()? Could you please give me some examples to merge the skeleton with same label? Thank you!

william-silversmith commented 5 years ago

Hi chaoyuxie,

Assuming the label connects across the two adjacent volumes, you can connect the skeletons using one pixel overlap between the volumes and set fix_borders=True. This will cause the skeletons to connect at the border exactly. You can then run skel = PrecomputedSkeleton.simple_merge(skels).consolidate() to create a single object, but it's possible that the object will have loops in it in the general case. Therefore, you have to also run kimimaro.postprocess which removes short disconnected components, short extensions from the main skeleton, and loops.

import kimimaro

img = ... # some big image that is 1024x512x512

skels1 = kimimaro.skeletonize(img[:512+1,:,:], fix_borders=True, ...) # note the overlap of 1 voxel
skels2 = kimimaro.skeletonize(img[512:, :, :], fix_borders=True, ...)

skels = [ skels1[ 1 ], skels2[ 1 ] ] # let's look at label 1
skel = PrecomputedSkeleton.simple_merge(skels).consolidate()
skel = kimimaro.postprocess(
  skel, 
  dust_threshold=1000, # physical units
  tick_threshold=3500 # physical units
)

I have an explanation for how the 1 voxel overlap works here: https://github.com/seung-lab/kimimaro#non-overlapped-chunked-processing-fix_borderstrue

If you're working with more than two images, I use Igneous for applying Kimimaro to large images that are hundreds of terabytes in a chunked fashion: https://github.com/seung-lab/igneous/blob/master/README.md#skeletonization-skeletontask-skeletonmergetask

Hope that helps! Let me know if you have more questions. :)

chaoyuxie commented 4 years ago

Amazing, actually i working with more than two images, i will try Igneous for my work. Thanks a lot.

william-silversmith commented 4 years ago

I'm going to close this since we were discussing this in Igneous. Please reopen if necessary!