1. Penn State University
E E 458 Project 3
Using Adaptive Filters to Remove Gaussian Noise
By Chad RyanWeiss
4/6/2016
2. Abstract:
Adaptive filteringisapopulardigital image processingtechniquethatusesstatistical datafroman image
to alterthe contentsof that image. The type of filterusedinthisreportwill take the variance andmean
of the image andapplyit ina way that will hopefullyreduce the amountof Gaussiannoise presentinthe
image. The firstpart of thisreportwill gointothe theorybehindadaptive filtering. Thenwe will apply
thistheoryand create a MatLab computerprogramthat will remove unwantednoise fromanimage in
the secondpart of thisreport.
3. Theory: Adaptive Filtering
Adaptive filtersuse dynamicvariablesasinputstoacquire a desiredoutput.
Application: RemovingGaussianNoise
% Name: Chad Weiss
% Date: March 25, 2016
% Project: E E 458 Project 003
% Instructor: Dr. Aldo Morales
% This program implements an adaptive filtering technique that uses the
% statistical means and variances of the image to reduce gaussian noise.
clear all;clc;
% Read-In Image
I = imread('Neighbors.jpg'); Status = imfinfo('Neighbors.jpg');
% Add Noise to Image
noise_variance = 0.03;
J = imnoise(I,'gaussian',0,noise_variance);
% Zero Border
Input = [zeros(1,Status.Width,3);J;zeros(1,Status.Width,3)];
Input = [zeros(Status.Height+2,1,3),Input,zeros(Status.Height+2,1,3)];
imtool(Input);
% Noisy r,g and b planes (RGB format)
r = Input; r(:,:,2:3)=0;
g = Input; g(:,:,1)=0; g(:,:,3)=0;
b = Input; b(:,:,1:2)=0;
R = double(r(:,:,1))/256;
G = double(g(:,:,2))/256;
B = double(b(:,:,3))/256;
% Define the Filter Mask
mask = zeros(3,3);
% Define Output Image
Output_R = zeros(Status.Height+2, Status.Width+2);
Output_G = zeros(Status.Height+2, Status.Width+2);
Output_B = zeros(Status.Height+2, Status.Width+2);
% Red Value Plane Loop
for i = 1:Status.Height
for j = 1:Status.Width
mask = R(i:i+2,j:j+2);
M = mean(reshape(mask,[],1)); % Mean
V = var(reshape(mask,[],1));
output = (mask(5)-((noise_variance/V)*(mask(5)-M))); % Output
if output < 0
output = 0;
4. end
if output > 1
output = 1;
end
Output_R(i+1,j+1) = output; % Insert Output
end
end
% Green Value Plane Loop
for i = 1:Status.Height
for j = 1:Status.Width
mask = G(i:i+2,j:j+2);
M = mean(reshape(mask,[],1));
V = var(reshape(mask,[],1));
output = (mask(5)-((noise_variance/V)*(mask(5)-M)));
if output < 0
output = 0;
end
if output > 1
output = 1;
end
Output_G(i+1,j+1) = output;
end
end
% Blue Value Plane Loop
for i = 1:Status.Height
for j = 1:Status.Width
mask = B(i:i+2,j:j+2);
M = mean(reshape(mask,[],1));
V = var(reshape(mask,[],1));
output = (mask(5)-((noise_variance/V)*(mask(5)-M)));
if output < 0
output = 0;
end
if output > 1
output = 1;
end
Output_B(i+1,j+1) = output;
end
end
Output = uint8(cat(3,Output_R*256,Output_G*256,Output_B*256));
imtool(Output);
6. Analysis:
The code breaksdownlike so:
1. Read-Inthe Image
2. AddNoise tothe Image
3. Create a ZeroBorder aroundthe perimeterof the image
4. Isolate the Red, Green andBlue Planes
5. Convertto type single ordouble
6. Define the 3-by-3mask
7. Fill the maskwiththe noisyimage values
8. Determine the variance andmeanof the mask
9. Applythe formula(highlightedinyellow)
10. Setthe centervalue of the maskequal tothe outputof the formulaand applytoa similarsize
zeromatrix
11. Repeatforthe Greenand Blue Planes
12. Concatenate the three planestoformthe final output
13. Displaythe InputandOutputimagesforcomparison
Discussion:
It was difficulttogetthisfiltertoproduce a clearoutputdespite severaldifferentapproaches. First,we
triedconvertingRGN to HSV formatbut foundoutthat thistype of filterdidnotworkat all on the Hue
and Saturationplanesof the images;furthermore,itproducedaveryinconsistentsmearingof the
Gaussiannoise acrossthe V planesof the HSV images. The secondattemptconsistedof simply
convertingthe RGB image tograyscale and changingthe datatype tosingle ordouble sothat the var
functioncouldwork. The resultwasnot great. Finally,we triedtomake some adjustmentstothe code
to try and find some errorslike substitutingthe outputof the filterintoazeromatrix insteadof
substitutingitdirectlyintothe inputimage (eventhoughthathasworkedinpreviousfilteringmethods
such as medianfiltering). The resultturnedoutmuchbetterthanthe original butthe inputimage still
appearedtobe muchclearerthan the outputimage whichshowsthatthe filterwasinfact ineffective.
Conclusion:
In conclusion,the pointof anadaptive filteristouse the dynamicvariablesof animage,suchas the
statistical data,to alteran image toproduce a cleaneroutput. For the purposesof thisexperiment,it
didnot turn outso well. Youcan see the resultsinFigs.1 and 2. Also,Ihave addedthe resultsof
previouscomputerprogramsaswell asthe resultof usingthe built-inMatLabfunctionspecifically
designedforremovingGaussiannoise.
7. PreviousAttempts:
% Name: Chad Weiss
% Date: March 25, 2016
% Project: E E 458 Project 003
% Instructor: Dr. Aldo Morales
% This program implements an adaptive filtering technique that uses the
% statistical means and variances of the image to reduce gaussian noise.
clear all;clc;
% Read-In Image
I = imread('Neighbors.jpg'); Status = imfinfo('Neighbors.jpg');
% Add Noise to Image
noise_variance = 0.01;
J = imnoise(I,'gaussian',0,noise_variance);
% Zero Border
Input = [zeros(1,Status.Width,3);J;zeros(1,Status.Width,3)];
Input = [zeros(Status.Height+2,1,3),Input,zeros(Status.Height+2,1,3)];
imtool(Input);
% Noisy r,g and b planes (RGB format)
r = Input; r(:,:,2:3)=0;
g = Input; g(:,:,1)=0; g(:,:,3)=0;
b = Input; b(:,:,1:2)=0;
% Noisy r planes (HSV format)
r_hsv = rgb2hsv(r);
r_v = r_hsv(:,:,3);
% Noisy g planes (HSV format)
g_hsv = rgb2hsv(g);
g_v = g_hsv(:,:,3);
% Noisy b planes (HSV format)
b_hsv = rgb2hsv(b);
b_v = b_hsv(:,:,3);
% Define the Filter Mask
mask = zeros(3,3);
for i = 1:Status.Height
for j = 1:Status.Width
mask = r_v(i:i+2,j:j+2);
M = mean(reshape(mask,[],1)); %
Mean
V = var(reshape(mask,[],1)); %
Variance
output = (mask(5)-((noise_variance/V)*(mask(5)-M))); %
Output
8. r_v(i+1,j+1) = output; %
Insert Output
end
end
% Green Value Plane Loop
for i = 1:Status.Height
for j = 1:Status.Width
mask = g_v(i:i+2,j:j+2);
M = mean(reshape(mask,[],1));
V = var(reshape(mask,[],1));
output = (mask(5)-((noise_variance/V)*(mask(5)-M)));
g_v(i+1,j+1) = output;
end
end
% Blue Value Plane Loop
for i = 1:Status.Height
for j = 1:Status.Width
mask = b_v(i:i+2,j:j+2);
M = mean(reshape(mask,[],1));
V = var(reshape(mask,[],1));
output = (mask(5)-((noise_variance/V)*(mask(5)-M)));
b_v(i+1,j+1) = output;
end
end
Output = uint8(cat(3,(r_v*256),(g_v*256),(b_v*256)));
imtool(Output);
Figure 3: Noisy Input Image
9. Figure 4: Adaptive Filter Output Image
Usingthe MatLab filter:
% Name: Chad Weiss
% Date: March 25, 2016
% Project: E E 458 Project 003
% Instructor: Dr. Aldo Morales
% This program implements an adaptive filtering technique that uses the
% statistical means and variances of the image to reduce gaussian noise.
clear all;clc;
% Read-In Image
I = imread('Neighbors.jpg'); Status = imfinfo('Neighbors.jpg');
% Add Noise to Image
noise_variance = 0.03;
J = imnoise(I,'gaussian',0,noise_variance);
% Zero Border
Input = [zeros(1,Status.Width,3);J;zeros(1,Status.Width,3)];
Input = [zeros(Status.Height+2,1,3),Input,zeros(Status.Height+2,1,3)];
imtool(Input);
% Noisy r,g and b planes (RGB format)
r = Input; r(:,:,2:3)=0;
g = Input; g(:,:,1)=0; g(:,:,3)=0;