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

How to extract 3D components from Binary 3D using cc3d package? #23

Closed
selvakarna opened this issue Jun 19, 2019 · 9 comments
Closed

How to extract 3D components from Binary 3D using cc3d package? #23

selvakarna opened this issue Jun 19, 2019 · 9 comments
Labels
question Further information is requested

Comments

@selvakarna
Copy link

How to extract 3D components from Binary 3D using cc3d package?

@william-silversmith william-silversmith added the question Further information is requested label Jun 19, 2019
@william-silversmith
Copy link
Contributor

Hi selvakarna, can you explain what you mean by 3D components? If you mean from an image processed with cc3d, obtain one of the components, you can do so like so:

cc_labels = cc3d.connected_components(labels)
one_label = (cc_labels == label_id) # e.g. label_id = 5 

The README has a more detailed example here: https://github.com/seung-lab/connected-components-3d#python-use

If you are looking to create meshes from 3D image components, have a look at this package:

https://github.com/seung-lab/zmesh

@william-silversmith
Copy link
Contributor

@selvakarna, I hope your problem is solved! Let me know if I can close this issue. I'll assume it's resolved in five days.

@selvakarna
Copy link
Author

@william-silversmith, while i got memory issue to use cc3d ? how to solve ? if any data types need to change?
my volume data= 1000 X 1200 X 7000 ~ 1000 X1200 X9000 ?

@william-silversmith
Copy link
Contributor

Can I ask how much RAM your machine has? If your data type is uint8, you could use about 50 GB maybe, but if the datatype is uint32, it would be 100 GB, and if uint64, 168 GB for the 7000 depth image. For the 9000 depth image, those numbers are 64 GB, 130 GB, and 216 GB.

You can try using the max_labels parameter to reduce the allocation size of one of the arrays but your data are pretty big. This would be slow, but you can try mmapping a file and see if that helps. There are still a few ways I could improve cc3d to reduce the memory pressure, but the data are pretty big.

@selvakarna
Copy link
Author

Hi @william-silversmith,, thanks for reply, is it any small changes in cc3d this parameter changes will reduce memory issue ? can share any parameters change in cc3d?

@william-silversmith
Copy link
Contributor

william-silversmith commented Jun 27, 2019 via email

@william-silversmith
Copy link
Contributor

Hi Sevlakarna, I'm going to close your issues tomorrow if that's okay with you. Let me know if you need more help!

@RylanSchaeffer
Copy link

@william-silversmith I have a quick question. I also want to extract 3d components from binary 3d, albeit in a slightly different manner than what this author was talking about. By this, I mean the following.

Suppose I have a 3D array (I'll use 2D because easier to visualize) of binary values. I would like to know what the connected components are. For instance, I would like to take this binary input:

>>> labels_in
array([[1, 0, 0, 0, 0],
       [0, 1, 0, 0, 0],
       [1, 1, 1, 0, 0],
       [1, 1, 0, 1, 0],
       [1, 1, 0, 0, 1]], dtype=int32)

and convert it to the connected components, where the connected component have arbitrary labels i.e.

>>> labels_in
array([[1, 0, 0, 0, 0],
       [0, 2, 0, 0, 0],
       [2, 2, 2, 0, 0],
       [2, 2, 0, 3, 0],
       [2, 2, 0, 0, 4]], dtype=int32)

How do I do this using your library? Your library appears to presume that the inputs are the connected component labels, which is not true in my case.

@william-silversmith
Copy link
Contributor

Hi Rylan,

I believe you are requesting (assuming your example is 2D), a 4-connected neighborhood. The default is 8-connected, which would return a single fused component in the above example.

import numpy as np
import cc3d

labels_in = np.array(
	[[1, 0, 0, 0, 0],
	[0, 1, 0, 0, 0],
	[1, 1, 1, 0, 0],
	[1, 1, 0, 1, 0],
	[1, 1, 0, 0, 1]], dtype=np.int32)

labels_out = cc3d.connected_components(labels_in, connectivity=4)

>>> print(labels_out)
    [[1 0 0 0 0]
...  [0 2 0 0 0]
...  [2 2 2 0 0]
...  [2 2 0 3 0]
...  [2 2 0 0 4]]


labels_out = cc3d.connected_components(labels_in, connectivity=8)
>>> print(labels_out)
    [[1 0 0 0 0]
...  [0 1 0 0 0]
...  [1 1 1 0 0]
...  [1 1 0 1 0]
...  [1 1 0 0 1]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants