Skip to content

phase_cross_correlation returns tuple instead of np.array when disambiguate=True #7083

Closed

Description

@m-albert

Description:

According to its documentation, ski.registration.phase_cross_correlation returns a numpy array as a shift. However, when using the function with disambiguate=True, a tuple is returned.

Way to reproduce:

import numpy as np
import skimage as ski

im = np.random.randint(0, 100, ((10,10)))

r1 = ski.registration.phase_cross_correlation(im, im)
assert(isinstance(r1[0], np.ndarray)) # r1[0] is a numpy array

r2 = ski.registration.phase_cross_correlation(im, im, disambiguate=True)
assert(isinstance(r2[0], np.ndarray)) # r2[0] is a tuple

Version information:

3.10.12 (main, Jul  5 2023, 15:02:25) [Clang 14.0.6 ]
macOS-12.6-arm64-arm-64bit
3.10.12 (main, Jul  5 2023, 15:02:25) [Clang 14.0.6 ]
macOS-12.6-arm64-arm-64bit
scikit-image version: 0.21.0
numpy version: 1.25.2

Activity

  1. m-albert commented on Aug 2, 2023

    @m-albert
    ContributorAuthor

    I was going to create a PR with a fix, but will postpone that for now as I'm getting strange ninja related errors on my M2 when trying to set up skimage testing.

  2. jni commented on Aug 2, 2023

    @jni
    Member

    😬

    Well a PR would be most welcome anyway! 😅

  3. decorouz commented on Aug 29, 2023

    @decorouz
    Contributor

    Hi @m-albert! May I create a PR that closes this issue?

    The bug seems to be from the _disambiguate_shift function which returns a 'tuple of floats'. One possible fix I have explored is to make _disambiguate_shift return an ndarray instead of a tuple. This is a more robust approach. Would require changes to the test suite as well.
    The other would be to update the if block like this.

    if disambiguate:
            if space.lower() != 'real':
                reference_image = ifftn(reference_image)
                moving_image = ifftn(moving_image)
            shift = np.array(_disambiguate_shift(reference_image, moving_image, shift), dtype=np.float32)

    The latter is an easy work around. Not sure it is the best approach. I would appreciate an input

  4. m-albert commented on Aug 29, 2023

    @m-albert
    ContributorAuthor

    Hey @decorouz, thanks for working on this :) I haven't had the time and happy to help.

    One possible fix I have explored is to make _disambiguate_shift return an ndarray instead of a tuple.

    I agree that that's probably the best fix, since there's no reason for a shift sometimes being a tuple and sometimes a numpy array.

    Ideally the fixed return type could also be checked for in the tests.

    I'd guess scikit-image would welcome your PR on this :)

  5. lagru commented on Sep 20, 2023

    @lagru
    Member

    Fixed in #7112.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions