GithubHelp home page GithubHelp logo

Comments (7)

william-silversmith avatar william-silversmith commented on July 22, 2024 1

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.

william-silversmith avatar william-silversmith commented on July 22, 2024

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.

william-silversmith avatar william-silversmith commented on July 22, 2024

The algorithm skips regions that are colored black (0), so masking will speed up the run time.

from connected-components-3d.

atpolonsky avatar atpolonsky commented on July 22, 2024

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.

william-silversmith avatar william-silversmith commented on July 22, 2024

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.

atpolonsky avatar atpolonsky commented on July 22, 2024

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.

william-silversmith avatar william-silversmith commented on July 22, 2024

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.

if (cur == 0) {
continue;
}

Since the output relabeled image retains the black voxels, np.uniquewill 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.