Octave/Matlab高提升滤波实现:高斯低通模糊后锐化代码求助
Gaussian Low-Pass + High-Boost Filtering for Image Sharpening (Octave/Matlab)
Hey there! Let's wrap up your image processing pipeline and make sure that high-boost filtering sharpens that blurry moon just right. Your initial Gaussian low-pass implementation is solid—let's fix the loose ends and walk through the high-boost step in detail.
First, Fix the Low-Pass Output (Critical Step!)
Your current InverseGauss is a complex array from the inverse FFT, so we need to extract the real component and normalize it back to the 0-255 range (and convert to uint8 for proper image display) before moving to high-boost filtering.
Complete Code with High-Boost Implementation
Here's the full, polished version of your code with explanatory comments:
% Load the blurry input image I = imread('blurry-moon.tif'); figure('Name','Image Processing Pipeline'); % Step 1: Gaussian Low-Pass Filter in Frequency Domain A = fft2(double(I)); Ashift = fftshift(A); [m, n] = size(A); R = 10; % Adjust this radius for more/less smoothing X = 0:n-1; Y = 0:m-1; [X, Y] = meshgrid(X, Y); Cx = 0.5*n; Cy = 0.5*m; % Gaussian low-pass filter kernel LoF = exp(-((X-Cx).^2 + (Y-Cy).^2) ./ (2*R^2)); % Apply filter and inverse transform Gauss = Ashift .* LoF; GaussShift = ifftshift(Gauss); InverseGauss = ifft2(GaussShift); % Clean up the low-pass result (remove complex artifacts, normalize) I_lowpass = real(InverseGauss); I_lowpass = uint8(mat2gray(I_lowpass)*255); % Convert back to 0-255 uint8 % Step 2: High-Boost Filtering A_boost = 2; % Boost factor (1 = no sharpening, >1 = increasing sharpness) % Convert images to double for safe arithmetic operations I_double = double(I); I_lowpass_double = double(I_lowpass); % Calculate high-pass component (original - low-pass) I_highpass = I_double - I_lowpass_double; % Apply high-boost formula: J = I + (A-1)*I_highpass J = I_double + (A_boost - 1)*I_highpass; % Clamp values to 0-255 to avoid overflow/underflow, convert back to uint8 J = uint8(max(min(J, 255), 0)); % Display all stages for visual comparison subplot(1,3,1); imshow(I); title('Original Blurry Image'); subplot(1,3,2); imshow(I_lowpass); title('Gaussian Low-Pass Filtered'); subplot(1,3,3); imshow(J); title(['High-Boost Sharpened (A=',num2str(A_boost),')']);
Key Technical Notes & Tuning Tips
- Gaussian Radius (
R): IncreasingRwill smooth the image more, which means the subsequent high-pass component will capture stronger edge details. Try values between 5 and 20 to find the sweet spot for your moon image. - Boost Factor (
A_boost):A_boost = 1returns the original image (no sharpening)- Values between 1.5 and 3 are ideal for subtle to moderate sharpening
- Avoid values >4, as they'll amplify noise and create unnatural, over-sharpened edges—test incrementally!
- Data Type Safety: Always convert
uint8images todoublebefore arithmetic operations to avoid integer overflow. Theclampstep (max(min(J,255),0)) ensures your final image stays within valid pixel value ranges. - No Ringing Artifacts: Unlike ideal low-pass filters, Gaussian low-pass filters don't cause ringing around edges, making them perfect for this sharpening workflow.
内容的提问来源于stack exchange,提问作者potu1304
相关产品推荐
相关产品推荐

