Skip to content

Commit

Permalink
[edit] Clean preprocess function
Browse files Browse the repository at this point in the history
  • Loading branch information
LouConreux committed Jan 24, 2025
1 parent a46a153 commit 5a146ad
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions lute/tasks/bayfai.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,12 +1298,13 @@ def _preprocess_powder(
Powder image to use for calibration
preprocess : str
Type of preprocessing technique
Available preprocessing: gradient "magnitude" powder, "gradient" sigmoid powder,
"high-pass" filtering, "CAE" convolutional autoencoding (later)
Available preprocessing:
"canny": Canny Edge Detection preprocessing
"PyPCA": Principal Component Analysis preprocessing
"""
if preprocess is None:
return powder
elif preprocess == "magnitude":
elif preprocess == "canny":
sigma = 1
calib = gaussian_filter(powder, sigma=sigma)
gradx_calib = np.zeros_like(powder)
Expand All @@ -1316,23 +1317,6 @@ def _preprocess_powder(
) / 2
powder = np.sqrt(gradx_calib**2 + grady_calib**2)
return powder
elif preprocess == "gradient":
sigma = 1
calib = gaussian_filter(powder, sigma=sigma)
gradx_calib = np.zeros_like(powder)
grady_calib = np.zeros_like(powder)
gradx_calib[:-1, :-1] = (
calib[1:, :-1] - calib[:-1, :-1] + calib[1:, 1:] - calib[:-1, 1:]
) / 2
grady_calib[:-1, :-1] = (
calib[:-1, 1:] - calib[:-1, :-1] + calib[1:, 1:] - calib[1:, :-1]
) / 2
powder = gradx_calib + grady_calib
return powder
elif preprocess == "high-pass":
kernel = np.array([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]])
powder = convolve2d(powder, kernel, mode="same", boundary="symm")
return powder
else:
logger.warning(f"Preprocessing technique {preprocess} not recognized.")
return None
Expand Down

0 comments on commit 5a146ad

Please sign in to comment.