HW6, computer problem
EECS 203A, UCI, Fall 2004

by Nasser Abbasi


FIrst start by reading my Mathematica pakcage. This contains Mathematica functions I have written for basic image processing and filtering

In[1]:=

Clear["Global`*"] ;

<<nma.m

<<ImageProcessing`

In[4]:=

g2D[x_, y_, σ_] := 1/((2 π)^(1/2) σ) ^(-(x^2 + y^2)/(2 σ ... rd deviation=5"] ; ] Show[GraphicsArray[{p1, p2}]] 

[Graphics:HTMLFiles/index_5.gif]

Out[6]=

⁃GraphicsArray⁃

Now, sample a 2D continuos gaussian to obtain a discrte version of Gaussian 2D, to use as a filtering window to convolve the image with

In[7]:=

nma`cd

Directory[]

Out[7]=

F:\\nabbasi\\data\\nabbasi_web_Page\\academic\\my_courses\\EECS_203A_UCI_FALL_2004\\HW6\\computer_prob

Out[8]=

F:\\nabbasi\\data\\nabbasi_web_Page\\academic\\my_courses\\EECS_203A_UCI_FALL_2004\\HW6\\computer_prob

In[54]:=

nRow = 480 ; nCol = 640 ;

f = BinaryReadList["triangle.raw"] ;

f = Partition[f, nCol] ;

Print["Image has dimensions ", Dimensions[f]] ;

fsaved = Chop[N[f]] ;

Print["Max[f]=", Max[f]] ;

Print["Min[f]=", Min[f]] ;

Image has dimensions  {480, 640}

Max[f]=255

Min[f]=148

Now create the 2D gaussian filter, have it centers at the center of the image

In[14]:=

σ = 5 ;

 nRowG = 480 ; nColG = 640 ;

h = Table[g2D[x, y, σ], {x, - nRowG/2, nRowG/2 - 1}, {y, - nColG/2, nColG/2 - 1}] ;

hsaved = Chop[N[h]] ;

Print["Min value of gaussian, std=5, is ", Min[h]] ;

Print["Max value of gaussian, std=5, is ", Max[h]] ;

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

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

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

Min value of gaussian, std=5, is 1/(5 ^3200 (2 π)^(1/2))

Max value of gaussian, std=5, is 1/(5 (2 π)^(1/2))

Now generate 'g', the degraded image

h = hsaved ; f = fsaved ; G = DFT[h] DFT[f] ; G = nm ... ngleDegraded.raw", Round[N[t]], "Byte"] ; ArrayPlot[Round[Re[g]]]

Out[239]=

5.7662

Out[240]=

3.34666

[Graphics:HTMLFiles/index_35.gif]

Out[244]=

⁃Graphics⁃

In[135]:=

Export["triangleDegraded.raw", t, "Byte"] ; (*file = Ope ... atten[t], "Character8"] ; Close["triangleDegraded.raw"] ; *)

g = nma`centerImage[Re[g]] ;

G = DFT[g] ; 

Print["degraded image dimensions=", Dimensions[g]] ;

degraded image dimensions= {480, 640}

Now center the images, and generate their DFT

f = nma`centerImage[f] ;

h = nma`centerImage[h] ; 

F = DFT[f] ;

H = DFT[h] ; 

Block[{$DisplayFunction = Identity}, p0 = ArrayPlot[f, PlotLabel"f, inp ... ot;] ; p22 = ArrayPlot[Arg[G], PlotLabel"Phase G"] ; ]

Show[GraphicsArray[{p0, p1, p2}]] ;

Show[GraphicsArray[{p01, p11, p21}]] ;

Show[GraphicsArray[{p02, p12, p22}]] ; 

[Graphics:HTMLFiles/index_50.gif]

[Graphics:HTMLFiles/index_51.gif]

[Graphics:HTMLFiles/index_52.gif]

(*Show[GraphicsArray[ListPlot3D[#1, PlotRangeAll, DisplayFunctionIde ... [G]=", Max[Abs[G]], "  Min Element in Abs[G]=", Min[Abs[G]]] ; 

Size of F= {480, 640}

Max element in Re[F]=126959.  Min Element in Re[F]= -6050.16

Max element in Im[F]=6806.46  Min Element in Im[F]= -6806.46

Max element in Abs[F]=126959.  Min Element in Abs[F]=0.000544455

Size of H= {480, 640}

Max element in Re[H]=0.0226125  Min Element in Re[H]= -0.0225853

Max element in Im[H]=2.73996*10^-18  Min Element in Im[H]= -2.80906*10^-18

Max element in Abs[H]=0.0226125  Min Element in Abs[H]=1.41499*10^-17

Size of G= {480, 640}

Max element in Re[G]=2870.87  Min Element in Re[G]= -136.352

Max element in Im[G]=153.582  Min Element in Im[G]= -153.582

Max element in Abs[G]=2870.87  Min Element in Abs[G]=3.69973*10^-17

Now generate restored image

{nRow, nCol} = Dimensions[G] ;

{hRow, hCol} = Dimensions[H] ; (*divide center of G/H *)

GG = G/ H ;

Print["Result of G/H has dimensions = ", Dimensions[GG]]

ArrayPlot[10 Log[Abs[GG]], PlotLabel->"Log[Abs[RestoredImage]]"] ;

ArrayPlot[Arg[GG], PlotLabel->"Phase RestoredImage"] ;

m = nma`centerImage[GG] ;

[Graphics:HTMLFiles/index_73.gif]

[Graphics:HTMLFiles/index_74.gif]

ff = InverseDiscreteFourierTransform[m] ; 

ff = nma`centerImage[Re[ff]] ; 

Close["triangleRestore.raw"] ;

file = OpenWrite["triangleRestore.raw", BinaryFormatTrue] ;

BinaryWrite[file, Floor[ff], Character8] ;

Close["triangleRestore.raw"] ; 

ArrayPlot[ff, PlotLabel->"restored Image"] ; 

Block[{$DisplayFunction = Identity}, p0 = ArrayPlot[f, PlotLabel"f, inp ...  = ArrayPlot[ff, PlotLabel"ff, restored  image"] ; ]

Show[GraphicsArray[{p0, p1, p2}]] ;

[Graphics:HTMLFiles/index_84.gif]

[Graphics:HTMLFiles/index_85.gif]


Created by Mathematica  (November 24, 2004) Valid XHTML 1.1!