Skip to content

Updating Fourier similarity to an RMSE of the power spectrum between two images #17

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 56 additions & 21 deletions notebooks/hologram_propagation.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
grad_total_variation
)
from .fourier import (
fourier_image_similarity,
fourier_rmse,
fourier_total_variation
)
from .wavelet import (
Expand All @@ -37,10 +37,10 @@
"grad-ds": gradient_difference_similarity,
"grad-rmse": gradient_rmse,
"laplace-rmse": laplacian_rmse,
"fourier-rmse": fourier_rmse,
"hist-int": histogram_intersection,
#"gpd": gradient_profile_difference,
"hog-pearson": hog_pearson,
"fourier-similarity": fourier_image_similarity,
"wavelet-similarity": wavelet_image_similarity,
"tv": total_variation,
"grad-tv": grad_total_variation,
Expand Down
17 changes: 6 additions & 11 deletions src/fourier.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ def compute_power_spectrum(image):
power_spectrum = np.abs(f_transform) ** 2
return power_spectrum

def fourier_image_similarity(image1, image2):
def fourier_rmse(image1, image2):
# Compute power spectra of both images
power_spectrum1 = compute_power_spectrum(image1)
power_spectrum2 = compute_power_spectrum(image2)

# Compute the normalized cross-correlation between power spectra
cross_correlation = np.real(np.fft.ifft2(np.fft.fft2(power_spectrum1) * np.conj(np.fft.fft2(power_spectrum2))))
cross_correlation /= np.max(cross_correlation)

# The maximum value of the cross-correlation indicates similarity
similarity_score = np.max(cross_correlation)

return similarity_score
# Compute the mean squared error between power spectra
mse = np.mean((power_spectrum1-power_spectrum2)**2)
return np.sqrt(mse)

def fourier_total_variation(image):
f_transform = np.fft.fft2(image)
Expand All @@ -32,5 +27,5 @@ def fourier_total_variation(image):
image1 = camera()
image2 = camera()

similarity_score = fourier_image_similarity(image1, image2)
print("Similarity Score:", similarity_score)
fourier_mse = fourier_mse(image1, image2)
print("Fourier power spectrum MSE:", fourier_mse)