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

Shifting center after resampling real array #53

Open
hzarei4 opened this issue Feb 17, 2025 · 7 comments
Open

Shifting center after resampling real array #53

hzarei4 opened this issue Feb 17, 2025 · 7 comments

Comments

@hzarei4
Copy link
Contributor

hzarei4 commented Feb 17, 2025

Hello,

I wonder why the array's center is shifted after resampling to a larger size...

for example:

julia> a = disc(Float32, (11, 11), 0.2);

julia> argmax(a)
CartesianIndex(6, 6)

julia> b = resample(a, (111, 111));

julia> argmax(b)
CartesianIndex(51, 51)

The peak of the resampled array is at (51, 51) and not:

julia> size(b) 2
(55, 55)
@roflmaostc
Copy link
Member

The reason is that we do resample around the first pixel (1,1, ...).

Try fftshift(resample(ifftshift(a), (111, 111))));

@roflmaostc
Copy link
Member

Maybe you could add a simple example to this documentation page?

https://nanoimaging.de/FourierTools.jl/dev/resampling/

@hzarei4
Copy link
Contributor Author

hzarei4 commented Feb 17, 2025

Thanks! It solved the problem.
Ok, I will add this to the documentation page. Or I can include this in the resample function (?)

@roflmaostc
Copy link
Member

We could add it as a flag shift_center=false and then exactly doing those changes.
If you could do a PR, I can review :)

@RainerHeintzmann
Copy link
Member

I agree. Such a flag would really be useful. However, we may think about how to implement this best. Two extra fftshift sound unnecessarily complex.

@roflmaostc
Copy link
Member

On the other hand, the whole algorithm calculates in a O(n*log(n)) complexity whereas a fftshift is only O(n). I'd argue, we keep the default the same, and otherwise it's slighty more expensive but barely noticeable (only memory is a bit higher).

@RainerHeintzmann
Copy link
Member

We can compare both options. Either a double shift or a separable multiplication in Fourier space.

@RainerHeintzmann RainerHeintzmann changed the title Shifting center after reampling real array Shifting center after resampling real array Feb 23, 2025
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