8000 API updates before 0.16 by jni · Pull Request #4187 · scikit-image/scikit-image · GitHub
[go: up one dir, main page]

Skip to content

API updates before 0.16 #4187

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

Merged
merged 24 commits into from
Oct 4, 2019
Merged

API updates before 0.16 #4187

merged 24 commits into from
Oct 4, 2019

Conversation

jni
Copy link
Member
@jni jni commented Sep 26, 2019

Description

Using @Carreau's great tool frappuccino, I went through all the new APIs we are releasing in 0.16 and checked that they were where we want them to be. Mostly it was a matter of making some arguments keyword-only.

The only thing missing right now is in the new metrics and registration modules, and also in the new util.compare_images function, some functions use im1, im2, others use im_true, im_test, while compare_images uses image1, image2 and the new optical flow uses image0, image1. Needless to say this is a mess and we should aim to rectify it. Suggestions welcome! My preference is reference_image, target_image.

Checklist

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.
  • Consider backporting the PR with @meeseeksdev backport to v0.14.x

@pep8speaks
Copy link
pep8speaks commented Sep 26, 2019

Hello @jni! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 80:80: E501 line too long (80 > 79 characters)
Line 85:80: E501 line too long (80 > 79 characters)

Comment last updated at 2019-10-04 00:56:05 UTC

@sciunto sciunto self-requested a review September 26, 2019 06:52
@soupault
Copy link
Member
soupault commented Sep 26, 2019

My preference is reference_image, target_image.

I'd maybe prefer image_reference and image_target (more convenient with auto-completion). For the same-order arguments (e.g. in some of the comparison/metric functions), image_0, image_1 would probably be fine.

The PR looks good so far 👍 .

@@ -19,7 +19,7 @@ def _match_cumulative_cdf(source, template):
return interp_a_values[src_unique_indices].reshape(source.shape)


def match_histograms(image, reference, multichannel=False):
def match_histograms(image, reference, *, multichannel=False):
Copy link
Member

Choose a reason for hiding this comment

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

This was released with 0.15, so it is an API change https://scikit-image.org/docs/stable/api/skimage.transform.html#match-histograms

Copy link
Member Author

Choose a reason for hiding this comment

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

No, skimage.exposure.match_histograms is a brand new function! =)

Copy link
Member

Choose a reason for hiding this comment

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

sounds good

