seung-lab / connected-components-3d

Connected components on discrete and continuous multilabel 3D & 2D images. Handles 26, 18, and 6 connected variants; periodic boundaries (4, 8, & 6)
GNU Lesser General Public License v3.0
356 stars 42 forks source link

Question on the output of contacts #116

Closed tengssh closed 5 months ago

tengssh commented 5 months ago

Hi,

Thank you for cc3d! I find it very helpful and efficient for labelling domains in 3D system. Maybe I misunderstood the use of "contacts" function, but when I try to input a 3x3x3 array like this:

data = np.ones((3,3,3))
data[1,1,1]=2
labels_out = cc3d.connected_components(data, connectivity=6)
cc3d.contacts(labels_out, connectivity=6, surface_area=True)

and it gives me {(1,2): 4.0}

Shouldn't it be 6 instead of 4, e.g. top-bottom, front-back, left-right? Thank you!

william-silversmith commented 5 months ago

Yup, that looks like a bug to me. Let me check it out.

william-silversmith commented 5 months ago

I've just uploaded a new version to PyPI! Please give it a test and let me know if that solves it for you.

tengssh commented 5 months ago

Yes, it solves the problem and the results now make more sense to me. Btw, would it be possible to implement a periodic boundary condition? I understand that experimental images may not consider it, but having this option for simulations would be cool. Thank you again for solving this issue!

william-silversmith commented 5 months ago

Glad that helped!

I don't think I understand what is meant by a periodic boundary condition. Can you elaborate?

On Wed, Apr 3, 2024, 11:31 AM Shenghan @.***> wrote:

Yes, it solves the problem and the results now make more sense to me. Btw, would it be possible to implement a periodic boundary condition? I understand that experimental images may not consider it, but having this option for simulations would be cool. Thank you again for solving this issue!

— Reply to this email directly, view it on GitHub https://github.com/seung-lab/connected-components-3d/issues/116#issuecomment-2034933670, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATGQSPPCEHXE642PK6PD6TY3QOEFAVCNFSM6AAAAABFTZZNN2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZUHEZTGNRXGA . You are receiving this because you commented.Message ID: @.***>

tengssh commented 5 months ago

Hi,

It means that D(x)=D(x+L), where L is the length of the box along x, so that in the following case:

data = np.array([[3,3,0,3,3]])
labels_out = cc3d.connected_components(data, connectivity=6)

Thereby instead of array([[1,1,0,2,2]], dtype=unit16) it will output array([[1,1,0,1,1]], dtype=unit16) if periodic boundary condition is applied. Maybe this wiki would be helpful in explaining what I meant.

william-silversmith commented 5 months ago

Oh I see what you mean. That's an interesting application. I'll consider it.

william-silversmith commented 5 months ago

Would you need support for 6 connected only? It's a lot more tractable to support it for a limited number of connectives. I believe there are 8 separate CCL implementations in the codebase: 4, 8, 6, 18, 26, and three continuous domain versions. I don't think I'd have time to do more than a few of them.

william-silversmith commented 5 months ago

Might be good to continue this conversation here: https://github.com/seung-lab/connected-components-3d/issues/117

tengssh commented 5 months ago

Would you need support for 6 connected only? It's a lot more tractable to support it for a limited number of connectives. I believe there are 8 separate CCL implementations in the codebase: 4, 8, 6, 18, 26, and three continuous domain versions. I don't think I'd have time to do more than a few of them.

Thank you! I think 6 should be enough.