HW 5, Problems 5.2
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 midpoint  filter?
(b) 7x7 ?
(c) 9x9 ?

Answer

Median filter is given by f(x, y) = (1/2)[Max(g(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.

Clear["Global`*"];
nma`cd;
nRow = 256; 
nCol = 256;
data = 
        nma`imread["Prob5.01.raw", nRow, 
          nCol];
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 Filter

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

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

Filter the image with Min 3x3 and display result

nImage3 = 
        nma`filterGMF[data, F3];

    nma`imshow[Round[N[nImage3]], "GMF 3x3"]

Show the top edge of the white bar BEFORE processing

nma`imshow[Round[N[Take[data, {20, 30}, {20, 35}]]], ""]

Show the top edge of the white bar AFTER processing

nma`imshow[
      Round[N[Take[nImage3, {20, 30}, {20, 35}]]], ""]

Look at the data before:

Take[Round[N[data]], {23, 26}, {25, 35}] // MatrixForm

Look at the data after filtering

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

So we see that the white bar is now is thinner it is  5 pixels wide,  So, there is more blck pixels. ALso the strip will be 4 rows shorter, so it is now 206 pixels high.

7x7 Filter

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

Now show the top of the white strip.

nma`imshow[
      Round[N[Take[nImage7, {23, 30}, {25, 31}]]], ""]

Take[Round[N[nImage7]], {23, 30}, {25, 31}] // MatrixForm

So we see that the white bar is now is thinner, it is  1 pixels wide. The strip is turning to all to black.

9x9 Filter

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

The strip is all black now.

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.

ListPlot3D[Take[data, {12, 40}, {15, 65}], 
      PlotLabel -> "original data"]
ListPlot3D[Take[nImage3, {12, 40}, {15, 65}], 
      PlotLabel -> "3x3 data"]
ListPlot3D[Take[nImage7, {12, 40}, {15, 65}], 
      PlotLabel -> "7x7 data"]
ListPlot3D[Take[nImage9, {12, 40}, {15, 65}], 
      PlotLabel -> "9x9 data"]