fix(v5): default fft spectrum to log magnitude
This commit is contained in:
@@ -354,19 +354,14 @@ def rgb_channel(image, params):
|
||||
|
||||
|
||||
def fft_spectrum(image, params):
|
||||
"""Display the DFT magnitude, log magnitude, or phase spectrum of an image.
|
||||
"""Display the DFT log-magnitude spectrum of an image.
|
||||
|
||||
Use it to understand whether image information is concentrated in low or high frequencies.
|
||||
"""
|
||||
|
||||
gray = to_gray(image).astype(np.float32)
|
||||
spectrum = np.fft.fftshift(np.fft.fft2(gray))
|
||||
mode = params.get("mode", "log_magnitude")
|
||||
if mode == "phase":
|
||||
return gray_to_rgb(normalize_to_uint8(np.angle(spectrum)))
|
||||
magnitude = np.abs(spectrum)
|
||||
if mode == "log_magnitude":
|
||||
magnitude = np.log1p(magnitude)
|
||||
magnitude = np.log1p(np.abs(spectrum))
|
||||
return gray_to_rgb(normalize_to_uint8(magnitude))
|
||||
|
||||
|
||||
@@ -436,7 +431,7 @@ OPERATIONS = [
|
||||
kernel_pair_preview("Sobel", [[-1, -2, -1], [0, 0, 0], [1, 2, 1]], [[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]),
|
||||
], 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("fft_spectrum", "FFT/DFT Spectrum View", CH4, "DFT and FFT", fft_spectrum, formula="Display log(1 + |fftshift(fft2(f))|).", 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),
|
||||
|
||||
Reference in New Issue
Block a user