HW 5, Problems 5.4
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 contraharmonic mean filter with Q=1?
(b) 7x7 ?
(c) 9x9 ?

Answer

CMF is given by f(x, y) = (Underoverscript[∑, x, y = s, arg3] g(x, y)^(Q + 1))/(Underoverscript[∑, x, y = s, arg3] g(x, y)^Q)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[18]:=

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

⁃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 ARM filter, and apply them to the above image

In[24]:=

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

Out[26]//MatrixForm=

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

Filter the image with HMF3 and display result

In[31]:=

nData = data + 1 ;   nImage3 = nma`filterContraharmonicMean[nData, F ... nImage3 = nImage3 - 1 ; nma`imshow[Round[N[nImage3]], "Contraharmonic Mean 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[34]=

⁃DensityGraphics⁃


Show the top edge of the white bar BEFORE processing

In[35]:=

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

[Graphics:HTMLFiles/index_18.gif]

Out[35]=

⁃DensityGraphics⁃

Show the top edge of the white bar AFTER processing

In[46]:=

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

[Graphics:HTMLFiles/index_21.gif]

Out[46]=

⁃DensityGraphics⁃

After applying the 3x3 filter, the white bar would blur to the following
Look at the data before:

In[43]:=

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

Out[43]//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[44]:=

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

Out[44]//MatrixForm=

( 0     0     0     0     0     0     0     0     0     0     0     0     0    ... 253   0     0            0     0     253   255   255   255   255   255   255   255   253   0     0

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

7x7 Filter

In[47]:=

F7 = F[7] ; nImage7 = nma`filterContraharmonicMean[nData, F7, 1] ; nImage7 = nImage7 - 1 ; nma`imshow[Round[N[nImage7]], "Contraharmonic Mean 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_32.gif]

Out[50]=

⁃DensityGraphics⁃


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

In[55]:=

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

[Graphics:HTMLFiles/index_35.gif]

Out[55]=

⁃DensityGraphics⁃

In[54]:=

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

Out[54]//MatrixForm=

( 0     0     0     0     0     0     0     0     0     0     0     0     0     0      ...  0     0     249   253   254   254   255   255   255   255   255   254   254   253   249   0     0

We see that now the white bar is  13 pixel wide, and added 4 rows at the top and 4 rows at the bottom, so it is now 218 pixels high. we see now the white strips are very narrow.

9x9 HMF

F9 = F[9] ; nImage9 = nma`filterContraharmonicMean[nData, F9, 1] ; nImage9 = nImage9 - 1 ; nma`imshow[Round[N[nImage9]], "Contraharmonic Mean 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_43.gif]

In[71]:=

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

[Graphics:HTMLFiles/index_45.gif]

Out[71]=

⁃DensityGraphics⁃

In[70]:=

Take[Round[N[nImage9]], {15, 23}, {18, 35}]//MatrixForm

Out[70]//MatrixForm=

( 0     0     0     0     0     0     0     0     0     0     0     0     0     0      ...  246   251   253   253   254   254   255   255   255   254   254   253   253   251   246   0     0

We see that now the white bar is  much wider, it is 15 pixel wide, and added 7 rows at the top and 7 rows at the bottom, so it is now 224 pixels high.

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 end of the top of the first white strip.

In[84]:=

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

⁃SurfaceGraphics⁃

[Graphics:HTMLFiles/index_52.gif]

Out[85]=

⁃SurfaceGraphics⁃

[Graphics:HTMLFiles/index_54.gif]

Out[86]=

⁃SurfaceGraphics⁃

[Graphics:HTMLFiles/index_56.gif]

Out[87]=

⁃SurfaceGraphics⁃


Created by Mathematica  (November 15, 2004)