Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

Frequency-Domain Image Enhancement Using Butterworth, Gaussian, and Laplacian Filters

Notes 1

Frequency-domain filtering operates by transforming spatial image data into its spectral representation, modifying amplitude components according to a defined transfer function, and reconstructing the spatial image via inverse transformation. This approach enables precise control over noise suppression, edge extraction, and contrast enhancement.

Mathematical Foundations of Frequency Filters

Butterworth Low-Pass Filter (BLPF): The BLPF provides a smooth transition between the passband and stopband, avoiding the ringing artifacts associated with ideal step filters. Its frequency response is defined by: $$ H(u,v) = \frac{1}{1 + \left( \frac{D(u,v)}{D_0} \right)^{2n}} $$ where $D(u,v)$ represents the Euclidean distance from the frequency origin, $D_0$ denotes the cutoff radius, and $n$ specifies the filter order. Higher values of $n$ appproximate an ideal cutoff but increase computational overhead.

Gaussian High-Pass Filter (GHPF): Constructed from a Gaussian distribution, the GHPF attenuates low-frequency components while preserving high-frequency details. The transfer function is expressed as: $$ H(u,v) = 1 - e^{-\frac{D(u,v)^2}{2\sigma^2}} $$ Here, $\sigma$ governs the bandwidth and sharpness of the transition. The filter effectively isolates edges and fine textures by blocking the dominant low-frequency background information.

Frequency-Domain Laplacian Operator: The Laplacian enhances regions with rapid intensity variations through second-order differentiation. In the frequency domain, the operator corresponds to: $$ H(u,v) = -4\pi^2 D(u,v)^2 $$ Applying this transfer function amplifies high-frequency spectral components, making it highly effective for image sharpening. The resulting enhanced image is typically reconstructed by adding the filtered output to the original spatial data.

Implementation Framwork

The following MATLAB implementation demonstrates the complete pipeline for spectral shifting, distance matrix generation, filter application, and image reconstruction. The code replaces iterative loops with vectorized indexing to improve execution speed and maintain readability.

function frequency_domain_enhancement()
    % Load and preprocess test images
    base_img = im2double(imread('lena.bmp'));
    if size(base_img, 3) == 3
        base_img = rgb2gray(base_img);
    end
    
    noisy_img = imnoise(base_img, 'gaussian', 0, 0.01);
    
    % Compute FFT and shift zero-frequency to center
    F_orig = fftshift(fft2(base_img));
    F_noisy = fftshift(fft2(noisy_img));
    
    % Generate distance matrix
    [h, w] = size(base_img);
    [U, V] = meshgrid((-w/2):(w/2)-1, (-h/2):(h/2)-1);
    dist_matrix = sqrt(U.^2 + V.^2);
    
    % Phase 1: Second-order Butterworth Low-Pass Smoothing
    cutoff_lpf = 30;
    order_lpf = 2;
    H_butter = 1 ./ (1 + (dist_matrix ./ cutoff_lpf).^(2 * order_lpf));
    F_smoothed = F_noisy .* H_butter;
    img_butter = real(ifft2(ifftshift(F_smoothed)));
    
    % Phase 2: Gaussian High-Pass Sharpening with Multiple Radii
    radii = [50, 450];
    for idx = 1:length(radii)
        sigma_val = radii(idx);
        H_gauss = 1 - exp(-(dist_matrix.^2) ./ (2 * sigma_val^2));
        F_high = F_orig .* H_gauss;
        img_gauss = real(ifft2(ifftshift(F_high)));
        
        % High-frequency boost via addition
        boosted_img = base_img + abs(img_gauss);
        
        figure('Name', sprintf('GHPF Radius %d', sigma_val));
        imshowpair(base_img, boosted_img, 'montage');
        title(sprintf('Original vs Enhanced (σ=%.0f)', sigma_val));
    end
    
    % Phase 3: Laplacian Frequency Sharpening
    H_lap = -(U.^2 + V.^2);
    F_lap_result = F_orig .* H_lap;
    lap_spatial = real(ifft2(ifftshift(F_lap_result)));
    
    % Normalize and scale Laplacian response
    lap_norm = mat2gray(lap_spatial);
    enhanced_lap = imadd(base_img, im2uint8(lap_norm * 0.8));
    
    figure('Name', 'Laplacian Enhancement');
    subplot(1,3,1); imshow(base_img); title('Input');
    subplot(1,3,2); imshow(lap_norm); title('Laplacian Response');
    subplot(1,3,3); imshow(enhanced_lap); title('Sharpened Output');
end

Spectral Analysis and Visual Outcomes

Applying the Butterworth low-pass filter to the noisy input effectively suppresses high-frequency Gaussian noise components. The spectral visualization confirms a significant reduction in peripheral frequency magnitudes. However, aggressive attenuation of the high-frequency band inevitably smooths fine textures and reduces overall sharpness. Adjusting $D_0$ upward retains more structural details but reintroduces residual noise, demonstrating the inherent trade-off between denoising and detail preservation.

The Gaussian high-pass implementation successfully isolates edge information by eliminating the dominant low-frequency spectrum. Increasing the cutoff radius $\sigma$ progressively removes mid-range frequencies, resulting in outputs that emphasize only sharpest boundaries. Overlaying the filtered high-frequency response onto the original spatial image yields a visually distinct sharpening effect, where edges and textures exhibit increased contrast without altering the underlying tonal distribution.

The Laplacian transfer function produces a direct second-derivative response in the frequency domain. The resulting spatial image highlights regions of rapid intensity change, effectively mapping edges and fine structures. When scaled and added to the source image, the Laplacian response enhances micro-details and boundary definition. This technique is particularly effective for restoring clarity to slightly blurred inputs, as the mathematical operator directly targets discontinuities in pixel gradients.

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Skipping Errors in MySQL Asynchronous Replication

When a replica halts because the SQL thread encounters an error, you can resume replication by skipping the problematic event(s). Two common approaches are available. Methods to Skip Errors 1) Skip a...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.