H ( u , v ) = ( γ H − γ L ) [ 1 − e − c [ D 2 ( u , v ) / D 0 2 ] ] − γ L H(u, v) = ({\gamma}_{H} - {\gamma}_{L})[1 - e^{-c[D^{2}(u, v)/D^{2}_{0}]}] -{\gamma}_{L} H(u,v)=(γH−γL)[1−e−c[D2(u,v)/D02]]−γL
其中, γ H {\gamma}_{H} γH的值为, γ L {\gamma}_{L} γL的值为
D(u, v)的定义如下:
D ( u , v ) = [ ( u − M 2 ) 2 + ( v − N 2 ) 2 ] 1 2 D(u, v) = [(u - \frac{M}{2})^2 + (v - \frac{N}{2})^2]^{\frac{1}{2}} D(u,v)=[(u−2M)2+(v−2N)2]21
即在频率域中的点距离中心的距离。(通过对空域做中心变换后,我们在经过快速傅里叶变换之后得到的图像的中心将会是 ( M 2 , N 2 ) (\frac{M}{2}, \frac{N}{2}) (2M,2N),中心变换操作可以通过和 ( − 1 ) x + y (-1)^{x + y} (−1)x+y做相关得到,可以通过傅里叶变换的平移性得到)
(1)将图像的灰度值取自然对数,将入射分量和反射分量变成相加的形式,这样就可以利用傅里叶变化的线性特征变换到频域进行图像处理
% Homomophic filtering
[YUV] = imread('office.jpg','jpg');
[height, width, channel] = size(f);
U = YUV(1:height, 1:width, 2);
V = YUV(1:height, 1:width, 3);
f = YUV(1:height, 1:width, 1);
%limit frequency
D0 = 1;
% uint8 to double
f = im2double(f);
% ln
for x = 1:height
for y = 1:width
f(x, y) = log(f(x, y) + 1);
end
end
(2)进行DFT变换
% discrete fourier transfer
F = zeros(height, width);
temp = zeros(height, width);
for y = 1:width
for u = 1:height
sum = 0;
for x = 1:height
sum = sum + exp(-1j * 2 * pi * u * x / height) * f(x, y);
end
temp(u, y) = sum;
end
end
for u = 1:height
for v = 1:width
sum = 0;
for y = 1:width
sum = sum + exp(-1j * 2 * pi * v * y / width) * temp(u, y);
end
F(u, v) = sum;
end
end
(3)进行同态滤波
% generate Homomophic filtering kernel
kernel = zeros(height, width);
for u = 1:height
for v = 1:width
D = sqrt((u - height / 2)^2 + (v - width / 2)^2);
% 同态滤波
kernel(u, v) = 1.75 * (1 - exp(-D^2 / D0^2)) + 0.25;
% Butterworth 高通滤波
%kernel(u, v) = 1 / (1 - (D0 / D)^2);
end
end
imwrite(kernel, 'kernel_.png', 'png');
F = F.*kernel;
(4)进行IDFT变换
% Inverse DFT
% Inverse discrete fourier transfer
temp = zeros(height, width);
for y = 1:width
for u = 1:height
sum = 0;
for x = 1:height
sum = sum + exp(1j * 2 * pi * u * x / height) * F(x, y);
end
temp(u, y) = sum;
end
end
for u = 1:height
for v = 1:width
sum = 0;
for y = 1:width
sum = sum + exp(1j * 2 * pi * v * y / width) * temp(u, y);
end
cent(u, v) = sum / (width * height);
end
end
(5)进行幂运算,基数为自然系数
% exp
for u = 1:height
for v = 1:width
f(u, v) = exp(f(u, v)) - 1;
end
end