Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge connectivity resolving helper functions in morphology._util #4581

Open
lagru opened this issue Apr 14, 2020 · 3 comments
Open

Merge connectivity resolving helper functions in morphology._util #4581

lagru opened this issue Apr 14, 2020 · 3 comments
Labels
🔰 Good first issue 🔧 type: Maintenance Refactoring and maintenance of internals

Comments

@lagru
Copy link
Member

lagru commented Apr 14, 2020

Right now there are

def _validate_connectivity(image_dim, connectivity, offset):
"""Convert any valid connectivity to a structuring element and offset.
Parameters
----------
image_dim : int
The number of dimensions of the input image.
connectivity : int, array, or None
The neighborhood connectivity. An integer is interpreted as in
``scipy.ndimage.generate_binary_structure``, as the maximum number
of orthogonal steps to reach a neighbor. An array is directly
interpreted as a structuring element and its shape is validated against
the input image shape. ``None`` is interpreted as a connectivity of 1.
offset : tuple of int, or None
The coordinates of the center of the structuring element.
Returns
-------
c_connectivity : array of bool
The structuring element corresponding to the input `connectivity`.
offset : array of int
The offset corresponding to the center of the structuring element.

and

def _resolve_neighborhood(selem, connectivity, ndim):
"""Validate or create structuring element.
Depending on the values of `connectivity` and `selem` this function
either creates a new structuring element (`selem` is None) using
`connectivity` or validates the given structuring element (`selem` is not
None).
Parameters
----------
selem : ndarray
A structuring element used to determine the neighborhood of each
evaluated pixel (``True`` denotes a connected pixel). It must be a
boolean array and have the same number of dimensions as `image`. If
neither `selem` nor `connectivity` are given, all adjacent pixels are
considered as part of the neighborhood.
connectivity : int
A number used to determine the neighborhood of each evaluated pixel.
Adjacent pixels whose squared distance from the center is less than or
equal to `connectivity` are considered neighbors. Ignored if
`selem` is not None.
ndim : int
Number of dimensions `selem` ought to have.
Returns
-------
selem : ndarray
Validated or new structuring element specifying the neighborhood.

which have very much in common and should probably be merged.

@lagru lagru added 🔰 Good first issue 🔧 type: Maintenance Refactoring and maintenance of internals labels Apr 14, 2020
@jni
Copy link
Member

jni commented Apr 15, 2020

Ha, love it. They are so similar. Thanks for spotting this @lagru, and I agree that they should be merged. We need to decide on selem vs footprint vs structure vs neighborhood, though. 😂 See #4154.

@jni
Copy link
Member

jni commented Apr 15, 2020

fwiw my preference is "neighborhood".

@stefanv
Copy link
Member

stefanv commented Apr 15, 2020

Elsewhere we had neighbors, which has now become connectivity, so I guess technically neighborhood is free; but it's not the most intuitive naming to me.

Structuring element is technically a correct naming, but the selem shortening isn't very appealing.

footprint would be consistent with SciPy; but, note that SciPy allows for a combination of footprint (which values are taken into consideration) + structure (which can be grey level). I think we only allow 1s and 0s in our structuring elements, so in that sense structure is appealing as the "combination" of footprint+structure.

@scikit-image scikit-image locked and limited conversation to collaborators Oct 18, 2021
@scikit-image scikit-image unlocked this conversation Mar 2, 2022
@grlee77 grlee77 reopened this Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔰 Good first issue 🔧 type: Maintenance Refactoring and maintenance of internals
Projects
None yet
Development

No branches or pull requests

5 participants