Learning with data – learning about and from data



Station 1 – Rotating imagesBy hand.Draw the vector (2, 1) on the Cartesian plane. Now draw the vector that is obtained by rotating (2, 1) 90 degrees anti-clockwise about (0,0). What are the coordinates of this vector?58026301765935Multiplication steps for A x B = C1. Determine the order of C.2. The (I,j)th element of C combines the ith row of A and the jth column of B.Look at the Multiplication Hints sheet for more details.00Multiplication steps for A x B = C1. Determine the order of C.2. The (I,j)th element of C combines the ith row of A and the jth column of B.Look at the Multiplication Hints sheet for more details.Vectors are often represented by column matrices. So the vector (2, 1) is represented as 21. Perform the multiplication0-110× 21=572643066040In the expression A x B, A comes first so it is said to “pre-multiply” B.A rotation matrix always comes before (pre-multiplies) the vector.00In the expression A x B, A comes first so it is said to “pre-multiply” B.A rotation matrix always comes before (pre-multiplies) the vector.What do your results from a) and b) imply about the graphical effect of pre-multiplying a vector by 0-110?What matrix can be used to rotate 21 by 180 degrees? Hint: Rotation by 180 degrees is the same as rotating by 90 degrees and then then rotating by 90 degrees again!2. Go to ncase.me/matrix. Test your answer to 1d) by entering the values in the four top-left cells of the matrix.Try out some other values for four the top-left cells in the matrix. How can you keep the M the same shape, but make it bigger or smaller?If time, look at the first two sentences of the Wikipedia page “Rotation Matrix”. What matrix would you use to rotate the M by 70 degrees anti-clockwise? Try it out and see if it works!Station 2 – Transposing and flipping914400502920A=020000A=Consider the image below. Create a 6×6 matrix (called A) of 0s and 1s that corresponds to this image – 1s represent black and 0s represent white.5764530100964To get AT from A, the first column of AT (top to bottom) is the first row of A (left to right); the second column of AT is the second row of A, etc.00To get AT from A, the first column of AT (top to bottom) is the first row of A (left to right); the second column of AT is the second row of A, etc.733425461010AT=020000AT=Try to imagine what the corresponding image would look like if you transposed this matrix. Then write down the matrix transpose and sketch the image.514351476885(AT)T =020000(AT)T =Now try to imagine what happens if you transpose the matrix from part b). Then write down the matrix and sketch the image.566928046355A matrix equation is an equation that uses upper-case letters to represent matrices, e.g. A+B = C00A matrix equation is an equation that uses upper-case letters to represent matrices, e.g. A+B = CWhat do your results from c) tell you about the transpose of a transpose? Express your answer as a matrix equation.1123950800735rowFlipA=020000rowFlipA=Consider an operation called rowFlip that “flips” each row of a matrix. So using the matrix from 1, the image of the “flipped” matrix would look like27145012787650Here is an image called boy:Match each of the following images with the sequence of operations that produced it, assuming that the boy image above is used to start. 123825245110 B. C.D. E. B. C.D. E.5926455292735Complete the table00Complete the tableSequence of operationsLabel of image that is producedrowFlipTransposerowFlip then transposeTranspose then rowfliprowFlip then transpose then rowFlipCheck your results in R using the functions rowFlip() to flip the rows, and transpose() to transpose the matrix.5831205181610This example corresponds to rowFlip then transpose00This example corresponds to rowFlip then transposeExample:> plot(boy)> boy.matrix <- img2matrix(boy)> boy.flip.tr <- transpose(rowFlip(boy.matrix))> plot(matrix2img(boy.flip.tr))Station 3 – Grey-scale images5850255762000 = black255 = white1 to 254 represent shades of grey.000 = black255 = white1 to 254 represent shades of grey.The following is a grey scale image and its matrix representation:657225273685A=00217217025521702552552552552551282170128255255255020000A=0021721702552170255255255255255128217012825525525556026051190625To add a matrix and a scalar, e.g. A + 10, add 10 to every element of A.00To add a matrix and a scalar, e.g. A + 10, add 10 to every element of A. “Reversing” a grey scale image means making the blacks white and the whites black (and the dark greys light grey, etc). The table below lists the reversed values for a few of the original pixel values. Pixel values in original imagePixel values in reversed image025512542253……2550Write down a matrix expression or equation that can be used to “reverse” any matrix A.565023057785To multiply a matrix by a scalar, e.g. 3A, multiply each element of A by 3. 00To multiply a matrix by a scalar, e.g. 3A, multiply each element of A by 3. 2.5602605226695Replace the !!! on line 3 with the expression you found in 1.00Replace the !!! on line 3 with the expression you found in 1.a) Try out your solution on the grey-scale boat image in R:> grey.boats <- grayscale(boats)> boats.matrix <- img2matrix(grey.boats)> boats.matrix.rev <- !!!> plot(matrix2img(boats.matrix.rev)) b) Challenge question. The contrast of an image in increased when the blacks become more black (closer to 0) and the whites become more white (closer to 255). Can you think of a way to adjust the contrast using matrix operations? Station 4 – Colour imagesColour images are created by overlapping a red image, a green image, and a blue image. Similar to grey scale, each of the R/G/B images is based on a matrix where the values represent the pixel intensity. Consider the following example. = R=011121025125225219990118, G=017402195535315647, B=070151001566204151Does 0 correspond to low (black) or high intensity?5926455334010If k is a scalar and A is a matrix, calculate kA by multiplying each element of A by k. 00If k is a scalar and A is a matrix, calculate kA by multiplying each element of A by k. Calculate the matrix corresponding to the grey-scale image if red, green, and blue contribute equally. That is calculate,Grey=13R+13G+13B5926455311785Add matrices together by adding the corresponding elements. 00Add matrices together by adding the corresponding elements. Make a grey-scale image of the boats picture.Plot the red, green, and blue components of the boats image using the functions plot.red(), plot.green() and plot.blue(), e.g.> plot.red(boats)Follow the instructions in the video to make a grey-scale version of the boats image.c) Compare this to the results of the in-built R function grayscale(): > plot(grayscale(boats))Can you find the ratio used by the authors of grayscale() to combine R, G, and B?Station 5 – Too much information!Below is an example of a singular value decomposition of an image matrix A. A=16495612919124489128107 =USVT, whereU=-0.20.21.0-0.90.4-0.3-0.5-0.90.1 S=3710003600013 V=-0.4-0.5-0.8-0.6-0.50.6-0.70.7-0.15793105116205To calculate USVT:1. Write down VT2. Calculate US3. Calculate (US)VT00To calculate USVT:1. Write down VT2. Calculate US3. Calculate (US)VTa) Verify (using matrix multiplication) that A=USVT, where VT represents the transpose of V. You may use the matrix calculator to help, but write down each step of your working.5840730253365Remember, US = U x S00Remember, US = U x S5793105158115Look in the Multiplication Hints resource for a link to a matrix calculator.00Look in the Multiplication Hints resource for a link to a matrix calculator.The slides showed an example of how to calculate the 2nd singular value decomposition, i.e. using the first two columns of U and V. 5840730247650First write down U1, S1, V1, and V1T. Then calculate U1S1, and finally (U1S1)V1T. 00First write down U1, S1, V1, and V1T. Then calculate U1S1, and finally (U1S1)V1T. Now it’s your turn: Calculate the 1st singular value decomposition of A, using the first column of U, the first column of V, and the first value of S from the matrices above. 5840730185420Look at the Add & Multiply Matrices resource for an example of how to multiply matrices with any orders. 00Look at the Add & Multiply Matrices resource for an example of how to multiply matrices with any orders. In R, use the function svd.image(image, k) to plot the image that uses the first k singular values. The function also displays the image size and quality. For example,> svd.image(boats, 100)Compare different values for k. What do you notice about the relationship between k and the image quality? ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download