Repository navigation
Closed
Labels
⚠️ PriorityThis issue or PR should be given priority
Description
Description
I am trying to create a flood mask with skimage.morphology.flood that encompassed all points connected to a given start point in a numpy array. This works when i create a small window around my start point but doesn't when i run it on the full image. I posted this issue on stack overflow and it was pointed out to me that my array is in F-ordering in this entails a bug since skimage expects a C-ordering array.
Way to reproduce
# I have a large array node_space and a point of interest current_point
In [1]: node_space.shape
Out[1]: (267, 321, 206)
In [2]: current_point
Out[2]: (127, 171, 51)
# When I take a small cube and flood it from my point of interest flood works fine
In [3]: array = node_space[current_point[0]-1: current_point[0]+2, current_point[1]-1: current_point[1]+2, current_point[2]-1: current_point[2]+2]
In [3]: mask = flood(array, (1,1,1))
In [4]: mask
Out[4]:
array([[[False, False, False],
[False, False, True],
[False, False, False]],
[[False, False, False],
[False, True, False],
[False, False, False]],
[[False, False, False],
[False, False, False],
[False, False, False]]])
# However when I run The same operation on the larger image it fails
In [5]: mask = flood(node_space, current_point)
In [6]: mask[current_point[0]-1: current_point[0]+2, current_point[1]-1: current_point[1]+2, current_point[2]-1: current_point[2]+2]
Out[6]:
array([[[False, False, False],
[False, False, False],
[False, False, False]],
[[False, False, False],
[False, False, False],
[False, False, False]],
[[False, False, False],
[False, False, False],
[False, False, False]]])Version information
# Paste the output of the following python commands
from __future__ import print_function
import sys; print(sys.version):
3.7.6 (default, Jan 8 2020, 13:42:34)
[Clang 4.0.1 (tags/RELEASE_401/final)]
import platform; print(platform.platform()):
Darwin-18.7.0-x86_64-i386-64bit
import skimage; print("scikit-image version: {}".format(skimage.__version__)):
scikit-image version: 0.16.2
import numpy; print("numpy version: {}".format(numpy.__version__))
numpy version: 1.18.2# your output hereMetadata
Metadata
Assignees
Labels
⚠️ PriorityThis issue or PR should be given priority
Activity
rfezzani commentedon Apr 4, 2020
Thank you @MarcoPerezCaceres for reporting this.
Can you please confirm this assumption using
jni commentedon Apr 4, 2020
@rfezzani sorry, I meant to provide some extra context here but didn't get a chance. I've verified the behaviour myself with the original dataset at the SO question.
jni commentedon Apr 4, 2020
node_spaceis actually a super-sparse array, so you can verify the behaviour by creating it as follows:jni commentedon Apr 4, 2020
CC @JDWarner @lagru
The quick fix is to always pass the input through
np.ascontiguousarray, which we should do, before deciding whether we want to go through a "proper" fix of ensuring that the neighbors code works with F-ordering.jni commentedon Apr 4, 2020
@MarcoPerezCaceres thank you for reporting! 😊
rfezzani commentedon Apr 4, 2020
OK, excellent, thank you @jni for all these information. The quick fix sound reasonable.
lagru commentedon Apr 5, 2020
Wew, quite a few things here which might be oversights:
_fast_padalways returns a c-contiguous array regardless of the input's order_offsets_to_raveled_neighborsis missing theorderparameterorderparameter is missing in all calls toravel()which therefore defaults toorder="C"I'll make a PR in a moment.
Thanks for the ping. 😉
lagru commentedon Apr 5, 2020
See #4556.