Giter Club home page Giter Club logo

Comments (5)

william-silversmith avatar william-silversmith commented on May 11, 2024

This snippet should do it for you. :)

cc_labels = cc3d.connected_components(img)
cc_segids, pxct = np.unique(cc_labels, return_counts=True)
mask_ids = [ sid for sid, ct in zip(cc_segids, pxct) if ct < dust_threshold and sid != 0 ]
cc_labels[ np.in(cc_labels, mask_ids) ] = 0

If you're willing to download another dependency I also write a package called fastremap that can do it like so, which may be slightly faster or less memory intensive:

cc_labels = cc3d.connected_components(img)
cc_segids, pxct = np.unique(cc_labels, return_counts=True)
mask_ids = [ sid for sid, ct in zip(cc_segids, pxct) if ct < dust_threshold and sid != 0 ]
cc_labels = fastremap.mask(cc_labels, mask_ids)

from connected-components-3d.

selvakarna avatar selvakarna commented on May 11, 2024

Thanks william-silversmith.

from connected-components-3d.

william-silversmith avatar william-silversmith commented on May 11, 2024

You're welcome!

from connected-components-3d.

selvakarna avatar selvakarna commented on May 11, 2024

from this above code:

cc_labels = cc3d.connected_components(img)
cc_segids, pxct = np.unique(cc_labels, return_counts=True)
mask_ids = [ sid for sid, ct in zip(cc_segids, pxct) if ct < dust_threshold and sid != 0 ]
cc_labels[ np.in(cc_labels, mask_ids) ] = 0

when i use volume image to this above code, nothing 3d small object removed ? so how to remove small 3d volume object? i set dust_threshold= 50, but its not working[ small object cannot removed] ?
@william-silversmith

from connected-components-3d.

william-silversmith avatar william-silversmith commented on May 11, 2024

For anyone reading this thread these days, cc3d.dust is available as of 3.7.0 which will remove components smaller than a specified number of voxels. If you want to do something fancy like "as a fraction of the size of the largest shape" you can do a pass with cc3d.statistics to compute it.

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.