Hello, welcome to the video lecture series on digital image processing. So, in today's lecture, as we said that we will discuss about some basic mathematical transformations which will include translation, rotation and scaling and this we will discuss both in 2 dimension as well as in 3 dimension. We will also discuss about the inverse transformations of these different mathematical transformations.
We will find out the relationship between between the Cartesian coordinate system and an homogeneous coordinate system and we will see that this homogeneous coordinate system is very very useful while discussing about the image formation by a camera. We will also talk about the perspective transformation and imaging process and then we will talk about the inverse perspective transformation. Now, coming to the basic mathematical transformations, let us first talk about that what is the translation operation and we will start our discussion with a point in 2 dimension. So, you know that if I have a 2 dimensional coordinate system given by the axis X and Y and if I have a point P which is having a coordinate given by say X Y and I want to translate this point P by a vector.
So, after translating this point, by the vector, I get the translated point say at point P prime whose coordinates are and. And because the translation vector in this case we have assumed as. So, you know that after translation, the new position will be given by X prime. plus x0 and y prime will be given by y plus y0. Now so, this is the basic relation when a point at location is translated by a vector.
Now, let us see that how this can be represented more formally by using a matrix equation. So, if I translate this equation in the form of a matrix, the equation looks like this. I have to find out the new location vector x prime y prime and we have said that this x prime is nothing but x plus x0 and y prime is nothing but y plus y0.
So, this particular relation if I represent in the form of a matrix, it will simply look like this. So, find that if you solve this particular matrix expression, it gives you this same expression x prime equal to x plus x0 and y prime is equal to y plus y0. So, on the right hand side you find that I have product of 2 matrices which is added to another column matrix or column vector.
Now if I want to combine all this operation in a single matrix form, then the operation will be something like this. On the left hand side, I will have X prime and Y prime which will be in the form of a matrix and on the right hand side, I will have 1 0 0, 1, Y0 and then I will have and. So, if I again do this same matrix computation, it will be x prime equal to x plus 0 plus x0, so which is nothing but x plus x0. Similarly, y prime will be 0 plus y plus y0 which is nothing but y plus y0. But you find that in this particular case, there is some asymmetry in this particular expression.
So, if I want to make this expression symmetric, then I can write it in this form x prime y prime and I introduce one more component which I make equal to 1. This is equal to 1 0 X0 0 1 Y0 then 0 0 1 and X Y1. So, find that this second expression which I have just obtained from the first one is now a symmetric expression and this is what is called an unified expression. So, find that basically what I have is I had the original coordinate of the point P which is appended with one more component that is given as 1 and if this modified coordinate is not transformed by a transformation matrix which is given as,, and then I get the translated point as x prime y prime 1 where if I just neglect the additional component which in this case is 1, then I get the translated point p prime. So, this is about the translation.
In the same manner, given a point P again in 2D, so again I have this point P which is again having a coordinate and suppose I want to rotate this point P around the origin by an angle theta. Now, one way of representing this point P is if r is the distance of point P from the origin, then these are the coordinates of the point P. This is the x coordinate, this is the y coordinate.
So, I can also represent and suppose this angle is alpha, then I can also represent X as X equal to r cosine alpha and Y equal to r sin alpha. Now, suppose I want to rotate this point P by an angle theta in the clockwise direction. So, the new position of P will now be P prime. having the coordinate location x prime and y prime and this rotation angle, angle of rotation is now angle theta.
So, our job is that what will be these points, the coordinate points x prime and y prime. So, here you find that I can write this x prime as R cos and I can write Y prime as R sin. So, if I simply expand this, so I have X prime is equal to R cosine alpha minus theta. So, and y prime is equal to r sin alpha minus theta.
So, if I simply expand this cosine term, it will simply be r cosine alpha cosine theta plus r sin alpha sin theta. Now, we know that r cosine alpha is nothing but x, so it becomes x cosine theta plus r sine alpha is nothing but y, so it becomes y sine theta. Similarly, in this case, if I expand this, it becomes r sine alpha.
cos theta minus r cos alpha sin theta. So again, r sin alpha, this is nothing but y. So, this takes the expression y cos theta minus x sin theta.
So, again here we find that X prime is given by X cosine theta plus Y sine theta and Y prime is given by minus X sine theta plus Y cosine theta. So, even now if I represent this in the form of a matrix equation, it becomes X prime Y prime is equal to cosine theta. theta, then minus sin theta, cosine theta and then I have the original coordinates x and y.
So, here you find that if I rotate the point P by an angle theta around the origin in the clockwise direction, in that case the transformation matrix which gives you the rotation transformation is given by this particular matrix which is cosine theta, sine theta, minus sine theta, cosine theta. Now, in the same manner, if I go for scaling, say for example if I have a scaling S, scaling factor of S in the X direction and I have scaling factor S in the Y direction, in that case the transformation matrix for scaling can also be represented as X prime Y prime is equal to S, and which is multiplied by the original coordinate. So, here you find that the transformation matrix for performing the scaling operation is nothing but the matrix and. So, these are the simple transformations that I can have in 2 dimension. Now, it is also possible to concatenate the transformations.
For example, if I have a matrix A, A is a constant, Here, I have considered rotation of a point around the origin. Now, if my application demands that I have to rotate the point P around an arbitrary point Q in the 2 dimension, then finding out the expression for this rotation of point P by an angle theta around another point Q is not an easy job. I mean that expression will be quite complicated. So, I can simplify this operation just by translating the point Q to the origin and the point P also has to be translated by the same vector and after performing this transformation, the translation, if I now rotate point P by the same angle theta and now it will be the rotation around the origin.
So, whatever expression that we have found here that is cosine theta, sine theta, minus sine theta, cosine theta. The same transformation matrix will be applicable and after getting this rotation, now you translate back the rotated point by the same vector but in the opposite direction. So here, the transformations that we are applying is first we are performing a translation of point P by the vector and after performing this translation, we are performing the rotation. So, this is your transformation say r theta. So, first we are translating by a vectors r, then we are performing a rotation by vector r theta and after doing this, whatever point I get that has to be translated back by minus r.
So, I will put it as translation by the vector minus r. So, this entire operation will give you the rotation of a point P. Suppose this is point P and I want to rotate this around the point Q.
So, if I want to rotate P around Q by an angle theta, then this operation can be performed by concatenation of this translation, rotation then followed by inverse translation which puts back the point. to its original point where it should have been after rotating around point Q by angle theta. So, these are the different transformations, the basic mathematical transformations that we can do in a 2 dimensional space.
Now, let us see that what will be the corresponding transformations if I move from 2 dimensional space to the 3 dimensional space. So, the transformations in the 3D coordinate system that we will consider is translation, rotation and scaling and the coordinate system that we will consider in this case is three dimensional coordinate system. So, first let us see as we have seen in case of two dimension that if a point is translated to a new coordinate say x star, y star, z star, Using a displacement vector, then this translated coordinates x star will be given by x plus x naught, y star will be given by y plus y naught and z star will be given by z plus z naught. So, you see that in our previous case, we have said that because we had only the coordinates x and y, so this third expression z star is equal to z plus z0 that was absent. But now, we are considering a 3 dimensional space, a 3D coordinate system.
So, we have 3 coordinates x, y and z and all these 3D coordinates, all these 3 coordinates are to be translated by the translation vector x0, y0, z0 and the new translation vector and the new point. we get as X star, Y star and Z star. Now, if I write these 3 equations in the form of a matrix, then the matrix equation will be like this.
X star, Y star, Z star on the left hand side will be equal to 1 0 0 X naught, 0 1 0 Y naught, 0 0 1 Z naught into the column vector. So, this is the matrix equation. x, y, z, 1. So, this is the similar situation that we have also seen in case of two dimension that we have to add an additional component which is equal to 1 in our original position vector x, y, z.
So, in this case again we have added the additional component which is equal to 1. So, our next position our new position vector becomes x, y, z, 1. which has to be multiplied with the translation matrix given by 1 0 0 X naught, 0 1 0 Y naught and 0 0 1 Z naught. So, again as before we can go for an unified expression where this translation matrix which at this moment is having a dimension 3 by 4 that is it is having 3 rows and 4 columns in unified representation. will represent this matrix, the dimension of the matrix will be 4 by 4 which will be a square matrix and the left hand side also will have the same unified coordinate that is x star y star z star 1. So, the unified representation as we have already said is given by x star y star z star 1 is equal to the translation matrix 1 0 0 x naught and 0 1 0 Y naught, 0 0 1 Z naught, 0 0 0 1 multiplied by the column vector X Y Z 1. So, this particular matrix that is 1 0 0 X naught, 0 1 0 Y naught, 0 0 1 Z naught and 0 0 0 1, this represents a transformation matrix.
used for the translation and we will represent this matrix by this upper case letter T. So, that is about the simple translation that we can have. So, in our unified matrix representation, we have done that if you have a vector V, a position vector V which is translated by the transformation matrix A, the transformation matrix A is a 4 by 4 transformation matrix. The V, if the original position vector was x, y, z, we have added an additional component 1 to it in our unified matrix representation. So, V now becomes a 4 dimensional vector having components x, y, z and 1. Similarly the transformed position vector V star is also a 4 dimensional vector which is having components x star, y star, z star and 1. So, this is how in the unified matrix representation, we can represent the translation of a position vector or a translation of a point in 3 dimension.
Similarly, we can have, so as I said that this is the transformation matrix which is represented, which is used for translating a point in 3D by vector or the displacement vector. Similarly, as we have seen in case of scaling in 2 dimension that if we have the scaling factor of S, S and S, the directions x, y and z. So, along direction x, we have the scaling factor S, along direction y, we have the scaling factor S and along the direction z, we have the scaling factor S.
Then the transformation matrix for this scaling operation can be written by S equal to S, then 0 S, 0 S, 0 S and then 0 S, 0 S and then 0 S and then 0 S and 0 0, then 0 0 S Z 0, then 0 0 0 1. So, here again if you find, you find that a position vector in unified form, it will be. If that position vector is translated by this scaling matrix, then what we get is the new position vector corresponding to point in the And there, if we remove the last component that is equal to 1, what we get is the scaled 3D coordinate of the point which has been scaled up or scaled down. So, it will be scaling up or scaling down depending upon whether the value of the scale factors are greater than 1 or they are less than 1. Then coming to rotation, we have seen that the translation and scaling In 3 dimension is very simple. It is as simple as we have done in case of 2 dimension. But, the rotation in 3 dimension is a bit complicated because in 3 dimension as we have 3 different axis, X axis, Y axis and Z axis.
So, when I rotate a point around origin by certain angle, the rotation can be around X axis, the rotation can be around Y axis. the rotation can also be around z axis. So, accordingly I can have 3 different rotation matrices for representing rotation around a particular axis and specifically if the rotation has to be done about an arbitrary point, then what we have to do is we have to translate the arbitrary point to the origins by using the translation transformation.
After translating the points to the origin, Then, we have to perform rotation around the origin, then we have to translate back the point to its original position. So, which gives us the desired rotation of any point p in 3D around any other arbitrary point q also in 3D. So, now let us see that how this rotation will look like in 3D. So, here you find that we have shown on the right hand side.
this particular figure where this figure shows the rotation of the point along X axis. So, if the point is rotated along X axis, the rotation is given by is indicated by alpha. If it is rotated along Z axis, the rotation is indicated by theta and if the rotated, rotation is done along y axis, the rotation angle is indicated by beta. So, if I rotate the point along z axis, so when I am rotating a point along z axis, then obviously the z coordinate of the point will remain unchanged even in the rotated position.
But what will change is the x coordinate and y coordinate of the point in its new rotated position. And, because the z coordinate is remaining unchanged, so we can think that this is a rotation on a plane which is parallel to the xy plane. So, the same transformation which we have done for rotating a point in 2 dimension in the xy coordinate, the same transformation matrix holds true for rotating this point in 3 dimension along the axis z.
But now, because the number of components in our position vector is more. So, we have to take care of the other components as well. So, using this you find that when I rotate the point around z axis. The rotation angle is given by theta and the rotation matrix is given by cosine theta sin theta 0 0 minus sin theta cosine theta 0 0 then 0 0 1 0 and 0 0 0 1. So, this is the transformation matrix or rotation matrix for rotating a point around z axis.
So, here you find that the first few components that is cosine theta, sine theta then minus sine theta and cosine theta. So, this 2 by 2 matrix is identical with the transformation matrix or rotation matrix that we have obtained in case of 2 dimension. So, this says that because the z coordinate is remaining the same, so the x coordinate and y coordinate due to this rotation around z axis.
follows the same relation that we have derived in case of two dimension. Similarly when I translate the point around Y axis, rotate the point around Y axis, the angle of rotation is given by beta. So, R beta as given in this particular case gives you the rotation matrix.
And, if you rotate the angle around X axis where the rotation angle is given by alpha, you find that R alpha gives you the corresponding transformation matrix for rotation along the X axis. So, as before here you find that when you rotate the point along around X axis, the X coordinate will remain the same whereas the Y coordinate and the Z coordinate of the point is going to be the same. Similarly, when you rotate the point around y axis, the y coordinate is going to remain the same but x coordinate and z coordinate, they are going to be different. Now, as we have also mentioned in case of 2 dimension that different transformations can be concatenated.
So, here we have shown that how we can concatenate The different transformations, here you find that all the transformations that we have considered in 3 dimension, all of them are in the unified form. That is every transformation matrix is a 4 by 4 matrix and all the coordinates that we consider, we add 1 to the coordinate xyz so that our position vector becomes a 4 dimensional vector and the translated point vector is also a 4 dimensional vector. So, if I want to concatenate these different transformations that is translation, scaling and rotation and if I want to rotate a point about z axis, then this translation, scaling and rotation, this can be concatenated as first you translate the point V by the translation operation T or the translation matrix T.
Then, you perform scaling, then you perform rotation and this rotation is R theta and all these 3 different transformation matrices that is R theta, S and T, all of them being 4 dimensional matrices can be combined into a single matrix. So, this single transformation matrix in this case A which is nothing but the product of R theta, S and T and this A again will be a matrix of dimension 4 by 4. Now, you note that whenever we are going for concatenation of the transformations, the order in which these transformations are to be applied that is very very important because these matrix operations are in general not commutative. Now just to illustrate that these matrix operations are not commutative, we can see that the order Let us take this example.
Suppose I have this particular point V and to this point V, I want to perform two kind of operation. One is translation by vector. So, the translation vector we have represented by this arrow by which this point has to be translated and the point V is also to be rotated by certain angle.
Now, there are two ways in which these two operations can be done. The first one shows that suppose I rotate point V first by using the operation R V. So here, the transformation matrix is A R for the rotation operation and after rotating this point V by using this transformation R, I translate the rotated point by using the transformation matrix T. So, if I do that, you find that this V is the original position of this point.
If I first rotate it by using this rotation transformation, the point V comes here in the rotated position and after this, if I give translation to this point V by this translation vector, then the translated point 1 is coming over here which is represented by V2. So, the point V2 is obtained from V first by applying the rotation by transformation R followed by applying the translation by the transformation T. Now, if I do it reverse that is first I translate the point V using this translation T, then transformation T and after this translation, I rotate this translated point which is now Tv by the same angle theta.
So, what I do is first I translate the point using the transformation T and after that this translated point is rotated by using the rotation transformation R. and this gives me the rotated point or the new point that is equal to V1. Now, from here you find that in the earlier case where I got the point V2 and now I get the point V1, this V1 and V2 they are not the same point.
So, this clearly illustrates that whenever we go for concatenation of different transformations. So, we have to be very very careful about the order in which these transformations are to be specified or the transformations are to be applied because if the order in which the transformations are applied vary, then we are not going to get the same end result. So, for any such concatenation, the order in which the concatenation is applied, the that has to be thought of very very carefully. So, that is about translation of the transformation of a single point. Now, if I have to transform a set of points, say for example, I can have a square figure which says like this.
Say for example, in a 2 dimensional space x, y, I have a square figure like this. So, these will have 4 vertices. The vertices I can represent as point p1, point p2, point p3 and point p4.
Now, so far the transformations that we have discussed that is the transformation of a single point around origin or the transformation of a single point around another arbitrary point in the same space. Now, here if I have to transform this entire figure that is for example, I want to rotate this entire figure about the origin or I want to translate this entire figure by certain vector say V. So, say for example, I want to translate this entire figure to this particular position. So, you find that here all these points p1, p2, p3 and p4, all these points are going to be translated by the same displacement vector V. So, it is also possible that we can apply transformation to all the points simultaneously rather than applying transformation to individual points one by one. So, for a set of M points, what you have to do is we have to construct a matrix V of dimension 4 by M.
That is every individual point will now be considered of course in the unified form. We will now be considered as a column vector. of this matrix which is of dimension 4 by m and then we have to apply the transformation A to this entire matrix and the transformation after this transformation, we get the new matrix say V star which is given by the transformation A multiplied by the matrix V. So, here you find that any particular columns, the ith column in the matrix V star which is the V star.
is the transformed point corresponding to the ith column of matrix V which is represented by Vi. So, if I have a set of points which are to be transformed by the same transformation, then all those points can be arranged in the form of columns of a new matrix. So, if I have m number of points, I will have a matrix having m number of columns.
The matrix will also obviously have four rows. So, I will have a matrix which is a new matrix And, this new 4 by M matrix that I get, this entire matrix has to be transformed using the same transformation operation and I get the transformed points again in the form of a matrix. And from that transformed matrix, I can identify that which point which is the transformed point of the original point. Now, once we get these transformations, again we can get the corresponding inverse transformations.
So, the inverse transformations in most of the cases can be obtained just by observation. Say for example, if I translate a point by a displacement vector V, then inverse transformation should bring back that translated point, that transformed point to its original position. So, if my translation is by a vector V, the inverse transformation or the inverse translation should be by a vector minus V. So, the inverse transformation matrix T inverse can be obtained as 1 0 0 minus X0, 0 1 0 minus Y0, 0 0 1 minus Z0, then 0 0 0 1. So, you remember that the corresponding transformation matrix that we said was 1 0 0 X0, 0 1 0 Y0, 0 0 1 Z0 and 0 0 0 1. So, you find that X0, Y0 and Z0, they have just been negated to give you the inverse translation matrix T inverse.
So, similarly by the same observation, we can get inverse rotations R theta inverse where what we have to do is. In the transformation matrix, original rotation matrix, we had the term cosine theta, sine theta, minus sine theta, cosine theta. Now, all these thetas are to be replaced by minus theta which gives me the inverse rotation matrix around the z axis. Similarly, we can also find out the inverse matrix for scaling where the S will be replaced by 1 upon x, x. Thank you.