In this video we will discuss Geometric Operations we will cover: Geometric Operations, Scaling, Translation, Rotation We will show the one channel representation, but unless specified we can apply these operations to each channel simultaneously We will treat the image as a function of y and x. y is the vertical direction, x is the horizontal direction. Although x and y are real numbers, we will sample integer points of x and y. for example point 0,0 or point 1,1 In a geometric transformation, we change the coordinates of the image x and y. The new image, g is a function of x prime and y- prime g of x prime and y prime has the value of f corresponding to the values that have been mapped from x and y. We will deal with a subset of Geometric Transformations called Affine transformations Scaling is where we reshape the image, we can shrink or expand the image in a horizontal and or vertical direction. Shrinking the image or making the image larger We can scale the image along the x axis. Let us use “a” to represent the scaling factor We can scale the image by 2. g of y and 2x is equal to f of f of y and x, hence the values of the image g will look stretched relative to image f Consider the following image, we will only work on the corner pixels points Consider the image at Point 0,0, the x coordinate is in red Applying the transform nothing happens, here is point 0, 5 Applying the transform the the x coordinates is mapped from 5 to 10 in red Applying the transform to point 5,0 nothing happens the point 5,5 is mapped to 5, 10 overlaying the image points we see the image appears stretched Let’s look at the relationship between the pixel f and g the first column of f is mapped to the first column of g ( The second column of f is mapped the third column of g the final column of f is mapped to the following column in g The colors shows the relation between columns of image f and g We see several column’s of g have no corresponding value in f, to determine the unknown pixel value we use Interpolation Interpolation is where we used neighbouring pixels to determine the value of an unknown pixel In this case, we use the nearest neighbours; this just assigns the value based on the nearest pixel; there are other methods that PIL and open cv use We can scale the horizontal axis; we will denote the vertical scale factor as d Lets set d to two, nothing changes when applying the transform to the top portion of the image For the point 5,0, the new value after the transform is applied is mapped to 10, 0 the point 5, 5 is mapped to 10,5. The result is the image is stretched in the horizontal direction We can use this method to make the image larger, if the values of a or d are less than zero; the image will shrink Translation is where we shift the image We can shift an image horizontally by adding the number of pixels “t x” then by mapping the new location x prime we can add two pixels, consider the following intensity values. We can apply the transform shifting the points, the points shift Transforming the next set of points, shifting the points the image appears shifted Let’s see what happens to each pixel We see that pixels have been shifted, those pixels that are on the edge have been replaced by zero values we can increase the size of the image to include the pixels that have been shifted We can shift the image vertically by adding pixels ty, this shifts the image vertically We can represent a geometric transformation as a set of equations, putting the equations in matrix form, we get the Affine Transformation matrix With open cv you input this matrix as an array. We also have the shear parameters; we will not cover them in this Course. You can also rotate an image We can rotate an image by an angle theta, where the red lines represent the original orientation of the horizontal and vertical access We can use a similar matrix to rotate an image. This Rotation matrix will perform a counter-clockwise rotation; the expression for the matrix is quite complex. We will simplify by assuming the Isotropic scale factor “r” is 1, and we will rotate from the center of the image to simplify If you make the above assumptions, libraries like PIL and open CV only require the parameter theta Lets try PIL In PIL we can scale the image by specifying the integer number of pixel’s using the method “resize" We can double the width of the image, we apply the method resize the image is twice as wide You can also shrink the image but the input must be an integer We can rotate the image. We use the method rotate; the input is the angle we would like to rotate the image by Lets try open CV In open cv we can use the function resize to rescale the image. We scale the horizontal axis by two and leave the vertical axis as is. We can also specify the interpolation the result is the image is twice as wide. The scaling factor does not have to be an integer, and it can be less than one Translation requires the Affine Transformation matrix M. Where tx is the number of pixels you shift the location in the horizontal direction, ty is the number of pixels you shift in the vertical direction. We will leave the scale factors as one We input the image and matrix into the function warpAffine, we also input the shape of the output image. The image is shifted, there is a lot more you can do using this method We can obtain the matrix to rotate the image using getRotationMatrix2D, this will rotate the image by angle θ The parameter center is the Center of the rotation in the source, scale will be set to one Like before we rotate the image. Check out the lab for more examples