Beruflich Dokumente
Kultur Dokumente
Homomorphic Filtering
Objective:
Description:
Homomorphic filtering is a generalized technique for signal and image processing,
involving a nonlinear mapping to a different domain in which linear filter techniques are applied,
followed by mapping back to the original domain.
Image enhancement
Operation
Homomorphic Filtering can be used for improving the appearance of a grayscale image
by simultaneous intensity range compression (illumination) and contrast enhancement
(reflection).
Where,
m = image,
i = illumination,
r = reflectance
We have to transform the equation into frequency domain in order to apply high pass filter.
However, it's very difficult to do calculation after applying Fourier transformation to this
equation because it's not a product equation anymore. Therefore, we use 'log' to help solving this
problem.
Then, applying Fourier transformation
Or
Next, applying high-pass filter to the image. To make the illumination of an image more even,
the high-frequency components are increased and low-frequency components are decrease.
Where
Afterward, returning frequency domain back to the spatial domain by using inverse Fourier
transform.
Task 1:
Enhance an image by applying Homorphic Filtering in Matlab.
Code
clear all
%read input image
dim=imread('football.jpg');
cim=double(dim);
[r,c]=size(dim);
cim=cim+1;
% add 1 to pixels to remove 0 values which would result in undefined log
values
% natural log
lim=log(cim);
%2D fft
fim=fft2(lim);
lowg=.9; %(lower gamma threshold, must be lowg < 1)
highg=1.1; %(higher gamma threshold, must be highg > 1)
% make sure the the values are symmetrically differenced
% function call
him=homomorph(fim,lowg,highg);
%inverse 2D fft
ifim=ifft2(him);
%exponent of result
eim=exp(ifim);
figure;
subplot(4,3,1);imshow(dim);title('Origional image');
subplot(4,3,2);imshow(lim);title('Natural Logarithm');
subplot(4,3,3);imshow(uint8(fim));title('Fourier transform');
subplot(4,3,4);imshow(him);title('Homomorphic filter');
Output
Filtering with Frequency Domain filters
a) Lowpass filters
Ideal Lowpass filter
Code
I=imread('cameraman.tif');
[m,n,h]=size(I);
if h~=1
I=rgb2gray(I);
end
subplot(1,3,1)
imshow(I);title('Original Image');
I_o=I;
subplot(1,3,2)
imshow(I);title('noisy Image');
I=imnoise(I,'gaussian',0,0.03);
[M N]=size(I);
a=im2double(I);
F1=fft2(a); %Obtain the Fourier transform
% Set up range of variables.
u = 0:(M-1); %0-255
v = 0:(N-1);%0-255
% center (u,v) = (M/2,N/2)
% Compute the indices for use in meshgrid
idx = find(u > M/2);% indices 130-255
u(idx) = u(idx) - M;
idy = find(v > N/2);
v(idy) = v(idy) - N;
%set up the meshgrid arrays needed for
% computing the required distances.
[U, V] = meshgrid(u, v);
% Compute the distances D(U, V).
D = sqrt(U.^2 + V.^2);
disp('IDEAL LOW PASS FILTERING IN FREQUENCY DOMAIN');
D0=input('Enter the cutoff distance==>');
% Begin filter computations.
H = double(D <= D0);
G=H.*F1; %Multiply
G=ifft2(G);
G=real(G);
ff=abs(fftshift(H));
subplot(133),imshow(G),title('IDEAL LPF Filtered Image')
Accuracy=Acc(I_o,G);
Output
Accuracy :- 0.18727
[m,n,h]=size(I);
if h~=1
I=rgb2gray(I);
end
subplot(1,3,1)
imshow(I);title('Original Image');
I_o=I;
%I=imnoise(I,'gaussian',0,0.03);
I=im2double(I);
FI=fft2(I); %Obtain the Fourier transform
LP=fspecial('gaussian',[11 11],1.3); %Generate a Low-Pass filter
FLP=fft2(LP,size(I,1),size(I,2)); % Filter padding
LP_OUT=FLP.*FI; %Multiply the transform by the filter
I_OUT_LP=ifft2(LP_OUT); %inverse DFT
I_OUT_LP=real(I_OUT_LP); %Obtain the real part(Output)
%%%%spectrum%%%%
FLP_S=abs(fftshift(FLP));%Filter spectrum
LP_OUT_S=abs(fftshift(LP_OUT));%output spectrum
Accuracy=Acc(I_o,medianFilteredImage);
Output
Accuracy :- 0.97416
%Convert to grayscale
footBall=rgb2gray(I);
[m,n,h]=size(I);
if h~=1
I=rgb2gray(I);
end
subplot(1,3,1)
imshow(I);title('Original Image');
I_o=I;
%I=imnoise(I,'gaussian',0,0.03);
%Determine good padding for Fourier transform
PQ = paddedsize(size(footBall));
Accuracy=Acc(I_o,S2);
Output
Accuracy :- 0.0052368
b) Highpass filters
Ideal Highpass filters
Code
I=imread('cameraman.tif');
[m,n,h]=size(I);
if h~=1
I=rgb2gray(I);
end
subplot(1,3,1)
imshow(I);title('Original Image');
I_o=I;
I=imnoise(I,'gaussian',0,0.03);
[M N]=size(a)
a=im2double(a);
F1=fft2(a); %Obtain the Fourier transform
[F,G ]=size(F1)
% Set up range of variables.
u = 0:(M-1); %0-255
v = 0:(N-1);%0-255
% center (u,v) = (M/2,N/2)
% Compute the indices for use in meshgrid
idx = find(u > M/2);% indices 130-255
u(idx) = u(idx) - M;
idy = find(v > N/2);
v(idy) = v(idy) - N;
%set up the meshgrid arrays needed for
% computing the required distances.
[U, V] = meshgrid(u, v);
% Compute the distances D(U, V).
D = sqrt(U.^2 + V.^2);
disp('IDEAL LOW PASS FILTERING IN FREQUENCY DOMAIN');
D0=15;
% Begin filter computations.
H = double(D > D0);
[T,L]=size(H)
G=H.*F1; %Multiply
G=ifft2(G);
G=real(G);
ff=abs(fftshift(H));
Accuracy=Acc(I_o,G);
Accuracy :- 0.064072
[m,n,h]=size(I);
if h~=1
I=rgb2gray(I);
end
subplot(1,3,1)
imshow(I);title('Original Image');
I_o=I;
%I=imnoise(I,'gaussian',0,0.03);
I=im2double(I);
[n,c]=size(I)
FI=fft2(I);
LP=fspecial('gaussian',1);
FLP=fft2(LP,n,c);
[A,B]=size(FLP)
LP_OUT=FLP.*FI ;
I_OUT_LP=ifft2(LP_OUT);
I_OUT_LP=real(I_OUT_LP);
FLP_S=abs(fftshift(FLP));
LP_OUT_S=abs(fftshift(LP_OUT));
subplot(133),imagesc(0.5*log(1+FLP_S)),title('gaussian HighPass
Filter')
Accuracy=Acc(I_o,LP_OUT_S);
Output
Accuracy :- 0.0028443
[m,n,h]=size(I);
if h~=1
I=rgb2gray(I);
end
subplot(1,3,1)
imshow(I);title('Original Image');
I_o=I;
%I=imnoise(I,'gaussian',0,0.03);
I=im2double(I);
[n,c]=size(I)
FI=fft2(I);
LP=fspecial('gaussian',1);
FLP=fft2(LP,n,c);
[A,B]=size(FLP)
LP_OUT=FLP.*FI ;
I_OUT_LP=ifft2(LP_OUT);
I_OUT_LP=real(I_OUT_LP);
FLP_S=abs(fftshift(FLP));
LP_OUT_S=abs(fftshift(LP_OUT));
subplot(133),imagesc(0.5*log(1+FLP_S)),title('gaussian HighPass
Filter')
Accuracy=Acc(I_o,LP_OUT_S);
Output
Accuracy :- 0.0028