Download - Fourier Filtering
FourierFiltering
9/8/08 Comp665–FourierFiltering 1
The first Problem set is posted on the web site, and is due on 9/23
FourierImpetus
• Therewasonemo<va<ngfactorbehindourfindingasetofEigenvectorscapableofdescribingawiderangeoffunc<ons
• ItissummedupbyoneFourierProperty:
• Spa<aldomainconvolu<onisequivalenttomul<plica<onintheFourierdomain
9/8/08 Comp665–FourierFun 2
€
x[n]∗h[n]↔ X [k ]H [k ]
AStraigh4orwardExample
9/8/08 Comp665–FourierFun 3
* =
= × Recalltherulesfor
complexmul<plica<on:(a+ib)(c+id)=ac‐bd+j(bc+ad)
FourierDomainFilters
• OUen,itisintui<vetospecifyfiltersen<relyinthefrequencydomain
9/8/08 Comp665–FourierFun 4
= ×
2DFourierConvolu>on
• Fourier‐domainConvolu<on
9/9/08 Comp665–FourierFun 8
* =
× =
Log(mag(X)) Log(mag(Y = X H))
2DFourierConvolu>on
• Fourier‐domainConvolu<on
9/9/08 Comp665–FourierFun 9
* =
× =
Log(mag(X)) Log(mag(Y = X H))
• Fourier‐domainFilter
2DFourierFiltering
9/9/08 Comp665–FourierFun 10
× =
Log(mag(X)) Log(mag(Y = X H))
Non‐SeparableConvolu>on
• Someconvolu<onkernelscannotbeseparatedintoindependentrowandcolumnfilters(buttheDFTs<llis)
9/9/08 Comp665–FourierFun 1111
* =
× =
Log(mag(X)) Log(mag(Y = X H))
• Withali`lelessblur(morehighfrequencies)
Non‐SeparableConvolu>on
9/9/08 Comp665–FourierFun 1212
* =
× =
Log(mag(X)) Log(mag(Y = X H))
BehindtheCurtains
• SimplePythoncodefragmentstoprocessimages
• Need– Python2.5– Install“easy_install”– Installscipy(includesnumpy)– InstallPIL(PythonImaginingLibrary)
9/9/08 Comp665–FourierFun 13
ASimpleImage
• Youcantypethisasascriptorexecuteitinterac<velyusing“idle”oripython(ipythoncomeswithscipy)
9/9/08 Comp665–FourierFun 14
import Image
im = Image.open(“mandrillSmall.png”) print im.size, im.format, im.mode
im.show()
MakingYourOwn
• FillinginvaluesofanImage
9/9/08 Comp665–FourierFun 15
radius = 30
h = Image.new("L", x.size, (0)) for u in xrange(x.size[0]): for v in xrange(x.size[1]): if ((abs(u-x.size[0]/2) < radius) and (abs(v-x.size[1]/2) < radius)): h.putpixel((u,v), (255)) h.show()
ConverttoaNumericalArray
9/9/08 Comp665–FourierFun 16
from pylab import *
x = im.convert(“L”) # make image one channel X = fftshift(fft2(asarray(x))) H = fftshift(fft2(asarray(h)))
mag = hypot(X.real, X.imag) t = 255.0 * mag / mag.max() Xim = Image.fromarray(numpy.uint8(t),'L') Xim.show() Xim.save(”imgMag.png", "PNG")
mag = log10(mag) t = 255.0 * mag / mag.max() Xim = Image.fromarray(numpy.uint8(t),'L') Xim.show() Xim.save("imgLogMag.png", "PNG”)