EE 4780 Bilateral Filter Bilateral Filter K is the normalization constant K x N e I ( y ) I ( x ) 2 / 2 r2 y x / 2 d2 2 e y x N Intensity (range) proximity ˆI ( x) 1 K x N Spatial (domain) proximity I ( y ) I ( x ) / 2 r2 y x / 2 d2 2 2 e e I ( y) y x N Bahadir K. Gunturk N is a fixed value used to define the spatial neighborhood of the filter 2 Bilateral Filter – Matlab implementation n=1:1:500; % Generate a vector from 1 to 500; the increment is 1. I0=zeros(size(n)); % Generate a vector of zeros; the size of the vector is equal to the size of n. I0(1:250)=15; I0(251:end)=10; % Set the first 250 values to 15, and the rest to 10. I = I0 + 0.5*randn(size(I0)); % 0.5 is the standard deviation of the noise figure; subplot(2,1,1); plot(n,I0); axis ([190 310 6 18]); title('Original signal'); subplot(2,1,2); plot(n,I); axis ([190 310 6 18]); title('Noisy signal'); Bahadir K. Gunturk 3 Bilateral Filter – Matlab implementation sigma_d=10; N=round(4*sigma_d); % N determines the spatial neighborhood sigma_r=1.3; d = -N:1:N; weights_d = exp(-d.*d/(2*sigma_d*sigma_d)); ˆI ( x) 1 K x N I ( y ) I ( x ) / 2 r2 y x / 2 d2 2 2 e e y x N The weights depend on the spatial distance (to the center pixel x) only; therefore, it is calculated once and saved. Bahadir K. Gunturk 4 I ( y) Bilateral Filter – Matlab implementation sigma_d=10; N=round(4*sigma_d); % N determines the spatial neighborhood sigma_r=1.3; d = -N:1:N; weights_d = exp(-d.*d/(2*sigma_d*sigma_d)); ˆI ( x) 1 K x N I ( y ) I ( x ) / 2 r2 y x / 2 d2 2 2 e e I ( y) y x N x=260; % An example pixels = I(x-N:x+N); % Put the pixels within the neighborhood of the center pixel into a vector. weights = weights_d .* exp(-(pixels-I(x)).*(pixels-I(x))/(2*sigma_r*sigma_r)) + 0.0001; Add a small number in case weights=0; weights = weights./sum(weights); Bahadir K. Gunturk 5 Bilateral Filter – Matlab implementation sigma_d=10; N=round(4*sigma_d); % N determines the spatial neighborhood sigma_r=1.3; d = -N:1:N; weights_d = exp(-d.*d/(2*sigma_d*sigma_d)); ˆI ( x) 1 K x N I ( y ) I ( x ) / 2 r2 y x / 2 d2 2 2 e e y x N x=260; pixels = I(x-N:x+N); % Put the pixels within the neighborhood of the center pixel into a vector. weights = weights_d .* exp(-(pixels-I(x)).*(pixels-I(x))/(2*sigma_r*sigma_r)) + 0.0001; weights = weights./sum(weights); % Normalize the weights so that its sum is equal to 1. I_output(x) = sum(weights.*pixels); Bahadir K. Gunturk 6 I ( y) Bilateral Filter figure; plot([x-N:x+N],weights) Bahadir K. Gunturk 7 Bilateral Filter – Matlab implementation d = -N:1:N; weights_d = exp(-d.*d/(2*sigma_d*sigma_d)); % Repeat for all pixels I_output = I; for i=1+N:length(I)-N, % Be careful with the borders; do not exceed the dimensions. pixels = I(i-N:i+N); weights = weights_d .* exp(-(pixels-I(i)).*(pixels-I(i))/(2*sigma_r*sigma_r)) + 0.0001; weights = weights./sum(weights); I_output(i) = sum(weights.*pixels); end figure; plot(n,I_output); Bahadir K. Gunturk 8 Bilateral Filter Input Gaussian d 10 Bilateral d 10 r 1.3 Bahadir K. Gunturk 9 Bilateral Filter vs. Gaussian LPF d 2 r 10 Gaussian MSE=49.8 MSE=100.0 n 10 r 30 MSE=30.3 sigma_d=10 MSE=99.57 r 50 Bahadir K. Gunturk MSE=42.5 10 Wiener Filter Y X W Noisy image Original image Wiener Filter Noise 2 x Xˆ 2 Y 2 x w Signal variance Noise variance When sigma_x << sigma_w, (noise is very large), X goes to 0. When sigma_x >> sigma_w, (noise is very small), X goes to Y. Bahadir K. Gunturk 11 Wiener Filter x2 is estimated by ˆ x2 y 2 w2 Estimate manually by looking at the variance in a smooth region. Since variance is nonnegative, it is modified as ˆ x2 max[ 0, y 2 w2 ] Estimate signal variance locally: ˆ x2 max[0, Bahadir K. Gunturk 1 N2 2 2 y i w] i N N 12 Wiener Filter Noisy, =10 Denoised (3x3neighborhood) Mean Squared Error is 56 wiener2 in Matlab Bahadir K. Gunturk 13 Image Enhancement 1 1 1 1 8 1 1 1 1 This is an high-pass filter. It removes low-frequency components. Bahadir K. Gunturk 14 Image Enhancement High-boost or high-frequency-emphasis filter Sharpens the image but does not remove the low-frequency components unlike high-pass filtering Bahadir K. Gunturk 15 Image Enhancement High-boost or high-frequency-emphasis filter High pass = Original – low pass High boost = A*(Original) + High pass Part of the low-frequency components are added back to the high frequency components Bahadir K. Gunturk 16 Image Enhancement 1 1 1 1 8 1 1 1 1 1 1 1 1 9 1 1 1 1 A high-pass filter A high-boost filter Bahadir K. Gunturk 17 Image Enhancement High-boost or high-frequency-emphasis filter Bahadir K. Gunturk 18 Spatial Filtering Bahadir K. Gunturk 19