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

1D Array of 4 Elements Incorrect #103

Closed modaresimr closed 1 year ago

modaresimr commented 1 year ago

An error occurs when using an array of 4 elements

import numpy as np
import cc3d
labels, seg_count = cc3d.connected_components(np.array([[[1,1,1,1]]]), return_N=True)
labels

output:

[1,0,0,0]

expected output:

[1,1,1,1]
william-silversmith commented 1 year ago

Thank you for reporting this! I'll take a look.

william-silversmith commented 1 year ago

This is due to faulty special handling of single rows of foreground for fast processing. It gets confused between the different orientations of arrays. Will issue a fix soon.

modaresimr commented 1 year ago

Thank you :-)

william-silversmith commented 1 year ago

Well, that was a subtle bug. 1D arrays are both C and F contiguous. Some parts of the code were checking for if F else and others were doing if C else and this caused 1D arrays to have problems.

william-silversmith commented 1 year ago

Released a fix in 3.10.3. Check it out!