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.


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)
        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 **


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)
[row col]=size(sub);

if (sub(2,2)>=t1 && sub(2,2)<=t2)

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.

Please help me implement the algorithm.

2 Answers

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

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

Add your own answers!

Related Questions

How to compand an OFDM signal?

1  Asked on January 6, 2022 by user150011


“Complex sampling” can break Nyquist?

4  Asked on December 22, 2021 by spacey


different between MVG and joint MVG?

1  Asked on December 14, 2021


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir