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 \(TraditionalForm\`f(x, 
          y) = \(m\ n\)\/\(∑\+\(x, y = s\)\%□ 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.

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

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.

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

3x3 processing

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

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

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

Show the top edge of the white bar BEFORE processing

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

Show the top edge of the white bar AFTER processing

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

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

\(\(\(
\)\(\(Take[Round[N[nImage3]], {21, 27}, {25, 35}] // 
      MatrixForm\)\(
\)
    \)\)\)

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

HMF7 = HMF[7];
nImage7 = nma`filterHMF[nData, HMF7];
nImage7  =  nImage7 - 1;
nma`imshow[Round[N[nImage7]], "HMF 7x7"]

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

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

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

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

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

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

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"]
ListPlot3D[Take[nImage3, {20, 30}, {20, 50}], 
      PlotLabel -> "3x3 data"]
ListPlot3D[Take[nImage7, {20, 30}, {20, 50}], 
      PlotLabel -> "7x7 data"]
\(ListPlot3D[Take[nImage9, {20, 30}, {20, 50}], 
      PlotLabel -> "9x9 data"]

\)