Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: very slow region graph function #20

Merged
merged 5 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,22 @@ python setup.py develop
## Python Use

```python
from cc3d import connected_components
import cc3d
import numpy as np

labels_in = np.ones((512, 512, 512), dtype=np.int32)
labels_out = connected_components(labels_in)
labels_out = cc3d.connected_components(labels_in)

# You can extract individual components like so:
N = np.max(labels_out)
for segid in range(1, N+1):
extracted_image = labels_out * (labels_out == segid)
process(extracted_image)

# We also include a 26-connected region adjacency graph function
# that returns a set of undirected edges. It is not optimized
# (100x slower than connected_components) but it could be improved.
graph = cc3d.region_graph(labels_out)
```

If you know approximately how many labels you are going to generate, you can save substantial memory by specifying a number a safety factor above that range. The max label ID in your input labels must be less than `max_labels`.
Expand Down
16 changes: 16 additions & 0 deletions automated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,19 @@ def test_compare_scipy():
# def test_sixty_four_bit():
# input_labels = np.ones((1626,1626,1626), dtype=np.uint8)
# cc3d.connected_components(input_labels, max_labels=0)

def test_region_grap():
labels = np.zeros( (10, 10, 10), dtype=np.uint32 )

labels[1,1,1] = 1
labels[2,2,2] = 2
labels[3,3,3] = 3

labels[4,3,3] = 4
labels[2,3,3] = 5

# not connected to anything else
labels[6,:,:] = 6

res = cc3d.region_graph(labels)
assert res == set([ (1,2), (2,3), (2,5), (3,4), (3,5) ])
Loading