fix(v5): reconstruct inverse fft from saved spectrum

This commit is contained in:
2026-07-09 15:01:47 +03:30
parent ca447c71cc
commit 30e1d250ef
5 changed files with 157 additions and 18 deletions

View File

@@ -371,21 +371,12 @@ def fft_spectrum(image, params):
def inverse_fft_reconstruction(image, params):
"""Reconstruct an image with real(ifft2(ifftshift(fftshift(fft2(image))))).
"""Placeholder for inverse FFT reconstruction from a saved FFT state.
Use it to demonstrate that FFT followed by inverse FFT recovers the image when no filter is applied.
The service layer handles this operation because it needs the complex FFT data saved by the FFT action.
"""
def reconstruct_channel(channel):
source = channel.astype(np.float32)
spectrum = np.fft.fftshift(np.fft.fft2(source))
reconstructed = np.real(np.fft.ifft2(np.fft.ifftshift(spectrum)))
return np.round(np.clip(reconstructed, 0, 255)).astype(np.uint8)
if image.ndim == 2:
return reconstruct_channel(image)
channels = [reconstruct_channel(image[:, :, idx]) for idx in range(image.shape[2])]
return np.stack(channels, axis=2)
raise ProcessingError("Inverse FFT Reconstruction must be applied to an FFT/DFT Spectrum View state.")
def operation(id, label, chapter, slide_group, func, params=None, supports="both", matrices=None, formula="", repeatable=True):
@@ -446,7 +437,7 @@ OPERATIONS = [
], formula="Gradient image = abs(imfilter(f,Gx)) + abs(imfilter(f,Gy))."),
operation("high_boost", "High-Boost / Edge Emphasis", CH3, "High-Boost Filtering", high_boost_slide, {"A": float_param(1.5, 1, 6, 0.1, description="Boost factor A, where A >= 1."), "K": odd_param(3, 35, description="Odd averaging mask size used for the blurred image.")}, formula="f_hb = A f - blurred(f)."),
operation("fft_spectrum", "FFT/DFT Spectrum View", CH4, "DFT and FFT", fft_spectrum, {"mode": select_param("log_magnitude", ["magnitude", "log_magnitude", "phase"], description="Choose magnitude, log magnitude, or phase display.")}, formula="F(u,v) = DFT{f(x,y)}", repeatable=False),
operation("inverse_fft_reconstruction", "Inverse FFT Reconstruction", CH4, "DFT and FFT", inverse_fft_reconstruction, formula="f = real(ifft2(ifftshift(fftshift(fft2(image))))).", repeatable=False),
operation("inverse_fft_reconstruction", "Inverse FFT Reconstruction", CH4, "DFT and FFT", inverse_fft_reconstruction, formula="f = real(ifft2(ifftshift(F))). Apply this to an FFT/DFT Spectrum View state.", repeatable=False),
operation("rgb_to_gray", "Convert to Grayscale", CH6, "Color Conversion", rgb_to_gray_matlab, {"red_weight": float_param(0.299, 0, 1, 0.001, description="R coefficient in gray = aR + bG + cB."), "green_weight": float_param(0.587, 0, 1, 0.001, description="G coefficient in gray = aR + bG + cB."), "blue_weight": float_param(0.114, 0, 1, 0.001, description="B coefficient in gray = aR + bG + cB.")}, formula="gray = 0.299R + 0.587G + 0.114B by default.", repeatable=False),
operation("rgb_channel", "RGB Channel View", CH6, "RGB color model", rgb_channel, {"channel": select_param("r", ["r", "g", "b"], description="Select the RGB channel to view.")}, formula="Show one RGB channel as grayscale.", repeatable=False),
]