HW 5, Problems 1-9
EECS 203A, UCI, Fall 2004

by Nasser Abbasi

Question

TextBook: Digital Iage Processing, 2nd edition. By Gonzalez and Woods.

The white bars in the test pattern shown below are 7 pixels wide and 210 pixels high. The separation between bars is 17 pixels. What would this image look like after application of
(a) 3x3 Arithmetic mean filter?
(b) 7x7 AMF?
(c) 9x9 AMF?

Answer

Load the original Image and display it first. I downloaded the image from the text book website, and used InfranView to get the image information to find how many pixels the whole image is, then read in into Mathematica to display it.

In[2]:=

Clear["Global`*"] ; nma`cd ; nRow = 256 ;  nCol = 256 ; data = nma`imread["Prob5.01.raw", 256, 256] ; nma`imshow[data, "problem 5.1 image"]

[Graphics:HTMLFiles/index_2.gif]

Now construct each ARM filter, and apply them to the above image

In[8]:=

ARM[n_] := Table[1/n^2, {i, 1, n}, {j, 1, n}] ARM3 = ARM[3] ; MatrixForm[ARM3]

Out[10]//MatrixForm=

( 1   1   1 )           -   -   -           9   9   9            1   1   1           -   -   -           9   9   9            1   1   1           -   -   -           9   9   9

Filter the image with ARM3 and display result

In[11]:=

nImage3 = nma`filter[data, ARM3] ; nma`imshow[nImage3, "ARM 3x3"]

startingRow = 2endingRow = 255 startingCol=2 endingCol=255

ncol= 256 nRow= 256 n=3

Dimension of new image is = {254, 254}

[Graphics:HTMLFiles/index_10.gif]

Now do the same with 7x7 ARM

In[13]:=

ARM7 = ARM[7] ; MatrixForm[ARM7] nImage7 = nma`filter[data, ARM7] ; nma`imshow[nImage7, "ARM 7x7"]

Out[14]//MatrixForm=

( 1    1    1    1    1    1    1  )           --   --   --   --   --   --   - ...  1    1    1           --   --   --   --   --   --   --           49   49   49   49   49   49   49

startingRow = 4endingRow = 253 startingCol=4 endingCol=253

ncol= 256 nRow= 256 n=7

Dimension of new image is = {250, 250}

[Graphics:HTMLFiles/index_16.gif]

Now do the same with 9x9 ARM

In[17]:=

ARM9 = ARM[9] ; MatrixForm[ARM9] nImage9 = nma`filter[data, ARM9] ; nma`imshow[nImage9, "ARM 9x9"]

Out[18]//MatrixForm=

( 1    1    1    1    1    1    1    1    1  )           --   --   --   --   - ...    --   --   --   --   --   --   --   --   --           81   81   81   81   81   81   81   81   81

startingRow = 5endingRow = 252 startingCol=5 endingCol=252

ncol= 256 nRow= 256 n=9

Dimension of new image is = {248, 248}

[Graphics:HTMLFiles/index_22.gif]

Analysis

In the original image, the vertical white bars look like this (displaying the top end of the white bar) we see that the white bar top starts at row number 24, we see that the strip is 7 pixels wide.

In[45]:=

Take[data, {23, 27}, {26, 34}]//MatrixForm

Out[45]//MatrixForm=

( 0     0     0     0     0     0     0     0     0   )            0     255   ... 255   255   255   255   255   255   0            0     255   255   255   255   255   255   255   0

After applying the 3x3 filter, the white bar would blur to the following

In[46]:=

Take[Round[N[nImage3]], {20, 27}, {23, 35}]//MatrixForm

Out[46]//MatrixForm=

( 0     0     0     0     0     0     0     0     0     0     0     0     0    ... 85    0     0            0     0     85    170   255   255   255   255   255   170   85    0     0

So we see that the white bar is 9 pixels wide, and now starts at row 22, so it has added 2 rows at the top (and 2 rows at the bottom by symmettry), hence it will be of 214 pixels high. We also see the effect of averaging is to give smooth boundaries.

Do similar analysis on the 7x7 filter.

In[53]:=

Take[Round[N[nImage7]], {16, 25}, {19, 35}]//MatrixForm

Out[53]//MatrixForm=

( 0     0     0     0     0     0     0     0     0     0     0     0     0     0      ...  0     0     36    73    109   146   182   219   255   219   182   146   109   73    36    0     0

We see that now the white bar is 13 pixels wide, and starts at row 18, so it has added 6 rows at the top and 6 rows at the bottom, so it is now 222 pixels high. we see that the edges now are more smooth.

Do similar analysis on the 9x9 filter.

In[59]:=

Take[Round[N[nImage9]], {14, 26}, {17, 35}]//MatrixForm

Out[59]//MatrixForm=

( 0     0     0     0     0     0     0     0     0     0     0     0     0     0      ...  28    57    85    113   142   170   198   198   198   170   142   113   85    57    28    0     0

We see that now the white bar is 15 pixels wide,and starts at row 16,so it has added 8 rows at the top and 8 rows at the bottom,so it is now 216 pixels high. we see that the edges now are even more smooth.


Created by Mathematica  (November 14, 2004)