L) Manipulation of Matrices 1

Chris introduces Manipulation of Matrices in this 2:00 video:

****************************************************************

There are many ways you can manipulate a matrix: Flip, Rotate, Reshape, Shift, or Transpose. If you perform these operations on a matrix, you can perform them on an image. Why would an astronomer want to do this with an image? Did you see any tools that might do this? Record a few thoughts in the JOURNAL BOX below.

You may remember these manipulations from geometry class, or if you haven’t had geometry class yet, these activities will give you an idea about what you can look forward to!

1. ACTIVITY: IMAGE ORIENTATION (Hands-on)

Teachers: a resource with instructions is available here

a) Materials: Two letter L’s glued or taped, back-to-back, to a small board or piece of cardboard. Foam grid.

b) As you follow the instructions, make sure to record in the JOURNAL BOX below what happened in each motion.

c) Try the same activity with a tactile image of any kind.

Now let’s learn how to do these manipulations on matrices.

There are several commands that manipulate both the orientation and values in the matrix. These should help us understand the ability of the software program, Afterglow Access, to manipulate the data received from the CCD camera. For example, the manipulation by addition, subtraction, etc., of the brightness values of the pixels allows one to see dim objects, bright objects, dust, etc. The manipulation of the orientation and position lets you line up multiple images, which we will do later.

2. ACTIVITY: MATRIX MANIPULATION (using Quorum commands)

A PDF of a text file of the commands of this Part, PART L, is available at this link:

It may be helpful to have the following list of all the Quorum MATRIX commands we have used:

A) ADD single value

What if you have several images of the same spot in the sky? What would be the value of adding them together? How about subtracting? Record some thoughts in the Journal below.

1. In a Quorum matrix, which is our model of the images on the computer, you can add, subtract, multiply, or divide using a single value that will affect all the elements of the matrix equally. Let’s try these.

a) Open a new Quorum box (recall: Whenever you open a Quorum Box for Matrices using the link, you will see the code you have already done – it will not be blank. You may reset it, or keep what you need and delete the rest). You can switch between tabs or arrange side by side.

b) Call the library and define three new matrices, two of which will be the same size. You will be using all three matrices later.

use Libraries.Compute.Matrix

Matrix m1

Matrix m2

Matrix m3

c) Make the first two matrices the same size but not the same values. Use the Fill() and Set() commands (not shown here) on matrices m1 and m2. Make the third matrix a different size, and then fill that.

d) Finally, use the SetRow(), or SetColumn() commands to change a chosen row or column to different values in each of your matrices. You need different values to see the manipulation that takes place.

e) It might be helpful to output (and say, if desired) the three matrices, with spaces between them, so you can compare them to the changes you make.

f) Now you are ready. We will start by changing the values in the first matrix, m1:

output m1:Add(7.0):ToText()

This adds 7 to each element in the matrix and then prints it in the output console window. Change 7.0 to any number you would like and then try it. See if you can predict what the matrices will look like before sending them to the console output window.

*********************************************************

Chris helps us to understand multiplication of matrices in this 1:20 video:

*********************************************************

B) SUBTRACT, MULTIPLY, DIVIDE by a single value

Let’s try these commands for changing all the pixels by the same value. Just type these at the end of the commands you already have in the Quorum Box you have been using. Notice there is a line that says output “space”. This puts a line inbetween each matrix that is produced for the purpose of easier reading on the console output window. Or, you could put ” ” with nothing in the quotes. Again, be careful of copying and pasting!

output “space”

output m1:Subtract(2.0):ToText()

output “space”

output m1:Multiply(5.0):ToText()

output “space”

output m1:Divide(3.0):ToText()

a) Did these give you the results you were expecting? Make a note in the JOURNAL BOX below.

b) If you want to SAVE any matrix manipulation, you must define a new matrix. The next set of commands show this:

Matrix m1a

m1a = m1:Multiply(5.0)

c.) If you would like to see this new matrix, you must say or output it “ToText()”. Try it.

d) Try any of the above commands on any one of your matrices. Save at least one of your new matrices.

******************************************************

Chris introduces the idea of combining matrices in this 2:26 video:

C) COMBINING TWO MATRICES

Besides changing the value of each pixel in a matrix, we can add, subtract, multiply, and divide all the elements in one matrix by all the elements in another matrix. What happens if the two matrices are not the same size? Come to a prediction and record in the JOURNAL BOX below. You will test your prediction at the end of this part.

– Again, start with two matrices that have the same size (dimensions), but not the same values, for example, m1 and m2.

– You can keep going in the same Quorum Box you have open. Add spaces between the outputs.

– Save any resultant matrix of your choosing to a newly defined matrix as done above.

** (add text file)

output m1:AddElements(m2):ToText()

output m1:SubtractElements(m2):ToText()

output m1:MultiplyElements(m2):ToText()

output m1:DivideElements(m2):ToText()

Now that you have used the commands, test them again with two matrices of different sizes to see if your prediction was correct. Comment in the JOURNAL BOX below.

********************************************************

JOURNAL BOX

Previous Page ** Next Page