Ebook Interactive computer graphics (5th edition) Part 1

490 276 0
Ebook Interactive computer graphics (5th edition) Part 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Interactive computer graphics A TopDown approach with shaderBased OpenGL®, is the only introduction to computer graphics text for undergraduates that fully integrates OpenGL 3.1 and emphasizes applicationbased programming. Using C and C++, the topdown, programmingoriented approach allows for coverage of engaging 3D material early in the text so readers immediately begin to create their own 3D graphics.

Interactive Graphics Computer A Top-Down Approach FIFTH Using EDITION OpenGL\302\256 To Rose Mary CONTENTS x xv Preface 1.1 A pp l i c a t i o n s of 1.1.1 D is 1.1.2 D 1.1.3 1.1.4 1.2 Si m u la t io n 1.2.1 / P ix e ls and the Frame O u t p u t Devices I n p u t Devices 10 1.21 1.2.3 U p la y of e s ig A n3 and Animation Interfaces ser Computer Graphics Information System Graphics Buffer 1.3.1 I m a g e s : Physical Ob j e c t s and Viewers 1.3.2 L ig 1.3.3 Im a g e Formation 1.4 Im a g i n g Systems 1.4.1 Th e Pinhole Camera 1.4.2 1.5 Th e Th e Human Visual System 1.6 1.6.1 Th e Th e 1.6.2 1.6.3 T h r e e -D i m e n s io n a lAPIs 1.6.4 Th e 1.7 Gr a p h i c s Architectures 1.7.1 D is la y 1.7.2 1.7.3 1.7.4 Th e Graphics 1.3 ht and 12 and Images 14 Models 16 16 of 19 21 Interface Programmer's ASequence 18 Model Synthetic-Camera Pen-Plotter 10 Synthetic 11 23 24 Model 27 Images Paradigm Modeling-Rendering 28 29 Processors 30 p Pip e l i n e Architectures 30 V e r t ex 31 Pipeline Processing 32 vu viii C o n t e nts 1.7.5 Cl i p p i n g 1.7.6 Ra st e r iz a t io n3 1.7.7 F 1.8 Pr o g r a m 1.9 P and Primitive 33 r a g m e n t Processing m a b le e rfo r m a n c e 35 Notes Suggested Readings 36 36 Exercises 2.1 Th e 2.2 P 2.2.1 C o o r d i n a te 2.3 T 2.3.1 G p h ic s Functions 2.3.2 T 2.3.3 Th e 2.4 Pr i m i t iv e s and 2.4.1 P o ly g o n Basics 2.4.2 P o ly g o n Types 2.4.3 A p p 2.4.4 2.4.5 g m h e Two-Dimensional m ing O pen Systems G LA P I 40 48 Machines Attributes 52 in OpenGL ro x i m a t i n g Tex t5 Applications 45 47 Graphics Pipeline and State 49 Interface OpenGL he aSphere 53 55 2.4.6 Cu r v e d Objects A t t r i b u t e s5 2.5 C o lo r 2.5.1 RGB Color 2.5.2 In d 58 60 ex ed 62 63 Color 2.5.3 Se t t i n g of Attributes Color 65 66 2.6 V ie 2.6.1 2.6.2 Th e Orthographic View Tw o - D i m e n s io n a l Viewing 2.6.3 M 2.7 2.7.1 Con t r o l 2.7.2 As p e c t 2.7.3 Th e w in g Functions e ct io n with the Ratio 66 69 70 a t r ix Modes In t 39 Gasket Sierpinski ro 33 34 Pipelines Characteristics and Summary 32 Assembly and System Viewports 2.7.4 main, display, P r o g m Structure 2.8 Th e 2.9 Pol y g o n s Gasket 70 Window and myinit 72 Functions 74 75 Program and 71 Recursion 76 77 Contents The 2.10.1 U se s e of of 2.10.2 U H idde 2.11 P l o t t i n g Implicit 2.11.1 M Suggested Functions 86 Notes 92 Readings 94 Exercises 3.1 In t e r a ct i o n p ut 99 100 Devices 3.2 In 3.2.1 Ph y s ic a l 10 Devices Input 104 3.2.2 Lo 3.2.3 In p 3.3 Cl i e n t s and Servers 3.4 3.4.1 3.4.2 3.4.3 3.5 g ic a l Devices D is 105 Modes 107 109 p l a y Lists Execution of Display Tex t and Display Lists 112 F o n t sinGLUT 115 D e f i n i t i o n and Di s p la y and Lists 3.6 Pr o g m m in g 3.6.1 U s in g the Pointing 3.6.2 Win d ow 3.6.3 K 3.6.4 Th e 3.6.5 W 121 122 Events Display and Idle i n d o w Management 24 124 P i c k in g P ic k i n g and Selection Mode 3.9 A 3.10 Bu i l d i n g Interactive e nus Simple CAD n im a tin g s ing aTimer 126 127 133 Program Models Interactive 3.11.1 The Rotating Square 3.11.2 D o u ble Buffering U 23 Callbacks M 3.11.3 117 Input 17 Device 3.8 3.8.1 A 10 116 Event-Driven Events e y b o a rd Lists Modeling 3.7 3.11 85 AND INPUT ut 82 83 Removal Squares and Summary 80 80 Dimensions in Three Polygons n - Su rface a rc h i n g Points Three-Dimensional 2.10.3 CHAPTER Gasket Three-Dimensional 2.10 140 142 Programs 14 144 146 De s i g n of Interactive 3.12 3.12.1 Toolkit s , W idgets, and Programs the Frame Buffer 147 148 IX Contents 3.13 3.13.1 L o g i c Operations D r a w ing 3.13.2 XOR 3.13.3 Cur s o rs and Erasable Lines Color 15 and 15 53 Planes Overlay Summary and Notes 154 SuggestedReadings 155 155 Exercises TC 14 HAPTE R OBJECTS ^GEOMETRIC 4.1 Scal a r s , 4.1.1 G e o m e t r ic Objects AND TRANSFORMATIONS 160 and Vectors Points, 16 4.1.5 4.1.6 161 Coor d i n a t e -F r e e Geometry Th e Mathematical View: Vector and Affine Th e Computer Science View 63 63 Geom e t r i cADTs L i n e s1 65 4.1.7 A f f i n eSums 4.1.2 4.1.3 4.1.4 4.1.8 4.1.9 4.1.10 4.2 E x a m p l e Change 4.3.4 H o m og e n e o u s 4.3.6 4.4 E x a m p le W o r k in g F r a m e s in M o d 4.5.1 M o d e lin g 4.5.3 4.5.4 Representation 175 Coordinates 183 OpenGL e l i n g a Colored the Faces 188 a rd -an d Outward-Pointing Faces D a t a Structures for Object Representation Th e Color Cube 19 B il i n e a r Interpolation 191 V e r t ex Arrays 19 4.5.5 4.5.6 4.6 4.7 Tr a n s l a t i o n , 4.7.1 T 4.7.2 R ot a t io n Rotation, 19 19 189 18 195 e Transformations r a n s l a t io n 187 Cube In w A ff in 170 176 in Frames 179 Change 181 with Representations 4.5 4.5.2 of 168 Primitives 4.3.3 4.3.5 162 166 4.3.2 4.3.1 Spaces 16 Con v e x it y1 66 D o t and Cross Products Pla n e s1 67 T h r e e -D i m e n s io n a l C o or d i n a t e Systems and Frames R e p re sen t a t io n s and N-Tuples 172 172 Ch a n g e of Coordinate Systems 4.3 T59 and Scaling 197 Contents 4.7.3 S c a l i n g2 4.8 Tr a n s f o r m a t i o n s Tr a n s l a t io n2 03 Scali n g2 04 4.8.1 4.8.2 4.8.3 4.8.4 4.9 4.9.1 o t at io R 00 in R o t at io n About a 4.9.4 R About an 4.10 O pe n G L 4.10.1 The Current 4.10.2 Ro tati 4.10.3 Rotatio n Ord e r of 4.10.4 4.10.5 4.10.6 o n, Translation, and Scaling a Fixed Point in About 4.11.2 AVirtual Trackball 221 4.11 Smooth Rotations 224 In c r Qu a t e r n i o n s 4.12.1 4.12r2 Com 225 and Quaternions Notes 230 231 231 235 JEWING 5.1 C la s s i c a l and 5.1.1 237 C l a s s ic a l Viewing Or t h o g r a p h ic Projections Computer 5.1.2 5.1.3 A 5.1.4 Obl i q u e Projections P x o n o m e t r i c Projections e r s p e c t iv e Viewing w in g a V ie 26 228 Rotation Readings Exercises 5.1.5 5.2 220 22 Screen 226 Quat e r n io n s and | 19 Three-DimensionalApplications the ple x Numbers Suggested Matrices Popping e m e n tal Rotation Summary and 17 18 a nd 4.11.1 4.11.4 16 OpenGL 17 Transformations 4.12 215 15 Matrix Transformation Loading , Pushing, I n t e r f a c e s to U s ing Areas of 4.11 12 Matrices Transformation n goftheCube Spinni 211 Axis Arbitrary 207 208 Point Fixed 209 G e n e r a l Rotation Th e Instance Transformation o t at io n 202 05 n2 Sh e a r2 06 Con c a t e n a t i o n of Transformations 4.9.3 4.9.2 Coordinates Homogeneous with Viewing 235 237 238 240 241 Computer 242 XI xii Con t e n t s 5.3.2 Pos i t i o n in g of the Camera P o s i t io n i n g of the Camera Frame T w o Viewing APIs 249 5.3.3 T 5.3.4 Ot h e r Viewing APIs 5.4 Simple Projections 5.4.1 5.3 5.3.1 he Look-At 253 5.4.2 Pr o j e c t i o n s 5.5.1 5.5.2 5.6 5.6.1 Per s p e ct iv e in OpenGL 259 Par a l le l Viewing in OpenGL 261 5.7 5.7.1 in 257 58 OpenGL 62 Removal d e n - S u rf a c e 64 In t e r a ct i v e Mesh M e s he s2 26 Displays 266 5.7.3 W a l k i n g Through a Scene P o ly g o n Offset 268 5.8 P a r a l l e l- P r o j e c t i o n Matrices 5.7.2 5.8.1 5.8.2 5.8.3 P r o j e c t io n O r t h o g o n a l - P r o j e c t io n 5.9 P e r s p e ct i v e - P roj e c t i o n P e r s p e c t iv e O b l iq ue Projections O p 5.10 P r o j e c t i o n s and and L ig ht L i g h t Sources 6.2.1 Colo r 6.2.2 A 280 281 84 285 290 294 Sources 294 6.2.3 m b i e n t Light P o i n t Sources 296 6.2.4 Sp o t l ig h t s2 6.2.5 D i s t a n t Light Sources 6.3 T 6.3.1 A he 276 and Matter 6.2 76 Matrices Transformations Notes 271 273 Shadows Suggested Readings Exercises 285 6.1 Matrices Normalization e n G L Perspective 26 70 Normalization 5.9.1 5.9.2 Summary 254 5.5 Cu l l i n g2 44 52 Function Pe r s p e ct iv e Projections O r t h o g o n a l Projections H id 244 | 95 297 Model Lighting Phong m b i e n t Reflection 300 298 Contents 6.4.2 00 01 Th e Modified Phong Model C o m p u t a t i o n of Vectors N o r m a l Vectors 04 A n g l e of Reflection 08 6.5 Pol y g o n a l 6.5.1 F la 6.5.2 S 6.3.2 D iff u s e Reflection 6.3.3 Sp e c u la r 6.3.4 6.4 6.4.1 Reflection Ph o n g Shading 6.6 A 6.8 6.9 6.10 04 09 Shading t Shading 310 m o o t h and Gouraud 6.5.3 6.7 303 311 Shading 313 p p r o x i m a t i o n of a Sphere Li g h t Sources in OpenGL S pe ci f i c a t i o n of Materials in Sh a d i n g of the Sphere Model Gl o b a l Illumination and Notes 25 Summary SuggestedReadings Exercises 326 by Recursive Subdivision 14 17 OpenGL 20 2 23 26 'T ^M\302\273TER 7.1 7.2 7.2.1 B a s i c Implementation F o ur Strategies 32 Major Tasks 7.2.3 7.2.4 g33 Geom e try Processing R a s t e r iz a t io n3 34 F r a g m e n t Processing 7.3 C 7.4 L in 7.2.2 7.4.1 o d e lin M lip 333 35 36 336 p in g e - S e g m e n t Clipping Coh e n -S u t h e rla n d 337 Clipping 7.4.2 L ia n g -Bar s ky Clipping 339 Pol y g o n Clipping 7.5 7.6 C l i p p i n g of Other Primitives 7.6.1 7.6.2 b ou n d i n g Boxes and Volumes Cu rv e s , Surfaces, and Text 7.6.3 C lip 7.7 Cl i p p i n g 7.8 7.9 R 330 as p in g in the Frame in Three 34 344 345 Buffer Dimensions 345 346 49 te r iz a t io n Br e s e n h a m 's 341 Algorithm xiii 53V Contents 7.10 P 7.10.1 I n s id 7.10.2 Ope 7.10.3 F il landSort 7.10.4 Fl o ly g o n 354 Rasterization 354 e - Ou t s i d e Testing and Concave n GL 55 Polygons 356 357 o o dFill 7.10.5 Si n gu la r it ie s3 57 7.11 H i d d e n - S u r f a c e Removal -Spaceand Image-Space 7.11.1 Object 7.11.2 So r ting 7.11.3 7.11.4 Scan L in e 7.11.5 7.11 7.11 The z-Buffer 7.12 B and Hidden-Surface a c k- Fa Scan A Di s 7.13.1 C o lo and the Painter's Algorithm and Dith e r ing 371 72 r Systems 75 76 76 Halftoning Summary and Notes 377 SuggestedReadings Exercises 379 79 PtSCRETf TECHNIQUES _ B uf fe rs 8.2 Di g i t a l 8.3 W r i t i n g into 8.3.1 W Images Buffers 389 391 Modes r it e swithXOR r it i n g W 8.4.2 B i t and Pixel Operations O p e n G L Buffers and the Pixel Bit m a p s3 94 8.4.3 Rast e r Fonts 8.4.4 8.4.5 Pix e ls 8.4.1 67 p l a y Considerations CHAPTER 8.3.2 8.4 65 z-Buffer 369 7.13.2 Th e Color Matrix 7.13.3 Gam m a Correction 8.1 362 with the n t i a l i a s in g 7.13 7.13.4 360 61 Algorithm Sort Depth 358 Approaches Removal 360 Algorithms ce Removal Conversion 358 Lo and in 396 Images 8.5 E 8.5.1 D is 8.5.2 Test i n g Algorithms 8.5.3 B 397 x a m p le s u ff e rs for 392 95 o ku p Tables p la y i n g 392 OpenGL Pipeline 399 a Color Gamut Picking 400 401 00 436 C h a pt e r Discrete Techniques at afinerr e s olu t i on , or have supersampled it, and then have to reconstruct the world from these samples 8.12 Bump used an averaging filter Mapping and Embossing another 9, we will consider mapping technique called bump mapping, will allow us t o render objects so t t they appear to havefined et a i l (bumps) that that is affected by the light Clasgive the surface a rough appearance position is done on a fragment-by-fragment basis we can However, sically, bump mapping achievea good approximation using the accumulation buffer A surface with bumps has an embossed because we see shading appearance, differences due to the orientation of the bumps with respect to the source light Surfaces that point toward the light source will appear brighter than surfaces pointing to alter the surfaces is given away from the light The information by the relationship between the normal to the surface and the light vector Although we could use the dot product between these two vectors,' we can use the displacement matrix D in In Chapter which combination with the accumulation buffer D and a version is the difference between of it rotated in the direction source This image will have positive values where faces toward the light source and negative values where faces point point away from the light We can usethis idea as a part of the bump mapping process D as a e n d er the scene into the accumulation buffer, Suppose that wefirstr using texture Note that the texture will have a singlecolor because eachvalue of D has map of the light source and render only one component.We then shift D in the direction the scene again with this rotated image as a texture, this time subtracting the results from the accumulation buffer Finally, we re nder the image normally, that is without buffer using D , and add the result to the accumulation Note that to the shift of D for the second pass, we need the direction of the to the surface However, we have the required information to light source relative create a homogeneous coordinate matrix that can be applied to eachvertex We use the normal at the vertex\342\200\224which is part of the state\342\200\224andone of the two vectorsthat are used to define the orientation ofthe displacement function d(u, v).These texture coordinates lie in the plane of the surface and are tangent to the normal Thus, we can use either one of them and its cross-product with the normal to obtain the three vectors t t determine t he required rotation matrix Consider 8.12 an image that of the light Image Processing accumulation buffer with pixel mapping to perform various image-processingoperations.Supposethat we star t with a discrete image Peror perhaps we obtained itbydigitizing haps thisimage wasgenerated bya rendering, a continuous the image with an N xM image using a scanner.We can represent matrix, We can combine A=[atj], use of the 8.12 and Multirendering Accumulation the \342\200\242' ivMSpii t:'*v'Li a H- i ' Mm:-'M \342\200\242 > of scalar we Filtering and 8.45 FIGURE \342\200\242 convolution levels If we process eachcolor component of a color image independently, in A as either individual the entries color or gray (lumicomponents levels A linear filter produces a filtered matrix B whose elements are can regard nance) h h=S\302\243 klai+k,J+l- k=\342\200\224m l=\342\200\224n of convolving say that B is the result values of mand naresmall,and wecan We A with a filter matrix H In + representHbyasmall(2m general, the 1x In +1) matrix convolution the filtering as shown in Figure 8.45 for m = n= 1.For operation in each pixel matrix over \302\253\302\253, and take a weighted average A, we placethe convolution of t h e surrounding points Th e values in the matrix are the weights For example, for n = m = 1,w e can average each pixel with its four surrounding neighbors the using 3x3 matrix We can view 10\" \"0 11 This 1o_ can be filter used center more heavily for use more points We can antialiasing and can weigh the with 121 242 H=\342\200\224 Note 16 LI 21 that we must sions.Other define a border around are possible operations matrix 0-10 H= -1 4- 0- 10J with A if small we want B t o have the same dimenFor example, we can use the matrices Buffer 437 438 C pt e r Discrete Techniques to detect changes a or edges in value a shifted 8.12 Imaging Extensions filter lation version of A implement are going be moving the car we k, time each buffer, in glAccum coefficient filter accumu- using the operations we can process, matrix H is k x accumulation the image-processing many look closely at if we buffer, If the image by accumulating we can Although the in k images in a different using implement adding in detect a major issue efficiency we images to and from the accumulation buffer, will amounts of data the frame buffer, large among processor memory, and texture and unpacking of the arrays, memory These transfers require packing further slowing the process If we to be transferring Our development be it should fairly erations Second, to of accumulation not require should it and are not to be required supported on extensions, the imaging OpenGL the facilities supported include operations all op- graphics hardware to the have been that defines an subset First, image-processing issues these These operations standard modifications operations In fact, both perspective, there is an imaging common image-processing are an addressed.From API for the However, implementations most extension OpenGL of all most commonly supported.Some convolutions (filters), color tables, the is the subset histograms, of and transformations color On the hardware and this back to from the and color mapping transferred filtering, lookups, processor memory 8.12.5 Other seen that hardware graphics would be located within pipeline on unpacked pixels Hence, image this works pipeline and unpacked we have side, pipeline Typically, until can supports an imaging hardware, graphics data would need to be the such as table without sending images of imaging operations is complete only application any once Operations be accomplished sequence Methods Multipass also use t he accumulation jitter an object and render We can we large two things suggests techniques supports imaging support an OpenGL if buffer to add an API that simple for filtering it multiple times, buffer in time and the leaving depth positions For example, of the other If dimmer copies of the jittered object in the final image a path, rather than randomly jittered, we see the trail of the This motion-blur effect is similar to the result of taking a photograph of object a moving object using a long exposure time We can adjust the constant in glAccum so as to render the final position of the object with greater opacity or to create the we get objects unchanged, the object is moved along of speed impression differences We can use filtering in depth A real camera cannot to create focusing effects in an with all focus within a certain distance from produce image objects Objects the the camera's depth of field, are in focus; objects outside this field are out camera, of focus and appear blurred with an infinite Computer graphics produces images depth of field Occasionally, produced by because however, a real we we not want camera, or to have to worry to create defocus an about the image that of real limitations looks as part of a scene so as to though emphasize lenses it were the objects 8.13 Sampling and ' min' 'min' FIGURE m in ' 8.46 Depth-of-field ji tte r a desired depth of field Once buffer This more, we can use the accumulation in a manner that leaves a particular time, the trick is to move the viewer fixed, plane as shown in Figure 8.46 Suppose that we wish to keep the plane at z = Zc in focus, and to leave the near (z = zmk) and far (z = zmax) distances clipping unchanged If we use glFrustum , we specify the near clipping (xmin, xmax> ymin, ymax) If rectangle we move the viewer from the origin in the x direction by Ax, we must change x to within ' \342\200\224 j _ \342\200\224 x ^ x ( z mm>^ *min Z f ~ ^ear-'* f a narrower equations hold for of field depth 8.13 SAMPLING AND ALIASING Similar xmax, ymin, and ymax- As we increase Ax and Ay, we create in which the conversion from a continuous discrete of that leads t o visible representation entity approximation entity errors in the display We have used the term aliasing to characterizetheseerrors When we work with buffers, we are always with digital images, and, if we working In this section,we examine are no t careful, these errorscan be extreme the nature of errors digital images and gather facts that will help us to understand where aliasing arise and how th e effects of these errorscan be mitigated We star t with a continuous two-dimensional image/(x, y) We can regard the value of/ as either a gray level in a monochromatic image or the value of one of the in a color image.In the computer, we work with a digital image that is an primaries as n rows of m pixels Each pixel has k bits There aretwo array of nm pixels arranged in involved from a continuous First, we processes going image to a discreteimage must sample the continuous at nm on some obtain a set ofv alu e s image points gridto Each of these samples of th e continuous {/\342\200\242\342\200\242} image is the value of/ measured over a small area in the continuous image Then we must convert each ofthese samplesinto a k-bit pixel by aprocess known as quantization We have seen a variety of an of applications to a Aliasing 439 440 Chapter Disc rete Techniques 8.13.1 Sampling Theory that we have a rectangular grid of locations where we wish in Figure 8.47 If we assume that the grid is samples of/, as shown then an ideal samplerwould a value produce Suppose y te 'r / f{*o y0) = oo FIGURE 8.47 obtain our spaced, V Sampling grid (b) FIGURE 8.48 to equally One- dimensional decomposition, (a) Function, (b) Components h are the distances between the grid points in the x and y directions, hx and such a respectively Leaving aside for now the fact that no real sampler can make precise measurement, there are two important questions First, what errors have we in the made in this idealized sampling process? That is, how much of the information in the sampled image? Second, can we go back from the original image is included to a continuous with out additional errors? This latter digital image image incurring in step is calledreconstructionand describes display processes such as are required the contents of a frame buffer on a monitor displaying The mathematical of these issues uses Fourier a branch of apanalysis analysis, well suited for explaining of digital signal plied mathematics particularly problems of either processing The essenceof Fourier theory is th at a function, space or tim e, can be decomposed into a set of sinusoids, at possibly an infinite number of frequencies.This conceptis most familiar with sound, where we routinely think of a particuin terms of its frequency lar sound or spectrum For a two-dimensional components in two spatial we can think of it as being composed of sinusoidal image, patterns when added together, produce the image.Figure shows a that, 8.48(a) frequencies one-dimensional function; shows t he two sinusoids that form it; Fig8.48(b) Figure ure 8.49shows two-dimensional functions Thus, every two-dimensional periodic function One is its spatial form spatial fix, y) has two equivalent representations /(x, y); the other is a representation in terms ofits spectrum\342\200\224the frequency-domain t o / at the two-dimensional representationg(\302\243, rj) The value ofg is the contribution these alternate off u n ct i o n s , we find (\302\243, spatial frequency rj) By using representations where that many frequency phenomena, domain including sampling, can be explained (b) (a) FIGURE 8.49 Two-dimensional periodic functions much more easilyin the 8.13 We can explain of sampling, without overwhelmed being by without the fundamental theorem known as the accept, proof, theorem There are two parts to the theorem: The first allows us to whereas the second governs reconstruction We examine the errors, the the mathematics,if sampling Nyquist discuss sampling secondin Section consequences we 8.13.2 sampling theorem (part information in the function is sampled at a frequency function Nyquist all the contain Sampling original greater of a continuous function samples function if and only if the continuous in the than twice the highest frequency ideal of not losing information, we must restrict ourthe frequency domain of w id th except in a window less than the sampling frequency, centered at the origin The lowest frequency that cannot be in the data so as t o avoid of the sampling frequency\342\200\224 aliasing\342\200\224one-half is called the Nyquistfrequency.F u n c ti on s whose spectra are zero outside of some window are known as band-limited functions For a two-dimensional image, the are determined the of a two-dimensional with sampling frequencies by spacing grid x and y spacing of \\/hx and \\/hy, The theorem assumes an ideal samrespectively an infinite number of samples,eachof which is the exact pling process that gathers value at the grid point In practice, we can take only a finite number of samples\342\200\224the number the resolution of our buffer Consequently, we cannot produce a matching band-limited function this result is a mathematical truly Although consequence of in Fourier we can observe that there will be some inherent theory, always ambiguity a finite collection of sampled points, simply because we not know the function outside the region from which we obtained the samples The consequences of violating the Nyquist criteria are aliasing errors We can see where the name aliasing derives by considering an ideal sampling process Both the function and its set of sampleshave frequency-domain original representations The spectral components of the sampled function are replicas of the spectrum of the original function, with their centers separated by the sampling Confrequency in Figure 8.50(a), with the samples indicated sider the one-dimensional function in Figure 8.50(c), we have the spectrum its spectrum; of the Figure 8.50(b) shows in Figure 8.50(b) Bethe replications of the spectrum sampled function, showing causewe have sampled at a rate higher than the Nyquist frequency, there is a separation between the replicas Now consider the case in Figure 8.51 Here we have violated the Nyquist criteand the replicas overlap Consider the central is magnirion, part of the plot, which fied in Figure 8.52 and shows only the central replica,centeredat the origin, and the Thus, if we are to selvesto functions have 1): The that any chance are zero in 8.This statement assumes no knowledge of the underlying function/, other than a set of its samples Ifwe have additional information, such as knowledge that the function is periodic, knowledge of the unction over a finite interval can be sufficient to determine the entire function of the spectrum becausethe Fourier transform produces complex num) We sh o w the magnitude jers for the frequency-domain components and Aliasing 441 442 Chapter Discrete Techniques 1)1 \\gi) fix) a (c) (b) FIGURE 8.50 spatial Band-limited function, domain, (b)Spectrum ofthe (a) Function function, and (c)Spectrum its samples in the of the samples >0f) /YYYYX FIGURE 8.51 Overlapping ^o FIGURE 8.52 replica to \302\243A) replicas ^s Aliasing at \302\243s Thefrequency\302\243 is above the Nyquist frequency a replica of ^0,generatedby the sampling process from the \342\200\224 on the right, at \302\2435 e s s t n the Nyquistfrequency.T h e en\302\2430, replica afrequencyl ifwe are dealing with sound, or seen, ifwe ergy at thisfrequencyc an beheard, digital are considering two-dimensional images We say that thefrequency^ has an alias at \342\200\224 Note that once aliasing has occurred, we cannot between infor\302\243s \302\2430 distinguish mation that was at afrequencyi n the original data and information that was placed at thisfrequencyb y the sampling process We can demonstrate without aliasing and ambiguity using Fourier analysis by at a single sinusoid, as shown in Figure 8.53 If we sample this sinusoid at looking twice itsfrequency,w e can recoverit from two samples However, these sametwo n d can also be samples are samples of a sinusoid of twice thisfrequency,a samples of ll thesefrequenciesa re aliases sinusoids of other multiples of the basicfrequency.A of th e same originalfrequency.I f we know t h at the data were band limited, however, then the samples can describe only t h e original sinusoid \302\2435/2 There its right, centered is, however, 8.13 Sampling v/WVW FIGURE 8.53 a sinusoid of Aliasing f(x,y) FIGURE 8.54 (a) Point Scanning sampling, (b) an image, Ar ea averaging If we were to an analysis of the frequency content of real-world we images, in the would find that the spectral components of most are concentrated images lower frequencies Consequently, it is impossible to construct a finite-sized although errors often are minimal because there islittle image that isband limited,the aliasing in frequencies content above th e Nyquist and little content is aliasedinto frequency, below t he Nyquist The exceptions to this statement arise when frequencies frequency in the continuous In the frequency there is regular information (periodic) image If an y at a few frequencies representation, regularity places m o st of the information of these frequencies is above the Nyquist the effect is noticeable as limit, aliasing beat or moire patterns Examples that you might have noticed include the patterns that appear on video displays when shirts or plaid people in the imageswear striped ties, and wavy patterns that arise both in printed (halftoned) figures derived from and in digital images of farmland with plowed fields computer displays before we scan an image or by Often, we can minimize aliasing by prefiltering 8.54 controlling the area of th e data that the scanner uses to measurea sample Figure shows two possibleways to scan an image In Figure 8.54(a), we see an ideal scanner It measures the value of a continuous image at a point, so the samplesare given by and Aliasing 443 444 Chapter Discrete Techniques On the we have right, a more realistic weighted average over a small samples of th samples taking by a e form M+S/2 l>x;+s/2 fii= / obtains that scanner to produce interval / f(x,y)w(x,y)dydx Jv:-s/2 Jx;-sl2 window s an d the weighting function w, we can attenuate in the image, and thus we can reduce aliasing Fortutake measurements over afiniter egion , called the sampling nately, real scanners must of aperture; thus, some antialiasing takes place evenif t he user has no understanding the abasing problem of the By selecting the size high-frequency components Reconstruction Suppose we have an (infinite) 8.13.2 set that sampled at a rate greater uous function from the Nyquist sampling ^2 fi /(*)= The theorem (part 2): part can reconstruction The of the sampling Nyquist reconstruct have of a been contin- theorem a continuous function/(x) formula sinc(x-*,\342\200\242) sinc(x) shown function We the members of which st frequency samplesis basedon {/\342\200\242} by the its samples from of samples, the Nyqui than in Figure 8.55 is defined as SU17TX sinc(x) = nx The two-dimensional with ideal version samples FIGURE 8.55 is {\302\243,} Sine function of the reconstruction formula for a function f(x, y) 8.13 FIGURE 8.56 One-dimensional reconstruction FIGURE 8.57 Two-dimensional sine function Z fijsinc (x /(*\302\273y)=\302\243 i=\342\200\224oo ;=\342\200\224oo - x f) s\" 10 ^ Sampling formulas follow from the 445 7y)- that we can recover an unaliased funcin a filter that is zero the interval frequency by using except number (\342\200\224\302\243s/2, \302\243s/2)\342\200\224a low-passfilter\342\200\224too b t ain a single replica from the infinite in Figure 8.50 The reconstrucof replicas generated by th e sampling process shown in Figure 8.56 In two dimensions, the tion of a one-dimensional function is shown reconstruction involves the use of a two-dimensional sine, as shown in Figure 8.57 in the sine function cannot be Unfortunately, produced a physical display, because of its negative side lobes Consider the display for a CRT display We start with problem a digital image that is a set of samples.For each sample, we can place a spot of light in Figure 8.58 The valu e of centered at a grid point on the display surface, as shown the sample controls the intensity of the spot, or modulates the beam We can control the of the such as thebeam The reconstrucshape spot by using techniques focusing tion formula tells us that the beam should have the shape of a two-dimensional sine, These tion in the and Aliasing fact domain FIGURE 8.58 point on a CRT Display of a 446 Chapter Discrete Techniques XA JL (c) (b) FIGURE 8.59 tion, (c) Display spots, Piecewise-linear but because beam the approximation, puts (d) (a) Ideal spot, (b) (d) out energy, the must the spot approximation be nonnegative must make errors Consequently, display process by considering how well its sp ot approximates sine a nd several one-dimensionalapproximations approxima- Rectangular Gaussian We can evaluate at all points a real display 8.59 shows the The Gaussian-shaped spot corresponds to the shape of many CRT spots, whereas the rectangular spot might correspond to an LCD display with square pixels.Note that we can make either approximation wider or narrower If we analyze the spot profiles in the frequency domain, h at the wider spots are more accurateat low frequencies wefindt but are less accurate at high frequencies In practice, the spot size that we chooseis a compromise Visible differences across monitors often can be traced to different spot profiles 8.13.3 a a quantizer FIGURE 02039A 8.60 Quantizer explains a number the effect of each sample being scalar function g with values in the range analysis not levels.Given i9l desired sine Figure Quantization The mathematical ever,we have 1(g) the is a ofsampling included function q such that if g {

Ngày đăng: 16/05/2017, 10:28

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan