HW 5, Problems 5.3
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 Harmonic mean filter?
(b) 7x7 HMF?
(c) 9x9 HMF?

Answer

HMF is given by f(x, y) = (m n)/(Underoverscript[∑, x, y = s, arg3] 1/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.

Since some pixels can have gray level of zero, and for HMF we can not have this, so add a 1 to all pixel values, then after processing, subtract a 1 and plot the image then.  

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"]

General :: spell1 : Possible spelling error: new symbol name \"nRow\" is similar to existing symbol \"Row\".  More…

[Graphics:HTMLFiles/index_5.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 processing

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

In[9]:=

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

Out[11]//MatrixForm=

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

Filter the image with HMF3 and display result

nData = data + 1 ; nImage3 = nma`filterHMF[nData, HMF3] ; nImage3 = nImage3 - 1 ; nma`imshow[Round[N[nImage3]], "HMF 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_16.gif]

Out[18]=

⁃DensityGraphics⁃


Show the top edge of the white bar BEFORE processing

In[19]:=

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

[Graphics:HTMLFiles/index_19.gif]

Out[19]=

⁃DensityGraphics⁃

Show the top edge of the white bar AFTER processing

In[20]:=

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

[Graphics:HTMLFiles/index_22.gif]

Out[20]=

⁃DensityGraphics⁃

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

<br />Take[Round[N[nImage3]], {21, 27}, {25, 35}]//MatrixForm<br />

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

So we see that the white bar is 5 pixels wide, and  has 2 rows at the top and at the bottom by symmettry), hence it will be of 206 pixels high.  So white strips are more narrow.

7x7 HMF

In[21]:=

HMF7 = HMF[7] ; nImage7 = nma`filterHMF[nData, HMF7] ; nImage7 = nImage7 - 1 ; nma`imshow[Round[N[nImage7]], "HMF 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[24]=

⁃DensityGraphics⁃


Show the top of the white strip. Now how much more thin it is

In[25]:=

nma`imshow[Round[N[Take[nImage7, {14, 40}, {15, 34}]]], ""]

[Graphics:HTMLFiles/index_34.gif]

Out[25]=

⁃DensityGraphics⁃

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

( 0     0     0     0     0     0     0     0     0     0     0     0     0     0      ...  0     0     0     0     1     1     2     6     255   6     2     1     1     0     0     0     0

We see that now the white bar is only 1 pixel wide, and lost 4 rows at the top and 4 rows at the bottom, so it is now 202 pixels high. we see now the white strips are very narrow.

9x9 HMF

In[26]:=

HMF9 = HMF[9] ; nImage9 = nma`filterHMF[nData, HMF9] ; nImage9 = nImage9 - 1 ; nma`imshow[Roun ... ge9]], "MHF 9x9"] nma`imshow[Round[N[Take[nImage9, {14, 40}, {15, 34}]]], ""]

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[29]=

⁃DensityGraphics⁃

[Graphics:HTMLFiles/index_44.gif]

Out[30]=

⁃DensityGraphics⁃

In[32]:=

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

Out[32]//MatrixForm=

( 0   0   0   0   0   0   0   0   0   0   0 )            0   0   0   0   0   0 ...     0   0   1   1   2   3   3   3   2   1   1            0   0   1   1   2   3   3   3   2   1   1

We see that the adges now much smother, but the image have become more dark.

3D plots

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

ListPlot3D[Take[data, {20, 30}, {20, 50}], PlotLabel"original data"] ListPlo ... Plot3D[Take[nImage9, {20, 30}, {20, 50}], PlotLabel"9x9 data"] 

[Graphics:HTMLFiles/index_49.gif]

[Graphics:HTMLFiles/index_50.gif]

[Graphics:HTMLFiles/index_51.gif]

[Graphics:HTMLFiles/index_52.gif]


Created by Mathematica  (November 16, 2004)