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

masked phase_cross_correlation not working in 1D #5458

Closed
patquem opened this issue Jul 6, 2021 · 4 comments
Closed

masked phase_cross_correlation not working in 1D #5458

patquem opened this issue Jul 6, 2021 · 4 comments

Comments

@patquem
Copy link
Contributor

patquem commented Jul 6, 2021

When working with 1D array, phase_cross_correlation without any mask works.
But when adding masks (reference_mask or moving_mask), the cross_correlate_masked() called function makes the calculation failed.
Indeed, this function seems to be designed typically for 2D arrays.

Is it possible to extend this function to any dimension (or at less to 1D) ?
Thanks

scikit-image : version 1.8.2

  File "...\lib\site-packages\skimage\registration\_masked_phase_cross_correlation.py", line 174, in cross_correlate_masked
    moving_image.shape[axis] - 1
IndexError: tuple index out of range
@grlee77
Copy link
Contributor

grlee77 commented Jul 7, 2021

Thanks for reporting. I will take a look. We do generally try to support n-dimensional images when possible.

@mkcor
Copy link
Member

mkcor commented Oct 20, 2021

Could this relate to #5138?

@grlee77
Copy link
Contributor

grlee77 commented Oct 20, 2021

I think this has since been resolved (probably by #5559). I just ran the following example and it worked:

import numpy as np

from pywt import data
from skimage import registration

x = data.ecg()
x2 = np.roll(x, 25)

shifts = registration.phase_cross_correlation(
    x, x2, upsample_factor=1, space="real", return_error=False,
    reference_mask=None, moving_mask=None
)
print(f"shifts={shifts}")

mask_x = np.ones_like(x)
mask_x[:10] = 0
mask_x[-10:] = 0

shifts = registration.phase_cross_correlation(
    x, x2, upsample_factor=1, space="real", return_error=False,
    reference_mask=mask_x, moving_mask=mask_x
)
print(f"shifts (masked)={shifts}")

Both the masked and unmasked cases give shifts of array([-25.]) as expected.

I will close, but please reopen if you find a case where this does not work.

@grlee77 grlee77 closed this as completed Oct 20, 2021
@grlee77
Copy link
Contributor

grlee77 commented Oct 20, 2021

Could this relate to #5138?

That is a separate issue and still exists. In the unmasked case you get three outputs when return_error=True, but the error and phase difference outputs are never returned in the masked case regardless of the return_error setting. That is not very nice and is probably something to revisit for the skimage2 API

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

No branches or pull requests

3 participants