Skip to content

Commit

Permalink
Use a blackman window instead of a Gaussian
Browse files Browse the repository at this point in the history
  • Loading branch information
dedean16 committed Nov 22, 2024
1 parent d45b33d commit fe35973
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions openwfs/calibration/fringe_analysis_slm_calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(
self.gray_values = gray_values

def execute(self) -> Tuple[nd, ArrayLike, nd]:
dtype = self.camera.read().dtype # Read one frame to find dtype
dtype = self.camera.read().dtype # Read one frame to find dtype
frames = np.zeros((len(self.gray_values), *self.camera.data_shape), dtype=dtype)

# Record a camera frame for every gray value
Expand Down Expand Up @@ -104,7 +104,7 @@ def get_dominant_frequency(self, img_data, dc_skip, std_factor=0.5):
std_factor: Multiplier for the Gaussian window std to suppress edge effects. See gaussian_window
"""
shape = img_data.shape[-2:]
G = self.gaussian_window(shape, std_factor)
G = self.blackman_window(shape)

fft_data = np.fft.fft2(G * img_data, axes=(-2, -1))

Expand All @@ -122,26 +122,21 @@ def get_dominant_frequency(self, img_data, dc_skip, std_factor=0.5):
return fft_data[:, *max_idx_2d]

@staticmethod
def gaussian_window(shape, std_factor):
def blackman_window(shape):
"""
Generates a 2D Gaussian window of requested shape.
Generates a 2D Blackman window of requested shape.
Args:
shape: Shape of the Gaussian window
std_factor: Standard deviation multiplier. (1 -> std = window size)
shape: Shape of the Blackman window
Returns:
2D numpy array of shape (M, N), the Gaussian window
2D numpy array of shape (M, N), the Blackman window
"""
M, N = shape

# Standard deviations
std_x = (N/2) * std_factor
std_y = (M/2) * std_factor
# Create 1D Blackman windows
blackman_x = np.blackman(N)
blackman_y = np.blackman(M)

# Coordinate arrays centered at zero
x = np.arange(N).reshape(1, -1) - (N-1)/2
y = np.arange(M).reshape(-1, 1) - (M-1)/2

# Return Gaussian window
return np.exp(-((x**2) / (2 * std_x**2) + (y**2) / (2 * std_y**2)))
# Create 2D Blackman window by outer product
return np.outer(blackman_y, blackman_x)

0 comments on commit fe35973

Please sign in to comment.