HW 5, Problems 5.8
EECS 203A, UCI, Fall 2004

by Nasser Abbasi

Question

TextBook: Digital Image 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 Min filter?
(b) 7x7 ?
(c) 9x9 ?

Answer

Median filter is given by f(x, y) = Min (g(x, y)where g(x, y)is the image data under the filter.

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[3]:=

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_4.gif]

Out[8]=

⁃DensityGraphics⁃

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.

<br />Take[data, {23, 27}, {26, 34}]//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

3x3 Filter

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

In[12]:=

F[n_] := Table[1, {i, 1, n}, {j, 1, n}] F3 = F[3] ; MatrixForm[F3]

Out[14]//MatrixForm=

( 1   1   1 )            1   1   1            1   1   1

Filter the image with Min 3x3 and display result

In[15]:=

nImage3 = nma`filterMin[data, F3] ; nma`imshow[Round[N[nImage3]], "Min 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_15.gif]

Out[16]=

⁃DensityGraphics⁃

Show the top edge of the white bar BEFORE processing

In[17]:=

nma`imshow[Round[N[Take[data, {23, 27}, {26, 34}]]], ""]

[Graphics:HTMLFiles/index_18.gif]

Out[17]=

⁃DensityGraphics⁃

Show the top edge of the white bar AFTER processing

In[18]:=

nma`imshow[Round[N[Take[nImage3, {21, 27}, {23, 34}]]], ""]

[Graphics:HTMLFiles/index_21.gif]

Out[18]=

⁃DensityGraphics⁃

Look at the data before:

Take[Round[N[data]], {23, 27}, {26, 34}]//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

Look at the data after filtering

In[26]:=

<br />Take[Round[N[nImage3]], {23, 27}, {26, 32}]//MatrixForm<br />

Out[26]//MatrixForm=

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

So we see that the white bar is now is thinner it is 5 pixels wide.  And will be 4 rows less, it will be 206 pixels high

7x7 Filter

In[27]:=

F7 = F[7] ; nImage7 = nma`filterMin[data, F7] ; nma`imshow[Round[N[nImage7]], "Min 7x7"]

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

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

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

[Graphics:HTMLFiles/index_31.gif]

Out[29]=

⁃DensityGraphics⁃


Now show the top of the white strip. Look now how much more wide it is

In[30]:=

nma`imshow[Round[N[Take[nImage7, {17, 30}, {19, 35}]]], ""]

[Graphics:HTMLFiles/index_34.gif]

Out[30]=

⁃DensityGraphics⁃

In[37]:=

Take[Round[N[nImage7]], {22, 26}, {25, 28}]//MatrixForm

Out[37]//MatrixForm=

( 0     0     0     0   )            0     0     0     0            0     0     254   0            0     0     255   0            0     0     255   0

So we see that the white bar is now is thinner, it is  1 pixels wide. and will be 8 rows shorter, so 202 pixels high

9x9 Filter

In[38]:=

F9 = F[9] ; nImage9 = nma`filterMin[data, F9] ;  nma`imshow[Round[N[nImage9]], "Min 9x9"]

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

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

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

[Graphics:HTMLFiles/index_42.gif]

Out[40]=

⁃DensityGraphics⁃

In[41]:=

nma`imshow[Round[N[Take[nImage9, {15, 26}, {18, 35}]]], ""]

[Graphics:HTMLFiles/index_45.gif]

Out[41]=

⁃DensityGraphics⁃

In[45]:=

Take[Round[N[nImage9]], {13, 20}, {17, 30}]//MatrixForm

Out[45]//MatrixForm=

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

So we see that the white bars are all disappered.

3D plots

I'll now display the 3 images in 3D to better illustrate the filter result. I will only plot the region near the ends of the top of the first white strips.

In[46]:=

ListPlot3D[Take[data, {12, 40}, {15, 65}], PlotLabel"original data"] ListPlo ... Plot3D[Take[nImage9, {12, 40}, {15, 65}], PlotLabel"9x9 data"] 

[Graphics:HTMLFiles/index_50.gif]

Out[46]=

⁃SurfaceGraphics⁃

[Graphics:HTMLFiles/index_52.gif]

Out[47]=

⁃SurfaceGraphics⁃

[Graphics:HTMLFiles/index_54.gif]

Out[48]=

⁃SurfaceGraphics⁃

[Graphics:HTMLFiles/index_56.gif]

Out[49]=

⁃SurfaceGraphics⁃


Created by Mathematica  (November 16, 2004)