Chapter Freqency Domain Processing Objectives: We will learn abot ilters that are carried ot in the reqency domain. In addition to being the base or linear iltering, Forier Transorm oers considerable lexibility in the design and implementation o iltering soltions in areas sch as image enhancement, image restoration, image data compression, and a some other applications. The reqency and spatial iltering can be combined to achieve reslts that are beyond what each can achieve individally. Forier Transorm Forier transorm o a nction x one-dimensional is: F j π x x e dx where j. We can obtain the x sing the inverse Forier Transorm. j π x F x F e d The two-dimensional version o this eqations are: F, v j π x vy x, y e dxdy And the inverse Forier Transorm or this one can be shown as: j π x vy x, y F, v e ddv
Discrete Forier Transorm To do any o these on a compter we need the discrete versions. For one dimensional case sppose we have M discrete points. In the two dimensional case, assme we have M and N discrete points in x and y directions respectively. One-dimensional: M F xi e M i 0 The inverse transorm is: j πx / M i or 0,,,3,..., M M x F i 0 i e j π x / M i or x 0,,,3,..., M 3
5 Two-dimensional: 0 0 / /,, M i N k N vy M x j k i k i e y x MN v F π Discrete Forier Transorm Where, x,y denotes the inpt image with: x 0,,,, M- and y 0,,,, N- representing the nmber o rows and colmns o the M-by-N image. The inverse transorm is: 0 0 / /,, M i N k N y v M x j k i k i e v F y x π Remember that we have: sin cos θ θ θ j e j Since images are -D arrays, we work with these two. 6 [ ],, tan, : Spectrm Phase,,,, : Spectrm Power,,, : Spectrm Forier / v R v I v v I v R v F v P v I v R v F φ Discrete Forier Transorm
What are they? The vale o the transormation at the origin o the reqency domain [I.e., F0,0] is called the dc component o the Forier Transorm. F0,0 is is eqal to MN times the average vale o x,y Even i x,y is real, it transormation in general is complex. To visally analyze a transorm, we need to compte its spectrm. I.e., compte the magnitde o the complex variable F, v and display it as an image. F,v can also be represented as: F, v F, v e jφ, v 7 Discrete Forier Transorm Example Compte the Forier transorm o the nction shown below: x,y A y Y X x 8
9 Example FFT Compte the FFT o x x. Let s only comptes or reqencies. 0,,,3,..., or 0 / M e x M F M i M x j i i π 3 0,,, or 3 0 / and e x F i x j i i π 3 6 0 3 0 3 0 0 03/ 0 / 0 / 00 / e e e e F j j j j π π π π 0 j --... 3 0 3 0 / 3 / 3 / / / 0 / π π π π π π π j j j j j j j e e e e e e e F F - F3 - - j
Example >> zeros5,5; >> 5:65,35:75; >> imshow Example - cont >> F t; >> F logabsf; >> imshowf
Example cont Centering the spectrm F t; F logabsf; imshowf or i :5 or j :5 i,j -^ij*i,j; end end F t; F logabsf; igre,imshowf 3 This is what happened
5 Filtering in the reqency domain In general, the ondation o linear iltering in both the spatial and reqency domains is the convoltion theorem: x, y h h, y H, v F, v Conversely, we will have: x, y h h, y H, v* G, v Here, the symbol * indicates convoltion o the two nctions, and the expression on sides o the doble arrow denotes Forier Transorm pair. We are interested in the irst one, where iltering in spatial domain consists o convolting an image x,y with a ilter mask, hx,y. Based on the convoltion theorem we can obtain the same reslt by mltiplying F,v by H,v, the Forier transorm o the spatial ilter. It is common to reer to H,v as the ilter transer nction. 6
Convoltion and Correlation Example: Occrrences o a letter in a text 7 Read the Original Image, Store it in array text Determine the size, Let s say p, q Read the image o the letter, Store it in an array l Determine the size, Let s say n, m Rotate the image o the letter by 80 Compte the FFT o the letter, pad it to the p, q size Compte the FFT o the text 8
Mltiply element-by-element the two Take the Real part o the reslt Mltiply element-by-element the two Find the MAX Threshold based on the MAX Display 9 Based on convoltion theorem: To obtain corresponding iltered image in the spatial domain we simply compte the inverse Forier transorm o the prodct o H,vF,v. This is identical to what we wold obtain by sing convoltion in the spatial domain, as long as the ilter mask hx,y is the inverse Forier transorm o H,v. Convolving periodic nctions can case intererence between adjacent period i the periods are close with respect to the dration o the nonzero parts o the nctions. 0
This intererence, wraparond error, can be avoided by padding the nctions with zeros as explain below. Assme that nctions x,y and hx,y are o size AXB and CXD, respectively. Form two extended padded nctions both o size PXQ by appending zeros to and h. The wraparond error is avoided by choosing: P A C and Q B D In MATLAB, we will se F t, PQ, PQ This appends enogh zeros to sch that the reslting image is o size PQ*PQ, then comptes the FFT.
3
Basic Steps in DFT Filtering 5 Basic Steps in DFT Filtering. Obtain the padding parameters sing nction paddedsize: PQ paddedsizesize;. Obtain the Forier transorm with padding: F t, PQ, PQ; 3. Generate a ilter nction, H, o size PQXPQ sing one o the methods discssed in the remainder o this chapter. The ilter mst be in the ormat shown in Fig.b. I it is not in that ormat, se shit to make it.. Mltiply the transorm by the ilter: G H.* F 6
Basic Steps in DFT Filtering 5. Obtain the real part o the inverse FFT o G: g realitg; 6. Crop the top, let rectangle to the original size: g g:size,, :size, ; 7 Example or DFT Filtering Try this or [0 0; ]; PQ paddedsizesize; Fp t, PQ, PQ; HP lpilter gassian, PQ, PQ, *sig; GP HP.* Fp; gp realitgp; gpc gp:size,, :size,; %cropping imshowgp, [ ] Similar reslt as: w special'gassian', 3,3; gnew imilterdoble, w 8
Obtaining Freqency Domain Filters rom Spatial Filters In general, iltering in the spatial domain is more eicient comptationally than reqency domain iltering when the ilters are small. One obvios approach or generating a reqency domain ilter, H, that corresponds to a given spatial ilter, h, is to let: H th, PQ, PQ, where the vales o vector PQ depend on the size o the image we want to ilter, as discssed in the last section. Bt we need to know: 9 Obtaining Freqency Domain Filters rom Spatial Filters How to convert spatial ilters into eqivalent reqency domain ilters, How to compare the reslts between spatial domain iltering sing nction imilter, and reqency domain iltering. 30
600x600 image F t S tshitlog absf; S gscales; imshows 3 Generate the spatial ilter sing special: h special sobol h 0-0 - 0 - To view a plot o the corresponding reqency domain ilter: 3
reqzh 33 PQ paddedsizesize; H reqzh, PQ, PQ; H itshith; Origin at the top 3
absh 35 absh 36
Next, we generate the iltered images. In spatial domain we se: gs imilterdoble, h; Which pads the border o the image with 0. The iltered image obtained by reqency domain processing: g dtilt, H; Download the dtilt, paddedsize, and other related iles rom the notes web page. 37 gs imilterdoble, h; 38
g dtilt, H; Negative vales are presented. Average is below the mid-gray vale. 39 imshowabsgs, [ ] 0
imshowabsg, [ ] Using thresholding we can see the bondaries better absgs > 0.*absmaxgs:
Using thresholding we can see the bondaries better absg > 0.*absmaxg: 3 Generating Filters Directly in the Freqency Domain We discssed circlarly symmetric ilters that are speciied as varios nctions o distance rom the origin o the transorm. One o the things we need to compte is the distance between any point and a speciied point in the reqency rectangle. In MATLAB, or FFT comptations the origin o the transorm is at the top-let o the reqency rectangle. Ths, or distance is also measred rom that point. In order or s to compte sch a distance, we need the meshing system. This is what we call meshgrid array and is generated by dtv nction.
Example Here is an example o distance comptation. In this example we will compte the distance sqared rom every point in a rectangle o size 8x5 to the origin o the reqency rectangle. >> [U, V] dtv8, 5; This comptes meshgrid reqency matrices U and V both o size 8-by-5. >> D U.^ V.^ 5 U 0 0 0 0 0 3 3 3 3 3-3 -3-3 -3-3 - - - - - - - - - - V 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 6
D 0 5 5 5 8 8 5 9 0 3 3 0 6 7 0 0 7 9 0 3 3 0 5 8 8 5 5 5 7 U 0 0 0 0 0 3 3 3 3 3-3 -3-3 -3-3 - - - - - - - - - - V 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - D 0 5 5 5 8 8 5 9 0 3 3 0 6 7 0 0 7 9 0 3 3 0 5 8 8 5 5 5 8
nction [U, V] dtv[m, N] 0: M-; v 0: N-; idx ind > M/; idx idx M; idy indv > N/; vidy vidy N; [U, V] meshgrid, v; The meshgrid nction will prodce two arrays. Rows on U are copies o rows in and colmns on V are copies o colmns on v. 9 The distance with respect to the center o the reqency rectangle can be compted as: >> tshitd ans 0 7 6 7 0 3 0 9 0 3 8 5 5 8 5 5 0 5 5 8 5 5 8 3 0 9 0 3 50
Lowpass Freqency Domain Filters An Ideal Lowpass Filter ILPF has the transer nction: i D, v D0 H, v 0 i D, v > D0 Where D 0 is a speciied non-negative nmber and D,v is the distance rom point, v to the center o the ilter. The D,v D 0 alls on a circle. Since we mltiply ilter H by the Forier transorm o an image, an ideal case wold be where all components o F otside the circle gets ct o, i.e. gets mltiplied by 0 and keep the points in/on the circle nchanged. 5 Lowpass Freqency Domain Filters cont. A Btterworth lowpass ilter BLPF o order n, with a cto reqency at distance D 0 rom the origin, has the transorm nction: Unlike ILPF, this one does not have a shape discontinity at D 0. In this transormation when D,v D 0,H,v will be 0.5, or down 50% rom its maximm vale. The Gassian lowpass ilter GLPF is given by: Where σ is the standard deviation. H I we let σ D 0 we will obtain: What wold be H,v For H D,v D 0? [ D, v / D0] H, v n, v e, v e D D, v/ σ 5, v/ D 0
GLPF 0.9 e^-p/ 0.8 0.7 0.6 0.5 0 0. 0. 0.6 0.8 p Where p D,v/D 0 53 Example: Create a 3x3 ilter in the reqency domain. 5
Example Original Image 55 PQ paddedsizesize; [U, V] dtvpq, PQ ; D0 0.05*PQ; F t, PQ, PQ; H exp- U.^ V.^/*D0^; igre, imshowtshith, [ ] 56
Spectrm: igre, imshowlog abstshitf,[ ] 57 g dtilt, H; igre, imshowg, [ ] Note: The lpilter generates the transer nctions o all the lowpass ilters discssed in this chapter. Yo need to copy this ile rom the notes web page. 58
Sharpening Freqency Domain Filters Jst as lowpass iltering blrs an image, the opposite will happen in case o highpass iltering. Highpass ilters sharpen the image by attenating the low reqencies and leaving the high reqencies o the Forier transorms relatively nchanged. Basics o highpass iltering Given the transer nction H p,v o a lowpass ilter, we obtain the transer nction o the corresponding highpass ilter by sing the simple relation: H hp, v H p, v The nction hpilter is sed in MATLAB to generate highpass ilters. 59 Highpass Filter Options with hpilter hpiltertype, M, N, D0, n It creates the transer nction o a highpass ilter, H, o the speciied TYPE and size M-by-N. ideal : Ideal highpass ilter with cto reqency D0. No need or n, and D0 mst be positive. btw : Btterworth highpass ilter o order n, and cto D0. The dealt vale or n is.0. D0 mst be positive. gassian : Gassian highpass ilter with cto standard deviation D0. No need or n, and D0 mst be positive. 60
Example Ideal highpass ilter H tshithpilter ideal, 500, 500, 50 ; meshh:0:500, :0:500; axis[0 50 0 50 0 ] colormap[0 0 0] axis o axis o 6 Example Ideal highpass ilter Corresponding image to This one is shown on the right hand side igre, imshowh, [ ] 6
Example Btterworth highpass ilter H tshithpilter btterworth, 500, 500, 50 ; meshh:0:500, :0:500; axis[0 50 0 50 0 ] colormap[0 0 0] axis o axis o 63 Example Btterworth highpass ilter Corresponding image to This one is shown on the right hand side igre, imshowh, [ ] 6
Example Gassian highpass ilter Corresponding image to This one is shown on the right hand side 65 PQ paddedsizesize; D0 0.05*PQ; H hpilter gassian, PQ, PQ, D0; g dtilt, H; igre, imshoowg, [ ] 66
High-Freqency Emphasis Filtering Highpass iltering zero ot the dc term, ths redcing the average vale o an image to 0. An approach to compensate or this is to add an oset to a highpass ilter. When an oset is combined with mltiplying the ilter by a constant greater than, the approach is called highreqency emphasis. The mltiplier increases the amplitde o low reqencies, bt low reqency eects on enhancement are less than those o high reqencies. The high-reqency emphasis transer nction is deined as: H he, v a bh hp,v Where a is the oset, b is the mltiplier, and H hp,v is the transer nction o a highpass ilter. 67