Skip to content

Commit

Permalink
add nxcorr
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiede committed Sep 27, 2023
1 parent d93029e commit 6d1e710
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/divergences.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export divergence
export divergence, nxcorr

"""
$(TYPEDEF)
Expand Down Expand Up @@ -240,3 +240,23 @@ function divergence_point(::LeastSquares, p, q)
end

@inline normalize_div(::LeastSquares, div) = div


"""
$(SIGNATURES)
Returns the normalized cross correlation (NXCORR) between `img1` and `img2`.
NXCORR is defined as
NXCORR(n, m) = (Nσₙσₘ) Σᵢ (nᵢ - μₙ)(mᵢ - μₘ)
where `n` and `m` are the two images `μ` is the mean and `σ` is the pixelwise standard deviation
"""
function nxcorr(img1::IntensityMap{T}, img2::IntensityMap{T}) where {T<:Real}
m1, s1 = mean_and_std(img1)
m2, s2 = mean_and_std(img2)
xcorr = sum(zip(img1, img2)) do (I, J)
(I - m1)*(J - m2)
end
return xcorr/(length(img1)*s1*s2)
end

0 comments on commit 6d1e710

Please sign in to comment.