# Image Noise Detection Using MATLAB

Signal Processing Asked by Premnath D on October 15, 2020

I want to implement the following algorithm. Let $I$ denote noisy image and for each pixel of $I$ is represented by $I(x,y)$. A Sliding window of size $3times3$ 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 weiner Filter.

Algorithm:

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) = weiner2(I(x,y)

6.  Repeat the step 3 , 4 and 5 on Entire Image.
7.  Display the Resultant Image.


First, I tried to implement this algorithm for median filter, so that I can extend it to other filters such as wiener, anisotropic diffusion,butterworth etc. I did implement it correctly with the help of ‘tbirdal’. Thank you ‘tbirdal’. But I am unable to extend the implementation for other filters.

**I don’t want to use loop.. Because it takes more time to run .. 20 mins to run a $512 times 512$ image.. I want to implement this using functions such as nlfilter, imfilter etc **
Program:

A=imread('npan3.jpg');

fun = @(x) noisedetect_2(x(:));
B = nlfilter(A,[3 3],fun);

imshow(A), figure, imshow(B, [])


The noisedetect_2 function is given as

function nd=noisedetect_2(sub)
sub=vec2mat(sub,3);
[row col]=size(sub);
%siz=size(sub)
s=std2(sub);
m=mean2(sub);
t1=m-s;
t2=m+s;
nd=zeros(row,col);

if (sub(2,2)>=t1 && sub(2,2)<=t2)
nd=sub;
else
nd=wiener2(sub);
end


I get the following error:

Assignment has more non-singleton rhs dimensions than non-singleton subscripts

Error in nlfilter (line 75)
b(i,j) = feval(fun,x,params{:});

Error in nd_test_2 (line 10)
B = nlfilter(A,[3 3],fun);


I understand what the error means. the nlfilter is expecting single value but the function returns $3times3$ matrix. How to solve this issue?. I just want to apply any filter only when the pixel falls out of the range $t_1$ and $t_2$ because it is considered as noisy pixel. Otherwise, it is retained as such because it is considered as noisefree pixel.

I would implement it differently altogether.
Since applying the Wiener filter is pretty "cheap" I would create an Image called mWienerFilter.
Then:

vNoisePixels = (abs(I -  mMeanImage) > noiseThr);
I(vNoisePixels) = mWienerFilter(vNoisePixels);


That would be the best thing to do in my opinion.

Answered by Royi on October 15, 2020

Use blockproc with the BorderSize option (to achieve the overlapping between the blocks):

B = blockproc(A,[1 1],fun,'BorderSize',[1 1]);


Answered by lennon310 on October 15, 2020

## Related Questions

### How to compand an OFDM signal?

1  Asked on January 6, 2022 by user150011

### Designing appropriate filter by choosing values for $A$ and $B$

2  Asked on January 6, 2022

### Does it make sense to have complex numbers representing real-world audio signals?

6  Asked on January 4, 2022 by growinman

### Homography for (small baseline) Stereo Image Registration

1  Asked on January 4, 2022 by cvnerd

### farrow resampler in timing recovery

1  Asked on January 4, 2022

### Continuously changing pitch of stable-pitch audio sample

1  Asked on January 4, 2022

### Is resizing of frequency spectrum a valid method of resampling?

1  Asked on January 2, 2022

1  Asked on December 31, 2021 by user26052

### Respiration (breathing) signal movement artifact removal

1  Asked on December 31, 2021 by parpar

### What is the best to confirm that the output of a matched filter for a linear FM chirp is correct?

2  Asked on December 31, 2021

### Low data rate with high frequency offset

1  Asked on December 28, 2021

### Time scale and Fourier transform

1  Asked on December 28, 2021

### How to prepare different input size in CNN

1  Asked on December 24, 2021 by smurf-again

### What is the unit-power information signal?

1  Asked on December 24, 2021 by fzzyy

### “Complex sampling” can break Nyquist?

4  Asked on December 22, 2021 by spacey

### Radar type application for narrow band only?

1  Asked on December 19, 2021

### Multisampling of an ADC channel in a PWM cycle in TI C2000

1  Asked on December 17, 2021 by yasin

### How to calculate time domain SNR using known sequence

1  Asked on December 14, 2021

### different between MVG and joint MVG?

1  Asked on December 14, 2021

### How to scale audio signal from PCM data to a dB SPL value?

0  Asked on December 12, 2021