track_check_repeat icon indicating copy to clipboard operation
track_check_repeat copied to clipboard

Possible cc3d Performance Improvement

Open william-silversmith opened this issue 3 years ago • 1 comments

Hi! I was just browsing through projects that are using cc3d and I noticed a spot where you might be able to get a lot better performance. I don't know how critical this routine is to your project, but I'll offer some advice in case it is helpful.

https://github.com/aharley/track_check_repeat/blob/29fdba438c4d8fe31a6d2117b132bab1571db890/utils/misc.py#L37-L56

Could be rewritten approximately like so to remove lots of redundant computation:

    labels = connected_components(mask)
    stats = cc3d.statistics(labels)
    for segid, extracted_vox in cc3d.each(labels, binary=True):
        slices = stats['bounding_boxes'][segid]
        zmin, zmax = slices[2].start, slices[2].stop
        ymin, ymax = slices[1].start, slices[1].stop
        xmin, xmax = slices[0].start, slices[0].stop
        voxel_count = stats['voxel_counts'][segid]

        if (zmax-zmin > min_side and 
            ymax-ymin > min_side and 
            xmax-xmin > min_side and 
            voxel_count > min_voxels): 

I haven't tested this snippet, it's just a guide. If this isn't helpful, please feel free to ignore this; I don't want to waste your time.

Thanks so much and good luck! Will

william-silversmith avatar Mar 29 '22 17:03 william-silversmith

Thanks, this does look useful! That is indeed a slow part of the code.

I'll keep this issue open until I integrate the idea of your snippet.

aharley avatar Mar 31 '22 01:03 aharley