Repository navigation
Description
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)
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Activity
sciunto commentedon Apr 14, 2017
Previous discussions: #1522
[-]consistency of multichannel handling[/-][+]SKIEP: Consistency of default parameter values (e.g. `multichannel`)[/+]soupault commentedon Apr 15, 2017
@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=Falseeverywhere by default. Also, I suggest to speedup this particular deprecation case and schedule everything for 0.15 instead of 0.16.TODO: Review and delete any "guessing" code.
soupault commentedon Apr 15, 2017
This issue can be related: #2605
stefanv commentedon Jul 15, 2017
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
jni commentedon Jul 18, 2017
@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.
stefanv commentedon Jul 19, 2017
None is a standard symbol for "use the default value", wouldn't you agree?
jni commentedon Nov 23, 2017
Adding a comment here at @soupault's prompting in #2870:
For functions that don't work with 3D images at all,
multichannelcould 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.stefanv commentedon Nov 27, 2017
I'm okay with that; it catches the by-far-most-common use case.
[-]SKIEP: Consistency of default parameter values (e.g. `multichannel`)[/-][+]SKIEP: Consistency of `multichannel` parameter handling[/+][-]SKIEP: Consistency of `multichannel` parameter handling[/-][+]SKIP: Consistency of `multichannel` parameter handling[/+]grlee77 commentedon Jul 10, 2020
I updated the list in the first comment in this issue. It looks like
gaussian_filteranddifference_of_gaussiansare the only nD functions still defaulting tomultichannel=Noneand then trying to guess based onmultichannel = image.shape[-1] == 3.See also the more recent proposal in #4294 for moving away from
multichanneland to achannel_axisargument instead.jni commentedon Oct 27, 2020
@scikit-image/core given #4294, I'm disinclined to add a new warning to
filters.gaussianasking people to addmultichannel=Falseto 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!