Image Processing with Matrices and Python
Image Processing with Matrices and Python
Authors:
Tamar Avineri, North Carolina School of Science and Mathematics, Durham
NC
Emily Berkeley, Panther Creek High School, Cary, NC
Ashley Miller, North Rowan High School, Spencer, NC
Abstract: In this all-inclusive module students will learn how to use matrices and
vectors to manipulate and edit images. The students will be provided with their
own image editing activity where they will create their own classroom “Instagram
feed.” There is also an extension activity that incorporates some basic Python
programming into this module.
2
The authors would like to acknowledge the support of the National Science
Foundation through the grant DMS-1845406
Implementation Notes 3
Lesson 1: Introduction to Matrices and Matrix Operations 5
Lesson Plan 5
Guided Notes – Teacher Version 9
Lesson 2: Matrix Multiplication 14
Lesson Plan 14
Guided Notes – Teacher Version 16
Lesson 3: Introduction to Image Processing 22
Lesson Plan 22
Guided Notes – Teacher Version 25
Lesson 4: (Extension) Image Processing using Computer Science 42
Lesson Plan 42
Lesson 5: Instagram Project 44
Lesson Plan 44
Warm-Up – Teacher Version 46
Instagram Project 49
References and Additional Readings 51
Appendices 52
Appendix A: Lesson Materials – Student Versions 52
Lesson 1: Guided Notes – Student Version 52
Lesson 2: Guided Notes – Student Version 58
Lesson 3: Guided Notes – Student Version 66
Lesson 5: Warm-Up – Student Version 11
Appendix B: Lesson Materials – Templates/Examples 14
Lesson 4: Math Symbols Image 14
Lesson 5: Instagram Project Stock Images 15
Lesson 5: Instagram Project Example 17
3
Implementation Notes
Length of module:
In total, this unit is designed to take approximately 3.5 days of
90-minute lessons, or 7 days of 45-minute lessons, including the
final project. There is also an extension project that is designed
to take approximately 85 minutes.
Each of the lessons is accompanied by an estimate of the length
of time it is designed to take in class. If the estimate is longer
than you can devote in class, feel free to select portions for
students to complete outside of class.
There is an extension project that includes coding in Python.
This is a lesson that is intended for Discrete Math for Computer
Science but would be a great tool if you have the extra time to
implement the lesson in the Math 4 or Pre-Calculus class.
Assessments:
Feel free to select portions of the guided notes to serve as out-
of-class activities.
Any problem set contained within guided notes could be given
as homework assignments.
As an alternative to the final project in this module, you could
choose to give students a standard test or quiz on the skills that
have been learned.
For the project, you can have the students create the matrices
using Microsoft word (or if they have access to a tablet and a
note taking app, they can create the matrices on there), they
can use this website to create the pictures, and then they can
screen snip the pictures out and paste them into the final
document. They can then submit the project fully through an
online submission.
Student Versions: Please note that the student versions are located
at the end of this document in Appendix A.
Lesson Plan
6
(~60 minutes)
How will you know if practice. Students turn in their circulate room and
students understand solutions to the last problem in monitor progress,
throughout the lesson? the problem set as an exit ticket engaging students who
(e.g., Stereo Problem) may be having
difficulty in discussion
to probe their
thinking.
A university is taking inventory of the books they carry at their two biggest
bookstores.
The East Campus bookstore carries the following books:
Hardcover: Textbooks-5280; Fiction-1680; NonFiction-2320; Reference-
1890
Paperback: Textbooks-1930; Fiction-2705; NonFiction-1560; Reference-
2130
In order to work with this information, we can represent the inventory of each
bookstore using an organized array of numbers known as a matrix.
The entry in the “mth” row and “nth” column is written as a mn.
If a matrix has only one row, then it is a row vector. If it has only one
The transpose of a matrix, A, written AT, switches the rows with the
Two matrices are equal if they have the same size and the same
corresponding entries.
12
T
FN R
W=
[
Hardback 7230 2450 3100 1380
Paperback 1740 2420 1750 1170 ]
Adding and Subtracting Matrices
In order to add or subtract matrices, they must first be of the same size.
The result of the addition or subtraction is a matrix of the same size as the
matrices themselves, and the entries are obtained by adding or subtracting
the elements in corresponding positions.
In our campus bookstores example, we can find the total inventory between
the two bookstores as follows:
E+W =
[5280
1930
+
][
1680 2320 1890 7230 2450 3100 1380
2705 1560 2130 1740 2420 1750 1170 ]
T FN R
= [
Hardback 12510 4130 5420 3270
Paperback 3670 5125 3310 3300 ]
13
Scalar Multiplication
type that he would need by simply multiplying the matrix E by the scalar (or
constant) 2. The result is as follows:
T FN R T FN R
2 E=2∗
[5280
1930
1680 2320 1890
2705 1560 2130
=] [
2(5280) 2(1680) 2(2320) 2(1890)
2(1930) 2(2705) 2(1560) 2(2130) ]
T FN R
= [
Hardback 10560 3360 4640 3780
Paperback 3860 5410 3120 4260 ]
15
[ ] [ ] []
1 0 1 0 6 −21 5
A= 2 −4 3 B=[ 2 8 −6 ] C= 2 4 −9 D= −2
−6 1 8 5 −7 1 3
[ ][ ][ ]
1 0 1 0 6 −21 1 −6 22
c. A−C= 2 −4 3 − 2 4 −9 = 0 −8 12
−6 1 8 5 −7 1 −11 8 7
[ ][ ][ ]
0 6 −21 1 0 1 −1 6 −22
d. C− A= 2 4 −9 − 2 −4 3 = 0 8 −12
5 −7 1 −6 1 8 11 −8 −7
e. 5 B=5∗[ 2 8 −6 ]= [ 10 40 −30 ]
[ ] [ ]
1 0 1 0 6 −21
f. – A +4 C=− 2 −4 3 +4∗ 2 4 −9 =¿
−6 1 8 5 −7 1
[ ][ ][ ]
−1 0 −1 0 24 −84 −1 24 −85
−2 4 −3 + 8 16 −36 = 6 20 −39
6 −1 −8 20 −28 4 26 −29 −4
16
g. B – D : This operation cannot be performed, since B and D are not of the same
size.
[ ] [ ]
0 6 −21 1 0 1
h. 2 C−6 A=2∗ 2 4 −9 −6∗ 2 −4 3 =¿
5 −7 1 −6 1 8
[ ][ ][ ]
0 12 −42 6 0 6 −6 12 −48
4 8 −18 − 12 −24 18 = −8 32 −36
10 −14 2 −36 6 48 46 −20 −46
[ ][ ] [ ]
2 5 7
T
i. B + D= 8 + −2 = 6
−6 3 −3
17
Lesson Plan
Teacher poses
questions: “Is matrix
multiplication
commutative? Is it
associative? Why/why
not?” Teacher
provides examples of
19
coach, and $150 for youth. Assume stars travel first class, other adults and staff
travel coach, and children travel for the youth fare.
Use multiplication and addition to find the total cost for each troupe to travel
each of the airlines.
It turns out that we can solve problems like these using a matrix operation,
specifically matrix multiplication!
We first note that matrix multiplication is only defined for matrices of certain
sizes. For the product AB of matrices A and B, where A is an m x n matrix, B
must have the same number of rows as A has columns. So, B must have size
n x p. The product AB will have size m x p.
Exercises
The following is a set of abstract matrices (without row and column labels):
[ ]
2 4 1
M= [ 1 −1
2 0 ]
N= 0 −1 3 O=
1 0 2
6
−1 [ ]
[ ] [] [
1
0 4
P=
−1
2
1
Q= 1 R=
3
3 1
−1 0 ]
2
[ ][][ ]
3 1 1
4 2 6 −1
1 0 2
S= T= U= 5 3 1 0
0 2 −3
0 2 −1 1
−1 1 4
List at least 5 orders of pairs of matrices from this set for which the product
is defined. State the dimension of each product.
MO: 2x1 MP: 2x2 PM: 2x2 MR: 2x2 RM: 2x2 NQ: 3x1
[
stars adults children 2 30 5 ¿
¿ 3 19 0 ]
[ ]
630 650 700
Red South Air
420 350 370 ¿
¿
250 275 150
We can multiply these two matrices to obtain the same answers we obtained
above, all in one matrix!
[ ]
630 650 700
¿ [
stars adults children 2 30 5 ¿ Red
3 19 0 ] South Air
¿
420 350 370 ¿
250 275 150
¿ Red
¿ [9870 8600 9130 ]
South Air 15110 13175 13250 ¿
Carmen/Redwing: $ 15110
Carmen/Southeastern: $ 13175
La Traviata/Redwing: $ 9870
La Traviata/Southeastern: $ 8600
Exercises
Bonds 13 25 22
Mort. 6 9 4
Loans 29 17 13
The current yields on these investments are 7.5% for bonds, 11.25% for
mortgages, and 6% for consumer loans. Use matrix multiplication to find
the total earnings for each state.
[ ]
13 25 22
Bonds Mort . Loans NC ND NM NC ND NM
6 9 4 ¿=
[ 1.075 1.1125 1.06 ] ¿
29 17 13
[ 3.39 3.9075 2.88 ]
2. Several years ago, Ms. Allen invested in growth stocks, which she hoped
would increase in value over time. She bought 100 shares of stock A, 200
shares of stock B, and 150 shares of stock C. At the end of each year she
records the value of each stock. The table below shows the price per
share (in dollars) of stocks A, B, and C
1984 1985 1986
at the end of the years 1984, 1985,
and 1986. Stock 68.0 72.00 75.0
A 0 0
Stock 55.0 60.00 67.5
B 0 0
Stock 82.5 84.00 87.0
C 0 0
Calculate the total value of Ms. Allen’s stocks at the end of each year.
Total value of the stocks (in dollars) at the end of each year:
[ ]
68 72 75
A B C 1984 1985 1986 1984 1985 1986
55 60 67.5 ¿=
[ 100 200 150 ] ¿
82.5 84 87
[ 30,175 31,800 34,050 ]
24
25
Define the matrices for the inventory parts (I ) and the daily
manufacturing goal(N ) as
[ ]
50 30 7 3
t ca co d 65 50 9 4 B Ec Ex P
I= ¿∧N=
¿ 85 42 10 6 [ 10 12 11 7 ]
85 42 10 12
t ca co d
¿=
[ 2810 1656 358 228 ]
B Ec Ex P
1.4 N =
[ 14 16.8 15.4 9.8 ]
[]
5
7
H= ¿ Hrs . ¿
¿ 6
7
NH =249
[ ]
Northgate 40039 10135 512
Downtown 15231 8751 105
South 25612 12187 97
What is the Square goal
for each branch in each type of account? (HINT: multiply by a 3 ×2 matrix
with certain nonzero entries on the diagonal and zero entries elsewhere.)
What will be the total number of accounts at each branch?
The goal for each branch in each type of account is given by:
[ ] [ ]
40039 10135 512 1.21 0 0
csm c s m
15231 8751 105 ¿ ⋅ 0 1.35 0 ¿
¿ ¿
25612 12187 97 0 0 1.52
[ ]
48447 13682 778.24
¿ ¿ c s m
18430 11814 159.6 ¿
¿
30991 16452 147.44
27
[]
1
Right-multiplying this result by the matrix 1 yields the following
1
[ ]
62907.68
¿ Total
total number of accounts at each branch: 30402.96 ¿.
¿
47590.41
Lesson Plan
(~90 minutes)
rules/process of
completing a
nanogram.)
Teacher opens
discussion with
students about what
pixels are and asks
students if they know
how to interpret the
numbers. Ultimately,
teacher concludes that
0 represents black and
255 represents white.
Figure: Image of a
Matrix representations:
A grayscale image is a 2-dimensional array of numbers. An 8-bit
The value 255 represents a white color, and the value 0 represents a
black color.
matrix indicate the pixel value of the corresponding part of the image.
pixels.
[ ]
255 255 255
255 0 255
255 255 255
0 255 0
Exercises:
1. Write a matrix that represents each of the following images.
a.
[ ]
0 255 255
255 0 255
255 0 255
255 255 0
255 0 255
b.
[ ]
255 255 255 255
0 255 0 255
255 255 255 0
[ ]
0 255 255
0 255 255
a.
255 0 0
255 255 0
33
[ ]
0 255 255
b. 0 0 255
0 255 255
c. [ 2550 0 0
255 0 ]
Color Images:
Color images can be stored in a similar fashion to a grayscale image.
Instead of one number (0-255) per pixel, one stores three numbers per pixel
– these three numbers denote the “amount” of red, “amount” of green, and
“amount” of blue in each pixel. These three numbers can be used to depict a
wide range of colors.
34
Image transformations:
Once images are represented as matrices, we can describe many
transformations of those images using basic matrix operations!
Example: Suppose we have two separate images that can be represented by the
A B
A+ B=
[ 255 0
+
][
0 0
0 255 255 0
=
255 0
][
255 255 ]
1
3. Compute C= A . How would you describe the image represented by C in
5
relation to the image represented by A ?
1
C= A=
5
1 255 0
5 0 255 [
=
51 0
0 51 ][ ]
The image represented by the matrix C would have pixels that are darker than
those in the image represented by matrix A .
Exercises:
1. a. Describe an image whose matrix representation contains entries of all zeros.
The image would be entirely black.
2. Let A and B be matrices that represent two images of the same size. Describe
in words what each of the following means.
a. A−B
This matrix represents the image that is the result of darkening the image
represented by A , if B has at least one nonzero entry.
b. 5 A + B
This matrix represents the lightening of the image represented by A , since all of
the values in A are multiplied by a positive number, and the entries in B are added
to those entries.
[ 2550
The matrix X ' that represents this image is X =
0]
255
. We can generalize
this result!
Exercises:
1. Which matrix represents the image that is the reflection of the matrix
[ ]
0 a b 0
c d 0 0
A= about the x -axis?
e 0 f g
0 0 0 h
38
[ ]
0 0 0 h
e 0 f g
c d 0 0
0 a b 0
[ ] [ ]
0 255 255 255 255 0
0 255 255 255 0 0
a. x−¿axis:
255 0 0 0 255 255
255 255 0 0 255 255
[ ]
255 255 0
255 255 0
y−¿axis:
0 0 255
0 255 255
[ ] [ ]
0 255 255 0 255 255
b. 0 0 255 x−¿axis: 0 0 255
0 255 255 0 255 255
[ ]
255 255 0
y−¿axis: 255 0 0
255 255 0
c. [ 2550 0 0
255 0 ] x−¿axis: [ 2550 255 0
0 0 ]
y−¿axis: [ 00 0 255
255 0 ]
39
40
Question: From our work above, we know that the matrix representing the
[ 01 10]
[ 01 10][ 12 34]=[21 43 ]
Question: From our work above, we know that the matrix representing the
[ 01 10]
[ 12 34] [01 10]=[ 34 12]
The matrix you used above is a form of a permutation matrix (here
referred to as a reverse identity matrix). This matrix is always square, and
its size is determined by the size of the matrix it is multiplied to (i.e. in
order for the matrix multiplication to be performed).
Exercises:
1
Note that these values each represent a shade of color between white and black, where 0
represents black, and 1 represents white. While we have used only values of 0 and 255 thus far, we
will use these values in this example to make the reflections clear.
41
3. Use the reverse identity matrix of the appropriate size to reflect the
images represented by the following matrices about the x -axis.
[ ] [ ][ ][ ]
0 255 255 0 0 1 0 255 255 0 255 255
a. 0 0 255 0 1 0 0 0 255 = 0 0 255
0 255 255 1 0 0 0 255 255 0 255 255
[ ] [ ][ ][ ]
0 255 255 0 0 0 1 0 255 255 255 255 0
0 255 255 0 0 1 0 0 255 255 255 0 0
b. =
255 0 0 0 1 0 0 255 0 0 0 255 255
255 255 0 1 0 0 0 255 255 0 0 255 255
c. [ 2550 0 0
255 0 ] [ 01 10][ 2550 0 0
255 0][
=
0 255 0
255 0 0 ]
4. Use the reverse identity matrix of the appropriate size to reflect the
images represented by the following matrices about the y -axis.
[ ] [ ][ ] [ ]
0 255 255 0 255 255 0 0 1 255 255 0
a. 0 0 255 0 0 255 0 1 0 = 255 0 0
0 255 255 0 255 255 1 0 0 255 255 0
42
[ ][ ][ ] [ ]
0 255 255 0 255 255 255 255 0
0 0 1
0 255 255 0 255 255 255 255 0
b. 0 1 0=
255 0 0 255 0 0 0 0 255
1 0 0
255 255 0 255 255 0 0 255 255
][ ][
0 0 1
c. [
255 0 0
0 255 0 ] [ 255 0 0
0 255 0
0 1 0=
1 0 0
0 0 255
0 255 0 ]
Reflecting images using matrix-vector multiplication
We can also manipulate images using matrix-vector multiplication. This
method is a bit more powerful than matrix-matrix multiplication, because it
allows us with more flexibility in ways you can manipulate those images.
Using this method, we first convert our matrices into vectors (i.e., single
column or single row matrices).
[]
⋮
x1
⋮
X=
[ ⋮
x1
¿⋮
¿ ] ⃗ )=
x n ¿ ⋮ ¿ ¿⋮ ¿ , we have ( X ….
⋮
xn
⋮
[]
We define mat ( X ) as the matrix conversion of the vector Y . In general,
⋮
x1
⋮
for Y = … , we have mat ( X )=
⋮
⋮ ¿⋮
x1 ¿ n [
x ¿⋮ ¿¿ ⋮ ¿
].
xn
⋮
Examples:
43
[]
1
1. For X = [ ]
1 3 (X
2 4
,
⃗ )= 2
3
.
4
[]
1
2
3
[ ]
1 4 7 4
⃗
2. For X = 2 5 8 , ( X )= 5 .
3 6 9 6
7
8
9
[]
3
5
3. For X = , mat ( X )=
6 [ ]
3 6
5 1
.
1
[]
1
0
0
[ ]
0 1 0 0
4. For X = 1 , mat ( X )= 0 1 0 .
0 0 0 1
0
0
1
Exercises:
[]
5
a. A= [ ]
5 0
3 4
( A)= 3
⃗
0
.
4
44
[]
2
b. B= [ ]
2 3
1 6
(⃗
B )=
1
3
.
6
[]
8
7
8
[ ]
8 8 8 8
⃗ )= 7
c. C= 7 7 7 (C .
8 8 8 8
8
7
8
[]
3
a. X =
5
6
mat ( X )=
[ 35 61]
1
[]
8
7
6
[ ]
5 8 5 2
b. Y = 4 mat (Y )= 7 4 1
3 6 3 0
2
1
0
45
[]
1
Consider the matrix X = [ ]
1 3
2 4
⃗ 2
. We know that ( X )= .
3
4
Question: From our earlier work, we know that the reflection of the image
[]
2
with matrix X about the x -axis would be Y = [ ]
2 4
1 3
⃗ 1
. So, ( Y )= . What matrix
4
3
⃗ ) by on the left in order to obtain ( Y⃗ ) ? Show
would we need to multiply ( X
that your answer gives you the correct result.
[ ] [ ][ ]
2 0 1 0 0 1
1 1 0 0 0 2
Using only 1s and 0s to fill in matrix A: =
4 0 0 0 1 3
3 0 0 1 0 4
Question: From our earlier work, we know that the reflection of the image
[]
3
with matrix X about the y -axis would be Y = [ ]
3 1
4 2
⃗ 4
. So, ( Y )= . What matrix
1
2
⃗ ) by on the right in order to obtain ( Y⃗ ) ? Show
would we need to multiply ( X
that your answer gives you the correct result.
[ ] [ ][ ]
3 0 0 1 0 1
4 0 0 0 1 2
Using only 1s and 0s to fill in matrix A: =
1 1 0 0 0 3
2 0 1 0 0 4
Blurring images
We can also blur images to get an effect we’re interested in, and we use
linear algebra to do it! The image on the left below is the picture, and the
image on the right is the blurred version.
[ ]
1 1 2
Example: Consider an image whose matrix representation is X = 2 1 1 .
3 1 2
Suppose we define a “neighbor” as an entry that is directly above, below,
next to or diagonal from that entry. For example, the entries that are
neighbors of x 31=3 in the matrix are x 21=2, x 22=1 , x 32=1, and x 31=3. So the
2+ 1+ 1+ 3 7
entry y 31 in the new matrix would be = .
4 4
47
[ ]
5/4 8/6 5/4
This gives us Y = 9 /6 14 /9 8 /6 .
7/ 4 10/6 5/4
48
⃗ ). Show
Challenge Question: Find the 9 x 9 matrix A such that Y = A∗(X
that your choice indeed results in Y .
[ ] []
1/4 1 /4 0 1/4 1 /4 0 0 0 0 1
1/6 1/6 1/6 1 /6 1/6 1/6 0 0 0 2
0 1 /4 1/4 0 1 /4 1/4 0 0 0 3
1/6 1/6 0 1 /6 1/6 0 1 /6 1/6 0 1
A= 1 /9 1/9 1/9 1 /9 1/9 1/9 1 /9 1/9 ⃗ )=
1/9 , ( X 1
0 1/6 1/6 0 1/6 1/6 0 1/6 1/6 1
0 0 0 1/4 1 /4 0 1/ 4 1 /4 0 2
0 0 0 1 /6 1/6 1/6 1 /6 1/6 1/6 1
0 0 0 0 1 /4 1/4 0 1 /4 1/4 2
Lesson Plan
Teacher: Subject:
This will be a teacher led activity Topic/Day: Using Python to Manipulate Photos
especially if students are not Content Objective: Use Matrices to solve real
familiar with Python. If students world problems.
have previous Python
programming experience they Materials Needed: Python notebook-nothing
could try the coding on their own. has to be downloaded but you will need to allow
“colab” to run as an extension in Google
Chrome to run the program.
personalization
Explain ~30 Student should ask for help on Review the algorithms
Personalize/
Differentiate as needed min any of the previously taught for reflecting, rotating,
Adjust along matrix operations as needed. blurring and
teacher/student combining as needed.
centered continuum
Provide vocabulary
Clarify understandings
Evaluate N/A Final Code will be the assessment N/A
Summative-like
Assessment
Questions similar to
final assessment
51
Lesson Plan
Standard Topic/Day: Instagram Project
NC.M4.N.2.1 Execute procedures of Content Objective: Use matrices to manipulate and edit a photo to
post on Instagram
addition, subtraction, multiplication, Language Objective:
and scalar multiplication on matrices; Vocabulary:
NC.M4.N.2.2 Execute procedures of Materials Needed: Instagram Project printout, stock images printed,
poster board (or other arts and craft supplies for the students)
addition, subtraction, and scalar
multiplication on vectors.
Extend
Apply knowledge to new scenarios N/A
Continue to personalize as needed
Consider grouping homogeneously
N/A N/A
Evaluate ~10 Share their outcomes with their Facilitate the students
Formative Assessment
How will you know if students mins peers sharing their outcomes
understand throughout the lesson? with their peers
Evaluate
Summative-like
Assessment N/A N/A N/A
Questions similar to final
assessment
[ ]
255 255 255 0 0 255 255 255 255 255
0 0 255 255 0 0 0 255 255 255
255 0 255 255 255 0 0 255 255 255
255 0 0 255 0 0 0 0 255 255
255 255 0 0 0 0 0 0 0 255
A=
255 255 0 0 0 0 0 255 0 0
255 0 0 0 0 0 0 0 0 0
255 0 0 255 0 0 0 0 0 255
0 0 255 255 255 0 0 255 255 255
255 255 255 255 0 0 255 255 255 255
Reflect the image over the x-axis, write the new matrix, and draw the
new image:
54
[ ]
255 255 255 255 0 0 255 255 255 255
0 0 255 255 255 0 0 255 255 255
255 0 0 255 0 0 0 0 0 255
255 0 0 0 0 0 0 0 0 0
255 255 0 0 0 0 0 255 0 0
A=
255 255 0 0 0 0 0 0 0 255
255 0 0 255 0 0 0 0 255 255
255 0 255 255 255 0 0 255 255 255
0 0 255 255 0 0 0 255 255 255
255 255 255 0 0 255 255 255 255 255
Reflect the previous image over the y-axis, write the new matrix, and draw the new image:
[ ]
255 255 255 255 0 0 255 255 255 255
255 255 255 0 0 255 255 255 0 0
255 0 0 0 0 0 255 0 0 255
0 0 0 0 0 0 0 0 0 255
0 0 255 0 0 0 0 0 255 255
A=
255 0 0 0 0 0 0 0 255 255
255 255 0 0 0 0 255 0 0 255
255 255 255 0 0 255 255 255 0 255
255 255 255 0 0 0 255 255 0 0
255 255 255 255 255 0 0 255 255 255
Reflect the previous image over the 45⁰ line, write the new matrix, and draw the new image:
[ ]
255 0 255 255 255 255 255 255 0 255
255 0 0 0 255 255 0 0 0 255
255 255 255 0 0 0 0 0 255 255
0 255 255 255 0 0 0 255 255 255
0 0 255 0 0 0 0 0 255 0
A=
255 0 0 0 0 0 0 0 0 0
255 0 0 0 0 0 0 0 0 255
255 255 255 0 0 255 0 0 255 255
255 255 255 255 0 0 0 0 255 255
255 255 255 255 255 0 0 255 255 255
55
Change the brightness of the previous image by a scalar of 1/2, write the new matrix, and draw the
new image: *Note: you will use the color gray to draw the darkened or lightened image.
[ ]
255 255 255 255 255 255 255 255
0 0
2 2 2 2 2 2 2 2
255 255 255 255
0 0 0 0 0 0
2 2 2 2
255 255 255 255 255
0 0 0 0 0
2 2 2 2 2
255 255 255 255 255 255
0 0 0 0
2 2 2 2 2 2
255 255
0 0 0 0 0 0 0 0
A= 2 2
255
0 0 0 0 0 0 0 0 0
2
255 255
0 0 0 0 0 0 0 0
2 2
255 255 255 255 255 255
0 0 0 0
2 2 2 2 2 2
255 255 255 255 255 255
0 0 0 0
2 2 2 2 2 2
255 255 255 255 255 255 255 255
0 0
2 2 2 2 2 2 2 2
Instagram Project
The project outline is in Appendix A
There is an example of the Instagram Project in Appendix B
58
Appendices
A university is taking inventory of the books they carry at their two biggest
bookstores.
The East Campus bookstore carries the following books:
Hardcover: Textbooks-5280; Fiction-1680; NonFiction-2320; Reference-
1890
Paperback: Textbooks-1930; Fiction-2705; NonFiction-1560; Reference-
2130
In order to work with this information, we can represent the inventory of each
bookstore using an organized array of numbers known as a matrix.
______________. The entry in the “mth” row and “nth” column is written
as a mn.
columns.
If a matrix has only one row, then it is a row ____________. If it has only
Two matrices are _____________ if they have the same size and the same
corresponding entries.
T FN R
Hardback [ ]
W= ¿
Paperback
In our campus bookstores example, we can find the total inventory between
the two bookstores as follows:
E+W =[ ¿ ] + [ ¿ ]
T FN R
Hardback [ ]
= ¿
Paperback
63
Scalar Multiplication
[ ] [ ] []
1 0 1 0 6 −21 5
A= 2 −4 3 B=[ 2 8 −6 ] C= 2 4 −9 D= −2
−6 1 8 5 −7 1 3
b. A+ B b. B – A
c.A–C d. C – A
e. 5 B f. − A+ 4 C
g. B – D h. 2 C−6 A
65
i. BT + D
Matrix Multiplication
Use multiplication and addition to find the total cost for each troupe to travel
each of the airlines.
67
It turns out that we can solve problems like these using a matrix operation,
specifically matrix multiplication!
We first note that matrix multiplication is only defined for matrices of certain
sizes. For the product AB of matrices A and B, where A is an m x n matrix, B
must have the same number of rows as A has columns. So, B must have size
¿¿ p . The product AB will have size ¿¿
Exercises
The following is a set of abstract matrices (without row and column labels):
[ ]
2 4 1
M= [ 1 −1
2 0 ]
N= 0 −1 3 O=
1 0 2
6
−1 [ ]
[ ] [] [
1
0 4
P=
−1
2
1
Q= 1 R=
3
3 1
−1 0 ]
2
[ ][][ ]
3 1 1
4 2 6 −1
1 0 2
S= T= U= 5 3 1 0
0 2 −3
0 2 −1 1
−1 1 4
List at least 5 orders of pairs of matrices from this set for which the product
is defined. State the dimension of each product.
68
We can multiply these two matrices to obtain the same answers we obtained
above, all in one matrix!
Carmen/Redwing:
Carmen/Southeastern:
Carmen/Air Atlanta:
La Traviata/Redwing:
La Traviata/Southeastern:
La Traviata/Air Atlanta:
Exercises2
2
Adapted from Bartkovich, K. G., Goebel, J. A., Graves, J. L., Teague, D. J., Barrett, G. B.,
Compton, H. L., ... & Whitehead, K. (2000). Contemporary Precalculus through
Applications. New York: Glencoe/McGraw-Hill
69
NC ND N
Bonds 13 25 22
Mort. 6 9 4
Loans 29 17 13
The current yields on these investments are 7.5% for bonds, 11.25% for
mortgages, and 6% for consumer loans. Use matrix multiplication to find
the total earnings for each state.
Calculate the total value of Ms. Allen’s stocks at the end of each year.
[ ]
Northgate 40039 10135 512
Downtown 15231 8751 105
South 25612 12187 97
What is Square the goal for
each branch in each type of account? (HINT: multiply by a 3 ×2 matrix
with certain nonzero entries on the diagonal and zero entries elsewhere.)
What will be the total number of accounts at each branch?
72
Figure: Image of a
Matrix representations:
A grayscale image is a 2-dimensional array of numbers. An 8-bit
The value ______ represents a white color, and the value ______
of the matrix indicate the pixel value of the corresponding part of the
image.
pixels.
74
c.
d.
[ ]
0 255 255
0 255 255
d.
255 0 0
255 255 0
[ ]
0 255 255
e. 0 0 255
0 255 255
f. [ 2550 0 0
255 0 ]
Color Images:
76
Image transformations:
Once images are represented as matrices, we can describe many
transformations of those images using basic matrix operations!
Example: Suppose we have two separate images that can be represented by the
matrices A= [ 2550 0
]
255
and B=[ 0 0
255 0 ]
.
1
6. Compute C= A . How would you describe the image represented by C in
5
relation to the image represented by A ?
77
Exercises:
2. a. Describe an image whose matrix representation contains entries of all zeros.
3. Let A and B be matrices that represent two images of the same size.
Describe in words what each of the following means.
a. A−B b. 5 A + B
[ 2550
The matrix X ' that represents this image is X =
0]
255
. We can generalize
this result!
Exercises:
1. Which matrix represents the image that is the reflection of the matrix
[ ]
0 a b 0
c d 0 0
A= ?
e 0 f g
0 0 0 h
1
2
[ ] [ ]
0 255 255
0 255 255
b.
0 255 255
255 0 0
b. 0 0 255
0 255 255
c. [ 2550 0 0
255 0 ]
255 255 0
Question: From our work above, we know that the matrix representing the
image reflected about the x -axis is [ ¿ ] . What matrix would we need to
multiply X by on the left in order to obtain the matrix of the image reflected
about the x -axis? Show that your answer gives you the correct result.
3
(Note that these values each represent a shade of color between white and black, where 0
represents black, and 1 represents white. While we have used only values of 0 and 255 thus far, we
will use these values in this example to make the reflections clear.)
3
Question: From our work above, we know that the matrix representing the
image reflected about the y -axis is [ ¿ ] . What matrix would we need to
multiply X by on the right in order to obtain the matrix of the image
reflected about the y -axis? Show that your answer gives you the correct
result.
Exercises:
7. Use the reverse identity matrix of the appropriate size to reflect the
images represented by the following matrices about the x -axis.
[ ]
0 255 255
a. 0 0 255
0 255 255
[ ]
0 255 255
0 255 255
b.
255 0 0
255 255 0
c. [ 2550 0 0
255 0 ]
8. Use the reverse identity matrix of the appropriate size to reflect the
images represented by the following matrices about the y -axis.
[ ]
0 255 255
a. 0 0 255
0 255 255
[ ]
0 255 255
0 255 255
b.
255 0 0
255 255 0
5
c. [ 255 0 0
0 255 0 ]
Using this method, we first convert our matrices into vectors (i.e., single
column or single row matrices).
[]
⋮
x1
⋮
X=
[ ⋮
x1
¿⋮
¿ ] ⃗ )=
x n ¿ ⋮ ¿ ¿⋮ ¿ , we have ( X …
⋮
.
xn
⋮
[]
We define mat ( X ) as the matrix conversion of the vector Y . In general,
⋮
x1
⋮
for Y = … , we have mat ( X )=
⋮
⋮ ¿⋮
[
x ¿⋮ ¿¿ ⋮ ¿
x1 ¿ n ].
xn
⋮
Examples:
5. For X = [ 12 34 ], ( X⃗ )= ¿ .
[ ]
6
[ ]
1 4 7
⃗ )=[ ¿ ] .
6. For X = 2 5 8 , ( X
3 6 9
[]
3
5
7. For X = , mat ( X )=[ ¿ ].
6
1
[]
1
0
0
0
8. For X = 1 , mat ( X )=[ ¿ ].
0
0
0
1
Exercises:
a. A= [ 53 04 ] A ) =[ ¿ ] .
(⃗
b. B= [ 21 36] B )= [ ¿ ] .
(⃗
[ ]
8 8 8
c. C= 7 7 7 ⃗ )=[ ¿ ] .
(C
8 8 8
[]
3
5
a. X = mat ( X )=[ ¿ ]
6
1
[]
8
7
6
5
b. Y = 4 mat (Y )=[ ¿ ]
3
2
1
0
8
[]
1
Consider the matrix X = [ ]
1 3
2 4
⃗ 2
. We know that ( X )= .
3
4
Question: From our earlier work, we know that the reflection of the image
Question: From our earlier work, we know that the reflection of the image
Blurring images
We can also blur images to get an effect we’re interested in, and we use
linear algebra to do it! The image on the left below is the picture, and the
image on the right is the blurred version.
[ ]
1 1 2
Example: Consider an image whose matrix representation is X = 2 1 1 .
3 1 2
Suppose we define a “neighbor” as an entry that is directly above, below,
next to or diagonal from that entry. For example, the entries that are
neighbors of x 31=3 in the matrix are x 21=2, x 22=1 , x 32=1, and x 31=3. So the
2+ 1+ 1+ 3 7
entry y 31 in the new matrix would be = .
4 4
This gives us Y = [ 7 /4 ¿ ¿ ] .
10
⃗ ). Show
Challenge Question: Find the 9 x 9 matrix A such that Y = A∗(X
that your choice indeed results in Y .
A=[ ¿ ]
Reflect the image over the x-axis, write the new matrix, and draw the
new image:
A=[ ¿ ]
A=[ ¿ ]
Reflect the previous image over the 45⁰ line, write the new matrix, and
draw the new image:
A=[ ¿ ]
A=[ ¿ ]
Blur the original image and write the new matrix (you do not need
to draw the new image):
12
A=[ ¿ ]
You are going to edit your given image to be Instagram ready! You will need to use
a combination of reflections, blurs, and brightness changes to post this image and
get LOTS of likes and comments.
Step 1:
● Come up with an Instagram handle (Note: all Instagram handles must be
school appropriate and approved by the teacher before you can choose your
image for step 2)
Step 2:
● Choose an image from your teacher to utilize throughout this project. First
come first serve, so be sure to pick your image quick!
Step 3:
● As a group, decide what types of reflections, inversions, and brightness
changes you would like to complete to post your picture. You MUST use one
of each type of edit!
Step 4:
● Create matrices and a new image for each edit that you complete. You will
need to turn this into your teacher at the end of the project.
Step 5:
● Once your edits are complete, you must come up with a perfect caption for
this photo (Note: all captions must be school appropriate).
o Remember, the better the caption, the more likely you are to receive
more likes and comments!
Step 6:
● Post your final image to the classroom Instagram feed on the wall and turn
in all other materials and work to your teacher.
14
Grading Rubric:
Potential Actual
What the teacher is looking for: Points Points
Earned Earned
Total Points: 15
15
* *
** **
** **
17
** **
** ***
*** ***
Original Image:
[ ]
255 255 255 0 0 255 255 255 255 255
0 0 255 255 0 0 0 255 255 255
255 0 255 255 255 0 0 255 255 255
255 0 0 255 0 0 0 0 255 255
255 255 0 0 0 0 0 0 0 255
A=
255 255 0 0 0 0 0 255 0 0
255 0 0 0 0 0 0 0 0 0
255 0 0 255 0 0 0 0 0 255
0 0 255 255 255 0 0 255 255 255
255 255 255 255 0 0 255 255 255 255
[ ]
255 255 255 255 0 0 255 255 255 255
0 0 255 255 255 0 0 255 255 255
255 0 0 255 0 0 0 0 0 255
255 0 0 0 0 0 0 0 0 0
255 255 0 0 0 0 0 255 0 0
A=
255 255 0 0 0 0 0 0 0 255
255 0 0 255 0 0 0 0 255 255
255 0 255 255 255 0 0 255 255 255
0 0 255 255 0 0 0 255 255 255
255 255 255 0 0 255 255 255 255 255
[ ]
255 255 255 255 0 0 255 255 255 255
255 255 255 0 0 255 255 255 0 0
255 0 0 0 0 0 255 0 0 255
0 0 0 0 0 0 0 0 0 255
0 0 255 0 0 0 0 0 255 255
A=
255 0 0 0 0 0 0 0 255 255
255 255 0 0 0 0 255 0 0 255
255 255 255 0 0 255 255 255 0 255
255 255 255 0 0 0 255 255 0 0
255 255 255 255 255 0 0 255 255 255
[ ]
255 0 255 255 255 255 255 255 0 255
255 0 0 0 255 255 0 0 0 255
255 255 255 0 0 0 0 0 255 255
0 255 255 255 0 0 0 255 255 255
0 0 255 0 0 0 0 0 255 0
A=
255 0 0 0 0 0 0 0 0 0
255 0 0 0 0 0 0 0 0 255
255 255 255 0 0 255 0 0 255 255
255 255 255 255 0 0 0 0 255 255
255 255 255 255 255 0 0 255 255 255
Change the brightness of the previous image by a scalar of 1/2, write the new matrix, and draw the
new image: *Note: you will use the color gray to draw the darkened or lightened image.
[ ]
1 ⋯ 1
Image Inversion – 255 ∙ ⋮ ⋱ ⋮ − A:
1 ⋯ 1