You are on page 1of 15

FACULTY OF INFORMATICS DEPARTMENT OF COMPUTER

SCIENCE

Digital Image Processing Individual Assignment

On Image Filtering

Set by: Estifanos Alebachew

ID: SGS/0231/2014A

Submitted To: Million M. (PhD)


Submission Date: 11/05/2022
An overview of median and mean (average) filtering

Median filtering
Median filtering is a nonlinear method used to remove noise from images.it is widely used
as it is very effective at removing noise while preserving edges.

It is practically effective at removing ‘salt and pepper ’type noise. The median filters works
by moving through the image pixel by pixel, replacing each values with the median values of
neighbouring pixels.

The pattern of neighbours is called the “window”, which slides, pixel by pixel, over the
entire image.

The median is calculated by first sorting all the pixel values from the window into numerical
order, and then replacing the pixel being considered with the middle (median) pixel value.

Mean (average) filtering


Mean or average filtering is a method of ‘smoothing’ images by reducing the amount of
intensity variation between neighbouring pixels.

The average filter works by moving through the image pixel by pixel, replacing each values
with the average values of neighbouring pixels, including itself.

There are some potential problems:

A single pixel with a very unrepresentative value can significantly affect the average
value of all the pixels in its neighbourhood.
When the filter neighbourhood straddles an edge, the filter will interpolate new
values for pixels on the edge and so will blur that edge. This may be problem if sharp
edges are required in the output.

1|Page
median filtering
Given image applying a 5x5 sampling windows

Median mask
100 130 110 120 110

110 90 100 90 100


F(x ,y)=
130 100 90 130 110
h(x,y)=
120 100 130 110 120

90 110 80 120 100

Steps for median filtering

o Arrange a 5x5 empty mask


o Place these mask on image for convolution
o Arrange the 25 pixels intensity in ascending or descending order
o Select the median from these 25 values
o Place this value at candidate pixel
o Move the mask in similar fashion

Before doing the above steps we applying zero padding in the given pixel.

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

and place the 5 x 5 masks on the image so the result is:

2|Page
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Now the first median pixel value is out of 25 =

1. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,90,90,100,100,100,110,110,130,130
median=0

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

2. 0,0,0,0,0,0,0,0,0,0,0,0,0,90,90,90,100,100,100,110,110,120,130,130,130
Median=0

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

3. 0,0,0,0,0,0,0,0,0,0,90,90,90,100,100,100,100,110,110,110,110,120,130,130,130

Median=90

3|Page
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

4. 0,0,0,0,0,0,0,0,0,0,0,0,0,90,90,90,100,100,100,110,110,110,120,130,130

Median=0

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

5. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,90,90,100,100,110,110,110,120,130

Median=0

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

6. 0,0,0,0,0,0,0,0,0,0,0,0,0,90,90,100,100,100,100,110,110,120,130,130,130

Median=0

4|Page
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

The pixels values in descending order=

7. 0,0,0,0,0,0,0,0,0,90,90,90,100,100,100,100,110,110,110,120,120,130,130,130,130

Median=100

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

The pixels values in descending order=

8. 0,0,0,0,0,90,90,90,100,100,100,100,100,110,110,110,110,110,120,120,120,130,130,
130,130

Median=100

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

5|Page
The pixels value in descending value =

9. 0,0,0,0,0,0,0,0,0,90,90,90,100,100,100,100,110,110,110,110,120,120,130,130,130

Median =100

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
10. 0,0,0,0,0,0,0,0,0,0,0,0,0,90,90,100,100,110,110,110,110,120,120,130,130

Median =0

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

11. 0,0,0,0,0,0,0,0,0,0,80,90,90,90,100,100,100,100,110,110,110,120,130,130,130

Median = 90

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

12. 0,0,0,0,0,80,90,90,90,90,100,100,100,100,110,110,110,110,120,120,120,130,130,13
0,130

Median =100

6|Page
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

