Skip to content

Instantly share code, notes, and snippets.

@M0nteCarl0
Created August 3, 2023 08:03
Show Gist options
  • Save M0nteCarl0/cb9106454bb019c6eea8b96ec8cc21af to your computer and use it in GitHub Desktop.
Save M0nteCarl0/cb9106454bb019c6eea8b96ec8cc21af to your computer and use it in GitHub Desktop.
DQE_MTF example
import numpy as np
from scipy.fft import fft2
from scipy.ndimage import sobel, gaussian_filter
from PIL import Image
def compute_dqe(image_path):
# Load the X-ray image
image = Image.open(image_path).convert("L")
image = np.array(image)
# Apply preprocessing steps if necessary
# e.g., denoising, contrast adjustment, histogram equalization
# Compute the noise power spectrum (NPS)
image_fft = fft2(image)
image_power_spectrum = np.abs(image_fft) ** 2
nps = np.mean(image_power_spectrum)
# Compute the modulation transfer function (MTF)
edges = sobel(image)
edges_fft = fft2(edges)
mtf = np.abs(edges_fft) / np.abs(image_fft)
# Compute the Detective Quantum Efficiency (DQE)
dqe = (mtf ** 2) / nps
return dqe
# Example usage
image_path = "path/to/your/xray_image.jpg"
dqe = compute_dqe(image_path)
print("DQE:", dqe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment