2D Imaging and Transformations2D geometric transformsTranslationGroups and composition2D rotationsEuclidean transformsProblems with this formChoosing a SubspacePlaying with Euclidean transformsSimilitude transformsPlaying with Similitude transformsAffine transformsAffine transformsDetermining affine transformsSolution methodProjective transformsProjective spaceProjective transformsDetermining projective transformsDetermining projective transformsProjective exampleOpenGL imagingOpenGL SetupDisplaying an imageTexture mappingHow to set up a texture mapApplying the texture mapNext time1/22/0712D Imaging and TransformationsComputer GraphicsCOMP 770 (236)Spring 2007Instructor: Brandon Lloyd1/22/0722D geometric transforms■ Functions for mapping points from one place to another■ Geometric transforms can be applied to° drawing primitives(lines, conics, triangles)° pixel coordinates of an image1/22/073Translation■ Translations have the following form:x' = x + txy' = y + ty■ inverse function: undoes the translation:x= x' -txy = y' - ty■ identity: leaves every point unchanged. x' = x + 0y' = y + 01/22/074Groups and composition■ Translations: 1.There exists an inverse mapping for each function 2.There exists an identity mapping ■ Functions with these properties are closed under composition■ Referred to as an algebraic group1/22/0752D rotations■ Another group - rotation about the origin:1/22/076Euclidean transforms■ Euclidean Group° translations + rotations■ Properties:° Preserve distances ° Preserve angles ° How do you represent these functions?1/22/077Problems with this form■ Translation and rotation considered separately■ Inverse transform involves multiple steps ■ Order matters between the R and T parts■ Problem remedied by considering our 2D plane as a subspace within 3D.1/22/078Choosing a Subspace ■ Can use any planar subspace that does not contain the origin■ WLOG assume our 2D space lies on the 3D plane z = 1.Now we can express all Euclidean transforms in matrix form:■ This gives a three parameter group of transformations.1/22/079Playing with Euclidean transforms■ In what order are the translation and rotation performed? ■ Will this family of transforms always generate points on our chosen 3-D plane? Why?1/22/0710Similitude transforms■ Similitude Group:° 4-parameter superset ofEuclidean transforms° Also called similarities■ Properties:° Distances between points are changed by a fixed ratio° Angles are preserved° Maintains a “Similar” shape(similar triangles, circles mapto circles, etc.)1/22/0711Playing with Similitude transforms■ Adds reflections ■ Scales in x and y must be the same. Why? ■ Order? ■ Will this family of transforms always generate points on thechosen plane? Why?1/22/0712Affine transforms■ Affine Group° 6-parameters■ Properties : ° Preserve our selected plane (sometimes called the Affine plane) ° Preserve parallel lines° Rigid body transforms1/22/0713Affine transforms■ σxscales the x-dimension ■ σyscales the y-dimension ■ σxyis often called the skew parameterMapping parametersto matrix elements1/22/0714Determining affine transforms■ Affine transform uniquely determined by three corresponding points (non-colinear)1/22/0715Solution method■ We know coordinates before and after transform■ We want matrix entries■ 6 equations with 6 unknownsxXa1−=1/22/0716Projective transforms■ Projective group:° 8 parameters■ Properties:° Most general 2D transform we can represent with a matrix■ Causes points to not lie on the plane. We need to deal with1/22/0717Projective space■ Projective space:° the mapping of points from an N-D space to anM-D subspace (M < N)■ Mapping points (x,y,w) in P2back to plane in R2:° Intersect the line from (0,0,0) to (x,y,w) with the w=1° Divide by w. Gives (x/w,y/w,1)■ Origin cannot be uniquely identified° Disallowed.° This is why we selected a plane that did not contain the origin.1/22/0718Projective transforms■ Transformed points defined to within a non-zero scale factor. ■ Applying non-zero scale to transform gives the same result:■ We can choose α so that one of the parameters of our matrix is 1 (i.e. p33= 1).1/22/0719Determining projective transformsProjective transform:Can be expressed as a linear rational equation:Rearranging terms gives a linear expression in the coefficients:1/22/0720Determining projective transforms■ Uniquely defined by the mapping of four points1/22/0721Projective example1/22/0722OpenGL imaging■ glDrawPixels() – Writes an array of pixels to the framebuffer■ glReadPixels() – Reads an region of the framebuffer into an array of pixels in main memory■ glCopyPixels() – Copies a region from one part of the framebuffer to another■ glRasterPos*() – Sets the current drawing position for glDrawPixels() and destination position of glCopyPixels()1/22/0723OpenGL Setup■ Map world coordinates to screen coordinates° Typical when working with pixel level imaging° Use gluOrtho2DglViewport(0, 0, width, height);glClearColor(0, 0, 0, 1);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0, width, 0, height);glMatrixMode(GL_MODELVIEW);glLoadIdentity();1/22/0724Displaying an image■ Code to display a list of images:glClearColor(0, 0, 0, 1)glClear(GL_COLOR_BUFFER_BIT)for im in imageList:glRasterPos2i(im.x,im.y);glDrawPixels(im.width, im.height,GL_RGB, GL_UNSIGNED_BYTE,im.data)glFlush()1/22/0725Texture mapping■ Imaging functions word directly with pixels° Raster position modified by matrix stack but pixels are not.■ Textures “attach” an image to geometry° Specify texture coordinates at vertices° What kind of transform is applied to the image by this mapping(x4,y4)(u4,v4)(x3,y3)(u3,v3)(x1,y1)(u1,v1)(x2,y2)(u2,v2)1/22/0726How to set up a texture mapglBindTexture(GL_TEXTURE_2D, self.texID)glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)if (self.channels == 3):glTexImage2D(GL_TEXTURE_2D, 0, 3, self.width, self.height, 0, GL_RGB, GL_UNSIGNED_BYTE, self.data)else:glTexImage2D(GL_TEXTURE_2D, 0, 4, self.width, self.height,0, GL_RGBA, GL_UNSIGNED_BYTE, self.data)Associates an integer ID to the textureControls the interpolation used when texturingMakes the
View Full Document