seung-lab / fill_voids

Fill holes in binary 2D & 3D images fast.
GNU General Public License v3.0
16 stars 4 forks source link

does not do the job? #6

Closed xiuliren closed 3 years ago

xiuliren commented 3 years ago

is this code expected to pass?

import fill_voids

import numpy as np

seg = np.zeros((7, 7, 7), dtype=bool)
seg[1:4, 2:5, 3:6] = True
seg[2, 3, 4] = False
fill_voids.fill(seg, in_place=True)
assert seg[2,3,4] == True
william-silversmith commented 3 years ago

Sorry I just saw this Jingpeng! It looks like the problem is that the array order is C. I call labels = fastremap.asfortranarray(labels) but it looks like that didn't perform an in-place transpose. I'll have to investigate more.

As a note, it does work if you do seg = fill_voids.fill(seg, in_place=True) but you shouldn't have to.

william-silversmith commented 3 years ago

I think I figured it out. The fastremap.asfortranarray does an in-place transposition but doesn't reset the C/F flags on the array. I'll need to fix that in fastremap. Since the array is now transposed, assert seg[4,3,2] == True works...

william-silversmith commented 3 years ago

On further consideration, the numpy documentation says that there's no way to set C/F on an existing array view. https://numpy.org/doc/stable/reference/generated/numpy.ndarray.setflags.html#numpy.ndarray.setflags it looks like you have to use the equal sign. :-/ More clumsy than I'd like. The alternative would be for me to write a fill_voids for C and F order arrays or to re-transpose C order arrays back to the way they were after going through fill_voids.

xiuliren commented 3 years ago

thanks for investigating this! I'll just use the equal sign for now.