Skip to content

Possible Performance Improvement #2

@william-silversmith

Description

@william-silversmith

Hi! I was browsing repos that were using cc3d recently to see how people are using it. I noticed in your repo that there was a spot that looked slow that could be improved fairly easily.

labels_out = cc3d.connected_components(np.asarray(hard_threshold_patch, dtype=int))
numb_labels = np.max(labels_out) # extract number of different connected components found
numb_non_zero_voxels = []
for seg_id in range(1, numb_labels + 1): # loop over different labels (i.e. conn. components) found
extracted_image = labels_out * (labels_out == seg_id) # extract one conn. component volume
numb_non_zero_voxels.append(np.count_nonzero(extracted_image)) # append number of non-zero voxels for this conn. component volume
largest_conn_comp_value = np.argmax(numb_non_zero_voxels) + 1
largest_conn_comp_binary = hard_threshold_patch * (labels_out == largest_conn_comp_value)

        largest_conn_comp_binary = cc3d.largest_k(labels_out, k=1)

If that's not useful to your project, please feel free to ignore this as I don't want to waste your time. Good luck!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions