Skip to content

Make phase_cross_correlation return ndarray when disambiguate=True - #7112

Merged
lagru merged 9 commits into
scikit-image:mainfrom
decorouz:phase_cross_correlation
Sep 20, 2023
Merged

lagru merged 9 commits into
scikit-image:mainfrom
decorouz:phase_cross_correlation

Conversation

@decorouz

@decorouz decorouz commented Aug 29, 2023 •

Copy link
Copy Markdown
Contributor

Description

ski.registration.phase_cross_correlation returns inconsistent results.
It returns a tuple when disambiguate is set to True but numpy array when set to False. Since there's no reason for a shift to sometimes be a tuple and sometimes a numpy array, this PR attempts to fix this bug #7083 by making the function return numpy array consistently.

Additionally, this gallery example returns a TypeError: can only concatenate tuple (not "int") to tuple when disambiguate is set to True on this line . This PR also fixed the error.

Checklist

Release note

Summarize the introduced changes in the code block below in one or a few sentences. The
summary will be included in the next release notes automatically:

Make `skimage.registration.phase_cross_correlation` consistently return an array even if
`disambiguate=True`.

@jarrodmillman jarrodmillman added the 🩹 type: Bug fix Fixes unexpected or incorrect behavior label Sep 7, 2023

@mkcor mkcor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for fixing this, @decorouz! I can't find the TypeError in the "Image Registration" gallery example though...

):
real_shift_acc.append(pos_shift if sl.stop is None else neg_shift)
if not subpixel:
real_shift = tuple(map(int, real_shift_acc))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And since real_shift was supposed to be a 'tuple of float,' it's not clear why this mapping to integer was even performed...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am also not seeing an immediate reason in #6617 why this mapping to int is performed. @jni do you remember?

@decorouz

decorouz commented Sep 9, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for fixing this, @decorouz! I can't find the TypeError in the "Image Registration" gallery example though...

I have updated the PR description to better explain the TypeError. With current implementation, this gallery example result in a TypeError when disambiguate=True.

@lagru lagru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this. I think the test is not actually testing that the bug is fixed though. Otherwise, nothing major.

):
real_shift_acc.append(pos_shift if sl.stop is None else neg_shift)
if not subpixel:
real_shift = tuple(map(int, real_shift_acc))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am also not seeing an immediate reason in #6617 why this mapping to int is performed. @jni do you remember?

@m-albert m-albert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing this @decorouz :)

@decorouz
decorouz requested a review from lagru September 10, 2023 13:47

@lagru lagru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good IMO.

@mkcor mkcor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I think that's what I meant. Though, right now we don't need to append

shift = np.asarray(shift)

because this function already returns an array with

return np.array(real_shift_acc)

@lagru well, it's EITHER/OR, of course (not both). By 'right now,' I guess that you mean 'with this PR,' since only this PR is adding return np.array(real_shift_acc) (but this PR isn't merged yet... For me, 'right now' typically means 'on current main').

So,

  • EITHER this PR keeps return np.array(real_shift_acc) but then line 145 needs to be updated
-real_shift : sequence of floats
+real_shift : ndarray
  • OR this PR updates the code within phase_cross_correlation as discussed.

@pep8speaks

Copy link
Copy Markdown

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

Line 256:1: E302 expected 2 blank lines, found 1
Line 266:13: E126 continuation line over-indented for hanging indent

@lagru

lagru commented Sep 20, 2023

Copy link
Copy Markdown
Member

All CI failures look related to #7140. As the test suite itself is passing fine, I am going ahead and merge this.

@lagru
lagru merged commit 3cd5270 into scikit-image:main Sep 20, 2023
@lagru

lagru commented Sep 20, 2023

Copy link
Copy Markdown
Member

Thanks everyone!

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

Labels

🩹 type: Bug fix Fixes unexpected or incorrect behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants