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

Add simple ccorr method to FourierTools #18

Merged
merged 2 commits into from
Aug 11, 2022
Merged

Add simple ccorr method to FourierTools #18

merged 2 commits into from
Aug 11, 2022

Conversation

roflmaostc
Copy link
Member

No description provided.

@roflmaostc
Copy link
Member Author

@RainerHeintzmann @LukasHasf a simple ccorr method first.

We can also add more advanced one like plan_ccorr later

@RainerHeintzmann
Copy link
Member

Thanks for starting this branch!
Since correlation is really just adding a conj. to one of the arrays in Fourier space and we would ideally want all the convolution specializations to also exist as correlations, I would suggest to implement this optional conj. as a named argument within the conv method. This would keep code replication at a minimum at a minimal combinatorial explosion overhead. The various corr methods should still be in a separate file, but only call the conv methods with the named argument correlate=true. They could use smart argument forwarding, which should be easy to maintain.

@roflmaostc
Copy link
Member Author

Yes it is but the final fftshift is for example not included and not needed in conv hence you only replace 1 line with a call to a different function.

@RainerHeintzmann
Copy link
Member

Maybe I am missing something here, but should not corr and conv have the same options of applying final Fourier shifts or not? I would think that there is no fundamental difference between the two except for the conj. operation.

@roflmaostc
Copy link
Member Author

There kind of is:

julia> conv(x,y) = irfft(rfft(x) .* rfft(y), size(x,1))
conv (generic function with 2 methods)

julia> conv([1,2,3,4,5],[1,0,0,0,0])
5-element Vector{Float64}:
 1.0
 2.0
 3.0
 4.0
 5.0

julia> ccorr(x,y) = irfft(rfft(x) .* conj.(rfft(y)), size(x,1))
ccorr (generic function with 1 method)

julia> ccorr([1,2,3,4,5],[1,2,3,4,5])
5-element Vector{Float64}:
 55.0
 45.0
 40.0
 40.0
 45.0

The conv is oriented the same as the image, the ccorr is centered around the first entry.

@RainerHeintzmann
Copy link
Member

thanks for the example. However, I think this is what to expect. If the "zero" is in the top left corner and you are correlating two equal array, than the result is zero shift, which has a maximum at zero, i.e. the top left corner. Moving this to the middle seems inconsistent to me.

@roflmaostc
Copy link
Member Author

Yes, I agree.
That's why there is a centeredBool if you Want to have it shifted

@roflmaostc roflmaostc merged commit 1482453 into main Aug 11, 2022
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

Successfully merging this pull request may close these issues.

2 participants