I am getting error while implementing a simple idea for noise detection in an image. Let I denote noisy image and for each pixel of I is represented by I(x,y). A Sliding window of size 3X3 centered at I(x, y) is defined. At first we estimate that the center pixel of window is noise or not. To differ the noise and signal, we calculate the mean (m) and standard deviation (s) of the window. If the pixel is between m-s and m+s then it is a signal otherwise noise and we will apply median Filter.
1. Read an Image I. 2. Take a Sliding Window or Mask of size 3X3. 3. Calculate the Mean (m) and Standard deviation (s) from the Mask. 4. Calculate the threshold as follows t1 = m-s and t2 = m+s 5. IF t1 <= I(x,y) and I(x,y) <= t2 THEN Result(x,y) = I(x,y) ELSE Result(x, y) = medfilt2(I(x,y) 6. Repeat the step 3 , 4 and 5 on Entire Image. 7. Display the Resultant Image.
I tried to implement this algorithm as follows
clc; close all; clear all; I=imread('lena.jpg'); I=rgb2gray(I); J=imresize(I, [128 128]); L = imnoise(J,'speckle',0.01); [m,n]=size(L); % RETAINING THE CORNER PIXELS/ we can do zero padding also, suggest me which one is good for i= 1:m+4 for j = 1:n+4 L(:,1:2)=J(:,1:2); % retain the first two columns L(:,(m-1):m)=J(:,(m-1):m); % retain the last two columns L(1:2,:)=J(1:2,:); % retain the first two rows L((n-1):n,:)=J((n-1):n,:); % retain the last two rows end end for i=1:m-2 for j=1:n-2 P=L(i:(i+2),j:(j+2)); s=std2(P(:)); % Calculating Standard deviation m=mean2(P(:)); % Calulating Mean t1=m-s; % Threshold 1 t2=m+s; % Threshold 2 if (P(2,2)<=t1 && P(2,2)>=t2) iout(i,j)=medfilt2(P(:)) else iout(i,j)=P(2,2) end end end L iout imshow(iout, ); imshowpair(L,iout,'montage');
It runs but there is no change between input and output images.. Image is not filtered. Please help me.