Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following code I have is to implement an adaptive filter to an image once no

ID: 3734013 • Letter: T

Question

The following code I have is to implement an adaptive filter to an image once noise has been added to the orignal image. If you run it, the output image looks the same as the noisy image. Let me know what parts of the code to modify or what to add on. The adaptive filter equation is below this. I tried out this code with a grayscale image. Also let me know about implementing this with an RGB image.

close all
clear all

name = 'moon.tif';
W=15;
Status = imfinfo(name);
I=imread(name);
I=double(I)/255;
M= mean(mean(double(I)));
figure (1); imshow(I); title('Original Image')
nVar = 0.005;
J=imnoise(I, 'gaussian', 0, nVar);
figure (2); imshow(uint8(J*255));title('Noise Image')
W1 = (W-1)/2;

NewI = J; %matrix: copy noisy image
[mx my]=size(J); % find the image size
m=zeros(mx,my); % place holder for the local means
myRatio=zeros(mx,my); % place holder for the variance ratios


% in this loop only calculate the variances and their ratios
for i=W1 +1 :Status.Height-W1 % allow for zeros along edge of matrix
for j=W1 +1 :Status.Width-W1
myWindow=double(J(i-W1:i+W1,j-W1:j+W1)); % get the window (W/2)*(W/2)
myWindow=reshape(myWindow,1,W*W); % get into double and reshape
m(i,j)=mean(myWindow); % to obtain mean m
myLocalVar=var(myWindow); %find local variance
myRatio(i,j)=nVar/myLocalVar;
% perform ratios
end
end
myMax=max(max(myRatio)); %find the maximum to normalize no gretaer than 1

myRatio=myRatio/myMax; %Nornmalize

newI=J-myRatio.*(J-m); % perform adaptive filter

NewI=uint8(NewI*255);
figure(3); imshow(NewI);
title('Output Image');

g(x,y) input image , N-Oise variance, you can specify in MATLAB m, Local mean within a window, i.e. 3x3 or 5x5 , Local variance within a window. 1.e. 3 x 3 or 5 x 5

Explanation / Answer

clc;
clear all;
close all;
I=imread('Lab9_2.png');
size(I); %251x366x3
R= I(: , : , 1);
G= I(: , : , 2);
B= I(: , : , 3);
rgb_image= cat(3 , R, G, B);
subplot(121),imshow(I),title('original image');
subplot(122),imshow(rgb_image),title('reconstructed image');

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote