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

WIP: Turn off relabelling in label2rgb #3015

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jni
Copy link
Member

@jni jni commented Apr 12, 2018

Description

I also updated parameter names and deprecated background=-1 as the default. I am currently stating that background=0 will be the default but I could also go for background=None.

This is the first PR with very verbose warning and error messages that we discussed in the mailing list. Comments very welcome.

Also included: a new utility DEFAULT value for use instead of None when deprecating. This makes it easy to distinguish between the use of the DEFAULT value because no value was passed, vs when the user explicitly passes None. I've kept it as simple as possible for now but this could be even more sophisticated, with a DEFAULT object actually holding a default value, rather than having to hardcode it somewhere inside the function. Comments also welcome here!

I still need to add tests for all the new code paths.

Checklist

[It's fine to submit PRs which are a work in progress! But before they are merged, all PRs should provide:]

References

Closes issue #2674

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.

jni added 8 commits April 12, 2018 11:35
This warning appears to have been adopted in scikit-image#485 with no discussion at
all. imho it is unnecessary: if we want to support negative intensity,
we should do it correctly (fixing the intensity), rather than raising a
warning and doing nothing (since the function silently succeeds).

Refs: scikit-image#485
Can turn off relabelling to consecutive labels before color matching.

Addresses issue scikit-image#2674
@pep8speaks
Copy link

Hello @jni! Thanks for submitting the PR.

Line 259:41: E128 continuation line under-indented for visual indent

@@ -0,0 +1,14 @@
class DefaultValue(object):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Ellipsis instead of None?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefanv @soupault to clarify, you mean, get rid of this object, and just use Ellipsis directly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I see it, use Ellipsis instead of 'None' in this class. Your option would work equally well, though

@soupault soupault modified the milestones: 0.14, 0.14.1 May 29, 2018
@soupault soupault self-assigned this Jul 29, 2018
@soupault soupault modified the milestones: 0.14.1, 0.15 Aug 20, 2018
@soupault soupault modified the milestones: 0.15, 0.16 Apr 20, 2019
@sciunto sciunto modified the milestones: 0.16, 0.17 Sep 22, 2019
@sciunto
Copy link
Member

sciunto commented Sep 22, 2019

@jni. I postponed your PR to 0.17. Perhaps you can have a quick look to check the status of it? :)

Copy link
Member

@soupault soupault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this a good change 👍. Added some points to discuss.


Returns
-------
result : array of float, shape (M, N, 3)
The result of blending a cycling colormap (`colors`) for each distinct
value in `label` with the image, at a certain alpha value.
"""
if image is None and kind in ['avg' or 'average']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if image is None and kind in ['avg' or 'average']:
if image is None and kind in ('avg', 'average'):

Returns
-------
result : array of float, shape (M, N, 3)
result : array of float, shape (M, N,[[ P,] ...,] 3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result : array of float, shape (M, N,[[ P,] ...,] 3)
result : array of float, shape (M, N,[ P, [...,]] 3)

@@ -75,7 +79,9 @@ def _match_label_with_color(label, colors, bg_label, bg_color):


def label2rgb(label, image=None, colors=None, alpha=0.3,
bg_label=-1, bg_color=(0, 0, 0), image_alpha=1, kind='overlay'):
background=DEFAULT, background_color=None, image_alpha=1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, this DEFAULT thing is introduced only to help in handling such complex deprecation scenarios. I think using it for other purposes would reduce user experience and should not be recommended.
Pehaps, changing the name to UPDATED could better show its temporary nature.

@@ -75,7 +79,9 @@ def _match_label_with_color(label, colors, bg_label, bg_color):


def label2rgb(label, image=None, colors=None, alpha=0.3,
bg_label=-1, bg_color=(0, 0, 0), image_alpha=1, kind='overlay'):
background=DEFAULT, background_color=None, image_alpha=1,
kind='overlay', relabel=DEFAULT,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
kind='overlay', relabel=DEFAULT,
kind='overlay', *, relabel=DEFAULT,

@@ -0,0 +1,14 @@
class DefaultValue(object):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, 👍

label : array, shape (M, N)
Integer array of labels with the same shape as `image`.
image : array, shape (M, N, 3), optional
label : array, shape (M, N,[[ P,] ...])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
label : array, shape (M, N,[[ P,] ...])
label : array, shape (M, N,[ P[, ...]])

label : array, shape (M, N,[[ P,] ...])
Integer array of labels with the same shape as `image` (not including
channels).
image : array, shape (M, N,[[[ P,] ...,] 3]), optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
image : array, shape (M, N,[[[ P,] ...,] 3]), optional
image : array, shape (M, N,[ P,[ ...,][ 3]), optional

@soupault soupault mentioned this pull request Dec 28, 2019
9 tasks
@jni
Copy link
Member Author

jni commented Dec 29, 2019

@soupault thanks for the blast from the past review! =) I'll try to pick this one up again soon. Yikes! LOL

@IssamLaradji
Copy link

any updates on this? this is very useful!

@rfezzani
Copy link
Member

I don't know if this PR is still relevant (please see #4464).

Base automatically changed from master to main February 18, 2021 18:23
@grlee77 grlee77 added the 📜 type: API Involves API change(s) label Mar 27, 2022
@grlee77 grlee77 modified the milestones: 0.17, skimage2 Mar 27, 2022
@grlee77
Copy link
Contributor

grlee77 commented Mar 27, 2022

I don't know if this PR is still relevant (please see #4464).

A subset of this was done elsewhere (the bg_label default was changed from -1 to 0). I am also not a big fan of using DEFAULT and think the we should use the more recently developed decorators for deprecations, but other items here are still relevant:

The proposed API change from:
bg_label->background
bg_color->background_color
seems reasonable to me and has not been done.

The other changes here are

  • introduction of a relabel keyword-only argument to label2rgb
  • more descriptive error message

If there is consensus that we should still work on these changes, I am happy to help update this PR along with another performance-based PR for label2rgb in #3344.

@rfezzani
Copy link
Member

I'm not a big fan of DEFAULT neither. Otherwise, the other suggestions are fine by me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants