Matlab Exercise 4: Transform the Clown (1.8-1.9)
MATH 3304, Fall 2018, Dr. Hedrick Due Oct. 1, 4:00 PM
In this exercise, we will perform a few linear transformations on the image of a clown. To begin, download the scripts transform the clown.m and color the clown.m and the file clown2.mat. The only file you will edit is transform the clown.m. Make sure all 3 files are in the same folder, and then run the script transform the clown.m. After several seconds, you should see the image below appear.
This image was created by plotting a dot at each pixel and specifying the (x,y)-coordinates and color of each dot. (If you think the image would look better on your computer with larger/smaller dots, change the markersize of each dot, which is specified in transform the clown.m under the variable name ms.)
To transform this image, we’ll change the coordinates of each pixel but not the color. For example, to stretch the image horizontally by a factor of 2, the red dot originally plotted at (20,35) should now be plotted at (40,35).
The file clown2.mat contains Matlab data, which is loaded to your workspace in transform the clown.m by the command load clown2.mat. Type open clown2.mat in the Command Window to see the variables contained in this file. Here’s a description of each:
- C: Each column of C is the (x,y)-coordinates of a pixel. CAREFUL: C is 2×16000. Make sure to write a semicolon after any line containing C so you don’t print 32000 numbers to the Command Window. You’ll have trouble publishing if you leave off semi-colons.
- col: Each element i of col is the index used to determine the color of pixel i, or the color of the dotplottedatx=C(1,i), y=C(2,i).
- map: Each row of map stores a color. The three numbers indicate the amount of red, green, and blue in the color.
To color pixel i of the clown, we’ll plot a dot at x = C(1, i), y = C(2, i) using the color given by map(col(i), :). This is coded for you already in the script color the clown.m, which you should not edit. Changing the coordinates of each pixel means changing each column of the coordinate matrix, C.
Tasks
Note: To save time, you might comment out (write a % at the beginning of the line) all prior calls to color the clown so that Matlab is only generating one figure when you run transform the clown. When you’re ready to publish, you can go back and uncomment (remove the %) these lines.
1. a.
b.
2. a.
b. 3. a.
(3 pts) Construct the standard matrix A that stretches the clown horizontally by a factor of 2 without changing its height. Hint: For each set of coordinates c (column of C),
c1 2c1 Ac=c.
22
(1 pt) To transform the entire clown, we need to change the coordinates of all pixels by multiplying A by each of the 16,000 columns of C. This can be done efficiently by computing the matrix-matrix product, AC. Compute this product and save it to the variable name C1. Then, plot the stretched clown by executing color the clown(C1,map,col,ms).
(3 pts) Construct the standard matrix that rotates the original clown CCW by 45◦. CAREFUL – Matlab uses radians.
(1 pt) Compute the new set of coordinates and plot the rotated clown, as in 1(b).
(3 pts) Construct the matrix that transforms the original clown to the clown shown below:
160 160 1 Hint: Use the fact that T 0 = 200 and the linearity of T to determine T 0 .
b.
Publish your script and print out the final pdf.
(1 pt) Compute the new set of coordinates and plot the transformed clown, as in 1(b).