Picture Manipulation (Affine transformations)

advertisement
Picture Manipulation
• The manipulation of (already
created) pictures.
• May be applied to vector
graphics or bitmaps.
• We will consider bitmaps and
introduce the DVE (digital
video effect).
• We will consider scaling,
translation and rotation.
Graphic Manipulation
• Manipulation achieved as a
series of transformations.
• These transformation achieved
by matrices.
• Called transformation matrices.
• Complex manipulation is
achieved by combination
(multiplication) of the basic
transformation matrices.
• We will see that the order of
multiplication is important.
Manipulating a picture
• In bitmaps we have to
manipulate each pixel in the
image.
• There are three basic operations:
– Translation (moving left/right,
up/down)
– Scaling (making smaller/larger)
– Rotation (turning through some
angle)
• Others can be made from
combinations of the above.
The equations of
manipulation
• Translation
• Scaling.
• Rotation.
Matrix multiplication
• Multiply each element of a row of
the first matrix by each element
of the corresponding column of
the second matrix.
• Add the products together.
• Put the result in position (row of
first matrix, column of second
matrix) of a new matrix.
• Repeat for all rows of the first
matrix.
• Means that the number of rows
of the first matrix must be the
same as the number of columns
of the second matrix.
• Easy for computers.
Matrix multiplication
• Example:
• Try it with Matlab.
A=[5 8 ; 7 2]
B=[6 1 ; 4 3]
A*B
Try B*A
Not the same.
The equations in a
matrix form.
• Scaling
• Rotation
• Translation
– Could add a translation matrix of a
similar form, but it would be simpler
if all matrices could be just
multiplied by the original coordinates.
The equations in a
“homogeneous” matrix
form.
• Translation
– Special 3x3 form allows
translation by multiplication.
• Scaling
• Rotation
The Matlab
DVE
• dve.m
• Need to make transformation
matrix first. Lets try scaling:
– Tr=[0.5 0 0; 0 0.5 0; 0 0 1]
• Also find or make two .bmp files
of the same size.
• Syntax
– dve
– You are prompted to enter the
names of the foreground and
background pictures, followed by
the transformation matrix.
• Try it.
Exercises in
translation, scaling
and rotation
• Now create your own
transformation matrices for the
following:
• Translation
– Move the foreground picture 200
pixels up and 50 pixels across
• Scaling
– Scale the foreground picture to a
tenth of its height and a third of its
width.
• Rotation
– Rotate the foreground picture by
45o clockwise. (You need to call 45o
pi/4 radians for Matlab)
Compound
Transformations
• By multiplying different types
of transformation matrix, we
can do two (or more)
transformations at once.
Effectively this transforms the
already transformed image.
Compound
Transformations
• For example:
Scaling followed by rotation.
Compound
Transformations
• For example:
Scaling followed by translation.
Order of
transformation
matrices
• Note that Scaling followed by
translation is not the same as
translation followed by
scaling, because we scale
the translation in the second
case.
• Rotation followed by scaling
distorts the transformation
matrix and results in “skew”.
Order of
transformation
matrices
• This is true of all compound
transformations, so the order is
important.
• Also, because the
transformation matrix is
multiplied by the object to be
transformed, rather than the
other way around, “later”
operations are on the left of any
expression. This may look like
the wrong way round.
Exercises in
compound
transformations.
• Produce a matrix which produces
a two times increase in height,
halves the width, and rotates the
original image.
• Repeat the above, but move the
image 40 pixels down and 100
pixels across also.
• Now reverse the order of the
transformations and observe the
effect.
• Try your own.
Scaling in PDF
• In PDF we change the
“current transformation
matrix” of the “graphics
state” using the cm operator.
• For scaling:
–
sx 0 0 sy 0 0 cm
Translation in PDF
• In PDF we change the
“current transformation
matrix” of the “graphics
state” using the cm operator.
• For translation:
–
1 0 0 1 tx ty cm
Rotation in PDF
• In PDF we change the
“current transformation
matrix” of the “graphics
state” using the cm operator.
• For rotation:
– cos(q) sin(q) -sin(q) cos(q) 0
0 cm
– Eg
• 0.707 0.707 –0.707 0.707 0 0 cm
rotates the current co-ordinates
by 45o
Further information
• Hill, Computer Graphics.
Prentice Hall.
• Adobe specifications
available from
www.adobe.com
– Postscript
– PDF
Download