13. 80,90,90,90,90,100,100,100,100,100,100,110,110,110,110,110,110,120,120,120,120
,130,130,130,130

Median = 110

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

14. 0,0,0,0,0,80,90,90,90,100,100,100,100,100,110,110,110,110,110,120,120,120,130,1
30,130

Median =100

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

15. 0,0,0,0,0,0,0,0,0,0,80,90,90,100,100,100,110,110,110,110,120,120,120,130,130

Median =90

7|Page
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

16. 0,0,0,0,0,0,0,0,0,0,0,0,0,80,90,90,90,100,100,100,110,110,120,130,130
Median= 0

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

17. 0,0,0,0,0,0,0,0,0,80,90,90,90,90,100,100,100,110,110,110,120,120,130,130,130

Median =90

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

18. 0,0,0,0,0,80,90,90,90,90,100,100,100,100,100,110,110,110,110,120,120,120,130,13
0,130

Median =100

8|Page
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

19. 0,0,0,0,0,0,0,0,0,80,90,90,90,100,100,100,100,100,110,110,110,120,120,130,130

Median=100

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

20. 0,0,0,0,0,0,0,0,0,0,0,0,0,80,90,90,100,100,100,110,110,120,120,130,130

Median =0

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

21. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,80,90,90,100,100,110,120,130,130

Median =0

9|Page
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

22. 0,0,0,0,0,0,0,0,0,0,0,0,0,80,90,90,100,100,110,110,120,120,130,130,130

Median =0

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

23. 0,0,0,0,0,0,0,0,0,0,80,90,90,100,100,100,110,110,110,120,120,120,130,130,130

Median =90

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

24. 0,0,0,0,0,0,0,0,0,0,0,0,0,80,90,100,100,100,110,110,110,120,120,130,130

Median =0

10 | P a g e
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 100 130 110 120 110 0 0
0 0 110 90 100 90 100 0 0
0 0 130 100 90 130 110 0 0
0 0 120 100 130 110 120 0 0
0 0 90 110 80 120 100 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

25. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,80,90,100,110,110,120,120,130,130

Median =0

Now the final output will be:

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 90 0 0 0 0
0 0 0 100 100 100 0 0 0
0 0 90 100 110 100 90 0 0
0 0 0 90 100 100 0 0 0
0 0 0 0 90 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

Mean (average) filtering


In this filtering method we are using the same filtering mask which is 5x5 filtering mask and
put the mask on the given image in each rows and finding the mean values on each row.

Now the given image that we have given is similar with the above given image and the mask
is also the same. To calculate the mean value we are replicating the pixels on the given
image.so the replication image is:

11 | P a g e
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1/25 1/25 1/25 1/25 1/25
0 0 100 130 110 120 110 0 0
1/25 1/25 1/25 1/25 1/25
0 0 110 90 100 90 100 0 0 The
0 0 130 100 90 130 110 0 0 filtering 1/25 1/25 1/25 1/25 1/25
0 0 120 100 130 110 120 0 0 5x5 mask
1/25 1/25 1/25 1/25 1/25
0 0 90 110 80 120 100 0 0 is: 1/25*
0 0 0 0 0 0 0 0 0 1/25 1/25 1/25 1/25 1/25
0 0 0 0 0 0 0 0 0

Now putting the given mask on the image on the similar manner with the median now the
resulting values for each row is:

 Average =1/n(x1+x2+x3………xn)

Now update the mean value on the given image it gives

1. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+90+90+100+100+100+110+110+130+130)=38.4
=approximately 38
2. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+0+90+90+90+100+100+100+110+110+120+130+130+130
)=52
3. 1/25(0+0+0+0+0+0+0+0+0+0+90+90+90+100+100+100+100+110+110+110+110+120+130+1
30+130)=64.8=65
4. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+0+90+90+90+100+100+100+110+110+110+120+130+130
)=51.2 approximately 51
5. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+90+90+100+100+110+110+110+120+130)=38.4
approximately 38
6. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+0+90+90+100+100+100+100+110+110+120+130+130+13
0)=52.4 approximately 52
7. 1/25(0+0+0+0+0+0+0+0+0+90+90+90+100+100+100+100+110+110+110+120+120+130+130
+130+130)=70.4 approximately 70
8. 1/25(0+0+0+0+0+90+90+90+100+100+100+100+100+110+110+110+110+110+120+120+120
+130+130+130+130)=88
9. 1/25(0+0+0+0+0+0+0+0+0+90+90+90+100+100+100+100+110+110+110+110+120+120+130
+130+130)=69.6 =70
10. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+0+90+90+100+100+110+110+110+110+120+120+130+13
0)=52.8=53
11. 1/25(0+0+0+0+0+0+0+0+0+0+80+90+90+90+100+100+100+100+110+110+110+120+130+13
0+130)=63.6=64
12. 1/25(0+0+0+0+0+80+90+90+90+90+100+100+100+100+110+110+110+110+120+120+120+1
30+130+130+130)=86.4=86

12 | P a g e
13. 1/25(80+90+90+90+90+100+100+100+100+100+100+110+110+110+110+110+110+120+120
+120+120+130+130+130+130)=108
14. 1/25(0+0+0+0+0+80+90+90+90+100+100+100+100+100+110+110+110+110+110+120+120+
120+130+130+130)=86
15. 1/25(0+0+0+0+0+0+0+0+0+0+80+90+90+100+100+100+110+110+110+110+120+120+120+1
30+130)=64.8=65
16. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+0+80+90+90+90+100+100+100+110+110+120+130+130)
=50
17. 1/25(0+0+0+0+0+0+0+0+0+80+90+90+90+90+100+100+100+110+110+110+120+120+130+1
30+130)=68
18. 1/25(0+0+0+0+0+80+90+90+90+90+100+100+100+100+100+110+110+110+110+120+120+1
20+130+130+130)=85.2=85
19. 1/25(0+0+0+0+0+0+0+0+0+80+90+90+90+100+100+100+100+100+110+110+110+120+120+
130+130)=67
20. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+0+80+90+90+100+100+100+110+110+120+120+130+130
)=51.2=51
21. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+80+90+90+100+100+110+120+130+130)=38
22. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+0+80+90+90+100+100+110+110+120+120+130+130+130
)=52.4=52
23. 1/25(0+0+0+0+0+0+0+0+0+0+80+90+90+100+100+100+110+110+110+120+120+120+130+1
30+130)=65.6=66
24. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+80+90+100+100+100+110+110+110+120+120+130+130)
=52
25. 1/25(0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+80+90+100+110+110+120+120+130+130)=39.6
=40

Now the final mean output is

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 38 52 65 51 38 0 0
0 0 52 70 88 70 53 0 0
0 0 64 86 108 86 65 0 0
0 0 50 68 85 67 51 0 0
0 0 38 52 66 52 40 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

13 | P a g e
Conclusion
As we have seen so far both the median and mean filtering is used to remove noises in the
image. But both filtering technique is some major differences as I seen in the previous
solution.

In the median filtering technique practically better for removing noises than mean filtering.
Because the media is just the middle value of all the values of the pixels in the
neighbourhood, while the mean filter we are defining a new value calculated by the other
values in the window.so median filtering is very effective at removing noise than mean.

Reference

[1]. Session 22 - Image Smoothing - Box / Average Filter, 2020(video file), available from:

< https://www.youtube.com/watch?v=jga235t0um4>[8 may 2022].

[2]. Median Filtering in Spatial Domain, 2020(video file), available from:

< https://www.youtube.com/watch?v=jga235t0um4>[8 may 2022].

[3]. Lecture 1: Image Processing and Computer Vision: Image Filtering, 2021(video file),
available from:

< https://www.youtube.com/watch?v=NGlYGPHegWs&t=1102s>[9 may 2022].

14 | P a g e

You might also like