Skip to content

SKIP: Consistency of multichannel parameter handling #2613

Closed

Description

@grlee77

Description

This is a summary of some inspection of the codebase to see how multichannel is typically handled. It seems the most common default is multichannel=False, but this is not always the case. There are a few functions that default to None and then try to guess True or False based on the data shape (i.e. if the last axis is size 3 (or 4), assume it is multi-channel). A couple of segmentation routines default to multichannel=True instead.

List as of Apr 13, 2017 original comment

defaults to None:

  • skimage.filters.gaussian (nD)
  • skimage.restoration.denoise_bilateral (2D or 2D+channels)
  • skimage.restoration.denoise_nl_means (2D, 2D+channels or 3D)

defaults to False:

  • skimage.measure.compare_ssim (nD)
  • skimage.restoration.denoise_tv_chambolle (nD)
  • skimage.restoration.denoise_wavelet (nD)
  • skimage.restoration.estimate_sigma (nD)
  • skimage.restoration.inpaint_biharmonic (nD)
  • skimage.segmentation.random_walker_segmentation (2D, 2D+channels, 3D, 3D+channels)

defaults to True:

  • skimage.segmentation.felzenszwalb (only 2D or 2D+channels)
  • skimage.segmentation.slic (2D, 2D+channels, 3D, 3D+channels)

From the above, skimage.filters.gaussian is the only n-dimensional function that doesn't default to multichannel=False. Should it be changed from None to False for consistency?

2 of 3 segmentation routines default to True, while the other defaults to False.

It would be helpful going forward to have a clear guideline of the expected behaviour for new PRs. I believe based on feedback in my prior PRs that multichannel=False is the preferred default, at least for n-dimensional routines.

Updated List as of July 2020
Progress has been made since this issue was originally opened and a number of functions were updated to default to False.

Notably, it seems that gaussian_filter and difference_of_gaussians are the only nD functions that still try to guess whether the data is multichannel based on its shape. hog also infers its multichannel status based on shape, but it is a 2D-only function, so that seems less problematic.

This is the current status (see details above for the original list). The values in parentheses are the number of spatial dimensions supported by the function:

default=True

  • skimage.segmentation.felzenszwalb (2D)
  • skimage.segmentation.slic: (2D or 3D)
  • skimage.draw.random_shapes (creates synthetic data, so different rules may apply)

default=False

  • skimage.exposure.match_histograms (nD)
  • skimage.filters.unsharp_mask (nD)
  • skimage.measure.structural_similarity (nD)
  • skimage.restoration.cycle_spin (nD)
  • skimage.restoration.denoise_bilateral (2D or 3D)
  • skimage.restoration.denoise_nl_means (2D or 3D)
  • skimage.restoration.denoise_tv_bregman (2D or 3D)
  • skimage.restoration.denoise_tv_chambolle (nD)
  • skimage.restoration.denoise_wavelet (nD)
  • skimage.restoration.estimate_sigma (nD)
  • skimage.restoration.inpaint_biharmonic (nD)
  • skimage.segmentation.random_walker (2D or 3D)
  • skimage.transform.pyramid_expand (nD)
  • skimage.transform.pyramid_gaussian (nD)
  • skimage.transform.pyramid_laplacian (nD)
  • skimage.transform.pyramid_reduce (nD)
  • skimage.transform.rescale (nD)
  • skimage.transform.warp_polar (2D)
  • skimage.util.montage (3D)

default=None (and guesses based on shape)

  • skimage.feature.hog (2D)
    if multichannel is None:
        multichannel = (image.ndim == 3)
  • skimage.filters.gaussian_filter (nD)
  • skimage.filters.difference_of_gaussians (nD)
        calls a `_guess_spatial_dimensions helper`
        (does issue a warning when guessing)