def structural_similarity(im1, im2, win_size=None, gradient=False,
data_range=None, multichannel=False,
gaussian_weights=False, full=False, **kwargs):
def structural_similarity(im1, im2,
Copy link
Member

Choose a reason for hiding this comment

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

I thought we didn't like im or img in signatures and prefered image. Should we fix here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, just waiting for the discussion above to settle...

Copy link
Member

Choose a reason for hiding this comment

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

Noticing these im1, im2 as I'm reviewing #6612 and... it hurts my eyes! 😢

I'm adding this item to the list of Pending API changes for 1.0.

`diff` computes the absolute difference between the two images.
`blend` computes the mean value.
`checkerboard` makes tiles of dimension `n_tiles` that display
``'diff'`` computes the absolute difference between the two images.
Copy link
Member

Choose a reason for hiding this comment

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

We must keep single backquotes now... (I'm responsible for the mess...)

Copy link
Member Author

Choose a reason for hiding this comment

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

@sciunto I think actually in this case this is better, because it's a literal string, not an argument name.

Copy link
Member

Choose a reason for hiding this comment

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

You're right, the rendering will be better.

Copy link
Member
@sciunto sciunto left a comment

Choose a reason for hiding this comment

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

I left few comments. Besides that, I'm +1.

@sciunto sciunto added this to the 0.16 milestone Sep 27, 2019
@rfezzani
Copy link
Member

I have a small suggestion concerning the API of optical flow algorithms: since only two values are allowed for the dtype argument (float32 and float64), isn't it better to use a bool argument (single_precision=True for example) to specify which floating point precision to use for the estimation?

@rfezzani
Copy link
Member

Otherwise, both names are fine to me (image_reference, image_target or image_0, image_1), may be the second is shorter, but less explicit...

@lagru
Copy link
Member
lagru commented Sep 27, 2019

since only two values are allowed for the dtype argument (float32 and float64), isn't it better to use a bool argument (single_precision=True for example) to specify which floating point precision to use for the estimation?

Hmm, I think I slightly prefer to keep the dtype argument because it is more flexible. The fact that only two values are allowed is not because it is a "true" flag that modifies the logic of the algorithm (please correct me if I'm wrong) but because those are the limits of the technology used. If in the future another dtype became available we'd have to change the API again. But maybe I'm overthinking it. ;)

Why do you think a flag would be better?

@rfezzani
Copy link
Member

Optical flow will always be estimated as float. Using single or double precision is a matter of treadoff between precision and memory use/computation speed.
Moreover, correct me if I am wrong, but I don't think that float16 or float128 are supported by skimage.
In my opinion, the use of dtype parameter is confusing for the user, he may be tempted to use any other dtype (int, bool or whatever).
The use of dtype also forces a check and the raise of a ValueError if the input dtype is not float...
The use of a flag is in my opinion less confusing and prevents some user errors.

@lagru
Copy link
Member
lagru commented Sep 28, 2019

@rfezzani Thanks for the insights. I don't see the check and raise as a disadvantage. Though I see your point that dtype might indeed be confusing for users who are used to that parameter from NumPy. I'm fine with either option but your suggestion seems to be the better one.

@rfezzani rfezzani mentioned this pull request Sep 30, 2019
9 tasks
@jni
Copy link
Member Author
jni commented Oct 3, 2019

Hi everyone,

After discussing with Stéfan in the community meeting this week, we settled on the following:

  • for comparison functions, image0 and image1 where the metric is in a strong sense symmetric, and image_true and image_test where it is not. (though this could be true_image and test_image, come to think of it)
  • for registration, reference_image and moving_image.

@NelleV has volunteered to be release manager and we've kept her waiting for a while, so I would like everyone who wants to have a say here to have one last review and then (hopefully) click approve. =) If no one has strong objections in the next ~24h, we will start pushing out 0.16 this time tomorrow.

Have a nice day! =)

def _tvl1(image0, image1, flow0, attachment, tightness, nwarp, niter,
tol, prefilter):
def _tvl1(reference_image, moving_image, flow0, attachment, tightness, nwarp,
niter, tol, prefilter):
Copy link
Member

Choose a reason for hiding this comment

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

Referring to your comment on #4154, I suggest to replace niter by num_iter before releasing v0.16 to anticipate ;-)

dtype='float32'):
def optical_flow_tvl1(reference_image, moving_image,
*,
attachment=15, tightness=0.3, nwarp=5, niter=10,
Copy link
Member

Choose a reason for hiding this comment

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

The same here: niter -> num_iter

@soupault
Copy link
Member
soupault commented Oct 3, 2019

for registration, reference_image and moving_image.

How about fixed_image and moving_image instead? There are several votes for that option besides mine - #3544 (comment).

@sciunto
Copy link
Member
sciunto commented Oct 3, 2019

for registration, reference_image and moving_image.

How about fixed_image and moving_image instead? There are several votes for that option besides mine - #3544 (comment).

I like reference...

@jni
Copy link
Member Author
jni commented Oct 3, 2019

@soupault

How about fixed_image and moving_image instead?

Stéfan preferred reference, and I agree. (And so does @sciunto it turns out! 😂) Ultimately I think the most important thing here is that it's unambiguous, and I think reference/moving meets that criterion.

@soupault
Copy link
Member
soupault commented Oct 3, 2019

it's unambiguous

I agree with that. Let's keep reference then. 👍

Copy link
Contributor
@grlee77 grlee77 left a comment

Choose a reason for hiding this comment

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

I am +1 on the naming conventions chosen here. I think I would have used image1, image2 instead of (image0, image1), but it is not a strong preference.

Once the test failures are resolved and the last bits completed, I approve merging this.

I commented on one of the bugs. I saw another one in the logs related to variation_of_information:

    def test_vi():
        im_true = np.array([1, 2, 3, 4])
        im_test = np.array([1, 1, 8, 8])
>       assert_equal(np.sum(variation_of_information(im_true, im_test)), 1)

c:\hostedtoolcache\windows\python\3.7.4\x64\lib\site-packages\skimage\metrics\tests\test_segmentation_metrics.py:29: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

image0 = array([1, 2, 3, 4]), image1 = array([1, 1, 8, 8])

    def variation_of_information(image0=None, image1=None, *, table=None,
                                 ignore_labels=()):
        """Return symmetric conditional entropies associated with the VI. [1]_
    
        The variation of information is defined as VI(X,Y) = H(X|Y) + H(Y|X).
        If X is the ground-truth segmentation, then H(X|Y) can be interpreted
        as the amount of under-segmentation and H(X|Y) as the amount
        of over-segmentation. In other words, a perfect over-segmentation
        will have H(X|Y)=0 and a perfect under-segmentation will have H(Y|X)=0.
    
        Parameters
        ----------
        image0, image1 : ndarray of int
            Label images / segmentations, must have same shape.
        table : scipy.sparse array in csr format, optional
            A contingency table built with skimage.evaluate.contingency_table.
            If None, it will be computed with skimage.evaluate.contingency_table.
            If given, the entropies will be computed from this table and any images
            will be ignored.
        ignore_labels : sequence of int, optional
            Labels to ignore. Any part of the true image labeled with any of these
            values will not be counted in the score.
    
        Returns
        -------
        vi : ndarray of float, shape (2,)
            The conditional entropies of image1|image0 and image0|image1.
    
        References
        ----------
        .. [1] Marina Meil\u0103 (2007), Comparing clusterings\u2014an information based
            distance, Journal of Multivariate Analysis, Volume 98, Issue 5,
            Pages 873-895, ISSN 0047-259X, :DOI:`10.1016/j.jmva.2006.11.013`.
        """
        h0g1, h1g0 = _vi_tables(image0, image1, table=table,
>                               ignore_labels=ignore_labels, normalize=True)
E       TypeError: _vi_tables() got an unexpected keyword argument 'normalize'

@rfezzani rfezzani mentioned this pull request Oct 3, 2019
9 tasks
@stefanv
Copy link
Member
stefanv commented Oct 4, 2019

+1; @jni one observation: in comparison functions, we have f(im_true, im_test), but registration is f(image, reference). This seems like the opposite way around. Probably nothing we can do about that at this point, but feels inconsistent.

@jni
Copy link
Member Author
jni commented Oct 4, 2019

@stefanv huh? Optical flow uses reference, moving?

@jni
Copy link
Member Author
jni commented Oct 4, 2019

Ditto for feature.register_translation, which should be moved to registration but I think that can wait until the next release.

@stefanv
Copy link
Member
stefanv commented Oct 4, 2019

@jni
Copy link
Member Author
jni commented Oct 4, 2019

Ah. Sure but that's not registration. =) I think in that case it makes more sense, because you are modifying the input image to match a reference. The output is a modified version of the first input. In registration, the output is something that relates the first input to the second. So I don't think it's a critical inconsistency. But anyway, thanks for pointing it out! It's something to consider for 1.0 I think. =)

@stefanv
Copy link
Member
stefanv commented Oct 4, 2019

👍 I'd merge, but you said you had one more thing to change?

@jni jni merged commit 579c4b8 into scikit-image:master Oct 4, 2019
@jni
Copy link
Member Author
jni commented Oct 4, 2019
1CF5

Nope, all done. =P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ Priority This issue or PR should be given priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0