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
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 5Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started