2H

Part 2H: Exploring Images 1

In this long, 7:13 video, Chris introduces the idea of a matrix, how to construct one using code, how to retrieve values from specific positions in the matrix, and how to output or say these values.
**You may skip the video and just follow the instructions below, or you may watch the video after trying the commands to review what you have done – whatever method works best for you!

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

We will use Quorum commands to define a small 5 x 5 matrix. Then we will retrieve and manage pixel values. This simple matrix will be our model of the output of a CCD camera. A PDF of a text file of the commands of this Part, Part H, is available at this link:

Quorum Commands Section 2 Part H – PDF

The following link is to a QUORUM BOX for Matrices:

Quorum Box for Matrices

– The commands are highlighted with an orange background. Most of the commands you can copy and paste, but, be aware, some copying changes the symbols in the Quorum Box and you will not get a ‘successful build’. Use the link to the text file above if that is your preferred method
– Recall, if you do not need the screen reader, unclick the button on the top left of the Quorum Box. This will give you line numbers and a different color for the commands.
*******************************************************

1. MAKE A MATRIX USING QUORUM

a) First, we must call the correct library of commands from the Quorum server:

use Libraries.Compute.Matrix

b) Start by typing the word Matrix, followed by a variable name – I simply used m1:

Matrix m1

The Matrix command is just like the “text” or “number” commands you’ve used before, but it makes a more complex type of object – a matrix. The capital letter in the Matrix command is necessary.

c) Now we can “fill” the matrix with values.

First we tell Quorum to talk to m1 by typing “m1:” (the variable name followed by a colon). Then we tell m1 what we want it to do by using the command “Fill()”(the quotes are not necessary):

m1:Fill(5,5,1.0)

Inside the parentheses, the first number is the number of rows, the second number is the number of columns. The third number is what is filled in at every position.

Quorum produces a “zero-based” matrix, which means the first row is zero, not one, and the first column is zero, not one. The command above gives a matrix with row numbers 0,1,2,3,4 and column numbers 0,1,2,3,4.

If you would like, make a 5×5 tactile matrix with the egg crate and stones to follow along with the rest of the commands.

d) Let’s send the matrix to the console output window with both a ‘say’ command and an ‘output’ command:

say m1:ToText()
output m1:ToText()

The say command speaks each row with a slight pause in between. Remember to turn up the volume if you use this command.

The ToText() command in both lines takes the matrix m1 and converts it to “text” type data so we can use the output or say command. Anytime you want to see the result of a command which produces a MATRIX, the “ToText()” command must be used. Quorum requires an open parenthesis and a close parenthesis, (), after the ‘ToText’ command. This is Quorum’s way of knowing to run this function with nothing needed in the parentheses.

2. MAKE A SECOND MATRIX

Call this m2. Give it any number of rows, but then a different number of columns. This will produce a matrix which is not square.
You may use the following example, or your own.

Matrix m2
m2:Fill(5,3,2.0)

What do you expect this to look like? Is it taller than it is wide? or wider than it is tall?
Run the program to check your prediction – see if you can remember the steps to do this.

Try making other matrices. You can make them any size or shape, with any value for now. Use different variable names then we have already used.

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

3. EXTRACTING INFORMATION FROM A MATRIX

Now that we have modeled image data as a simple matrix, we can relate it to some of the functions of the display settings.

For example, the histogram. How do you think a matrix relates to the histogram? Record your thoughts in Your journal. (Your teacher will be able to help with this).

Now let’s extract information.

a) The “Get” command will retrieve the value at a certain position in the matrix:

m1:Get(1,1)

Start the command with the matrix you are interested in followed by a colon :. Then type the command, “Get()”. Finally specify the (row, column) of the pixel you’re interested in within the parentheses.

JOURNAL QUESTIONS:

1. What would be the use of knowing the individual pixel values in an image?
2. What do those values represent?

b.) There are two ways to have the result of your command appear in the output box.

i. The Get() command produces a number, which is one of the primitive data types. Therefore, if you type output (or say) before the command, it will appear in the output box.

output m1:Get(1,1)
say m1:Get(1,1)

ii. You could also assign a number variable to the command, and then output or say the variable:

number x = m1:Get(1,1)
output x
say x

Question: Previously, you used a ToText() command. Why can you not use that here? Record some ideas in your journal, then try and see what response you get if you use the ToText() command.

Note: These commands use some capital letters – a preference of the software engineer.