Comments (7)
Perhaps that was more verbose than you needed, but yes, I think you understand the problem correctly now and this is normal behavior.
from connected-components-3d.
You can try masking the source image with numpy operators before applying cc3d. e.g. img *= boolean_mask
You may also find useful masking operators in this other library I wrote called fastremap. Let me know if that helps!
from connected-components-3d.
The algorithm skips regions that are colored black (0), so masking will speed up the run time.
from connected-components-3d.
I'm still getting a returned feature of size equal to the number of black (0 value) voxels in my volume, even after applying a mask. Is this the expected behavior?
from connected-components-3d.
Can you show me some of your code? How are you measuring the feature and performing the mask? Have you visualized the volume?
from connected-components-3d.
I think I figured it out, the labels coming out of cc3d.connected_components has a region 0, so what I was doing subsequently was counting this as a feature (np.unique includes 0 as a unique number in the array). I can't actually tell if the algorithm is checking black voxels in this case, but I did see a slight slowdown when I made all of the voxels non-zero and ran the code again, maybe a second or two difference in run time at most. My test dataset volume was 1500 x 500 x 800 voxels, but I have larger volumes on the order of 5000x5000x500 voxels, so its possible without masking these would take much longer. If this behavior makes sense you can mark this as closed.
from connected-components-3d.
cc3d takes a multi-labeled image as input and counts black voxels in that image as background. Non-zero voxels are counted as foreground, though neighboring values that do not match are not counted as part of the same component. It outputs an image with the foreground voxels labeled 1 to N where there are N connected regions of foreground voxels. Background labels (black voxels) remain unchanged and are treated specially so that the innermost loop skips over them without applying the decision tree. Therefore, you should expect better performance on an image that has a lot of black voxels.
connected-components-3d/cc3d.hpp
Lines 307 to 309 in 1b7479c
Since the output relabeled image retains the black voxels, np.unique
will indeed output an accounting of them. You can try using fastremap.unique
for a faster implementation of that function.
https://github.com/seung-lab/fastremap/blob/master/fastremap.pyx#L705
As a 2D example:
INPUT IMAGE OUTPUT IMAGE
0 0 4 5 6 4 0 0 1 2 3 4
0 4 0 5 6 4 0 1 0 2 3 4
0 4 0 5 6 4 ====cc3d===> 0 1 0 2 3 4
0 0 0 5 5 6 0 0 0 2 2 3
0 0 0 6 6 0 0 0 0 3 3 0
Applying np.unique(labels, return_counts=True)
to the output image in the above example would return results agnostic to the connected components problem and would contain a tabulation of black pixels.
from connected-components-3d.
Related Issues (20)
- Applying Dust and largest_k dtype output option HOT 2
- dust sugnature HOT 1
- Massive memory Leak HOT 7
- 1D Array of 4 Elements Incorrect HOT 5
- Cannot find reference 'dust' in 'cc3d.py' HOT 2
- Question on comparing individual lesions between two masks based on the cc3d.statistics output. HOT 1
- Additional metrics support HOT 2
- Does cc3d also work with memmory-mapped numpy arrays and array-like data? HOT 14
- cc3d.statistics["bounding_boxes"] are wrong HOT 1
- largest_k fails for transposed arrays HOT 6
- About the lastest_k function HOT 4
- Statistics output HOT 7
- Question on the output of contacts HOT 9
- Periodic Boundary Conditions HOT 4
- Is the output label of largest_k ordered? HOT 2
- Add a better error for type support. HOT 4
- Any way to make this GPU Compatible? HOT 6
- Applying dust to labels does not do anything HOT 3
- Support for Numpy 2.0 HOT 3
- cc3d.dust fails HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from connected-components-3d.