Activity

  1. sciunto commented on Apr 14, 2017

    @sciunto
    Member

    Previous discussions: #1522

  2. changed the title [-]consistency of multichannel handling[/-] [+]SKIEP: Consistency of default parameter values (e.g. `multichannel`)[/+] on Apr 15, 2017
  3. soupault commented on Apr 15, 2017

    @soupault
    Member

    @grlee77 Thank you for bringing up this important topic! I've renamed the issue, and suggest to use it for all the discussions on similar matters.

    My decision would be to use multichannel=False everywhere by default. Also, I suggest to speedup this particular deprecation case and schedule everything for 0.15 instead of 0.16.


    defaults to None:

    • skimage.filters.gaussian (nD) [TODO: deprecate]
    • skimage.restoration.denoise_bilateral (2D or 2D+channels) [deprecated, default to False in 0.15]
    • skimage.restoration.denoise_nl_means (2D, 2D+channels or 3D) [deprecated, default to False in 0.15]

    defaults to False:

    TODO: Review and delete any "guessing" code.

    defaults to True:

    • skimage.segmentation.felzenszwalb (only 2D or 2D+channels) [TODO: deprecate]
    • skimage.segmentation.slic (2D, 2D+channels, 3D, 3D+channels) [TODO: deprecate]
  4. soupault commented on Apr 15, 2017

    @soupault
    Member

    This issue can be related: #2605

  5. added this to the 0.14 milestone on Jun 18, 2017
  6. stefanv commented on Jul 15, 2017

    @stefanv
    Member

    We should never guess whether the input is multi-channel or not. However, setting multichannel to None holds an advantage: None can mean "False", but raise a warning if it looks like multi-channel data got passed in (that's a useful warning!). If the user explicitly sets the flag to True or False, you don't need to do the check. We can factor this out into a little utility function, if that's helpful.

    Thoughts? /cc @jni

  7. jni commented on Jul 18, 2017

    @jni
    Member

    @stefanv I'm not sure I like your None proposal. What you're really after is "Probably not" or "I don't think so"... None is not a great or intuitive synonym for those.

  8. stefanv commented on Jul 19, 2017

    @stefanv
    Member

    None is a standard symbol for "use the default value", wouldn't you agree?

  9. jni commented on Nov 23, 2017

    @jni
    Member

    Adding a comment here at @soupault's prompting in #2870:

    For functions that don't work with 3D images at all, multichannel could have a default value of "None". Then we do, if multichannel is None: multichannel = (image.ndim == 3). I know we want a "don't guess" policy, but my feeling is that this applies when there is ambiguity.

  10. stefanv commented on Nov 27, 2017

    @stefanv
    Member

    I'm okay with that; it catches the by-far-most-common use case.

  11. self-assigned this
    on Nov 30, 2017
  12. changed the title [-]SKIEP: Consistency of default parameter values (e.g. `multichannel`)[/-] [+]SKIEP: Consistency of `multichannel` parameter handling[/+] on Nov 30, 2017
  13. modified the milestones: 0.14, 0.14.1 on May 29, 2018
  14. modified the milestones: 0.14.1, 0.15 on Aug 20, 2018
  15. modified the milestones: 0.15, 0.16 on Apr 20, 2019
  16. modified the milestones: 0.16, 0.18 on Apr 8, 2020
  17. added
    🔽 Deprecation
    on Apr 8, 2020
  18. changed the title [-]SKIEP: Consistency of `multichannel` parameter handling[/-] [+]SKIP: Consistency of `multichannel` parameter handling[/+] on Apr 8, 2020
  19. grlee77 commented on Jul 10, 2020

    @grlee77
    ContributorAuthor

    I updated the list in the first comment in this issue. It looks like gaussian_filter and difference_of_gaussians are the only nD functions still defaulting to multichannel=None and then trying to guess based on multichannel = image.shape[-1] == 3.

    See also the more recent proposal in #4294 for moving away from multichannel and to a channel_axis argument instead.

  20. jni commented on Oct 27, 2020

    @jni
    Member

    @scikit-image/core given #4294, I'm disinclined to add a new warning to filters.gaussian asking people to add multichannel=False to all their code only to change it soon. My proposal is to close this issue and move the discussion to #4294, and if we reopen it, certainly to remove it from the 0.18 milestone. If you disagree with this decision please reverse it!

  21. moved this to Done in skimage2on Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions