Chapter 2 Part 1 Linear Algebra Basics and Its Applications in Image Processing and CV
Chapter 2 Part 1 Linear Algebra Basics and Its Applications in Image Processing and CV
ECE467
Image Processing & Robot Vision
=
• Image Processing is the process of transforming an image into a digital form and
performing certain operations to transform, enhance, and extract some useful
information from it.
• It involves the use of algorithms, software, and hardware to process digital images
typically obtained from sources like cameras, satellites, medical devices, or digital
sensors.
• Digital Image processing is the field of study that deals with manipulating digital
images using algorithms and mathematical models.
• Digital Image Processing becomes an essential tool for a wide range of
applications, including medical imaging, computer vision, remote sensing, and
more. In this blog, we will explore the basics of image processing and some of its
applications.
• At the heart lies the Linear algebra that provides the essential mathematical
foundation for a wide range of image processing techniques.
-
Image processing is a
preprocessing step for computer vision
Linear Algebra Basics Chapter 2
Why Linear Algebra is crucial for Image Processing?
1. Digital Image is automatically written in the form of a matrix whose entries
are the pixels values. So any photo is associated to a matrix and vice-versa.
E.g. MATLAB can convert image to a matrix and any matrix to an image.
2. Linear algebra provides a powerful framework for representing and
manipulating digital images. In both spatial and frequency domain, a
digital image is represented as a matrix, where each element in the matrix
corresponds to a pixel value in the image.
Linear Algebra Basics Chapter 2
Why Linear Algebra is Crucial for Image Processing?
• We all share thousands of images, memes etc. to our known ones. But
when it comes to sharing large image files we need to compress it such that
the size of image got reduced significantly keeping the image quality and
content as good as possible. Images are represented as 3 dimensional(2 for
height and width and 1 for channel) array/matrix of pixels, and we all know
whenever matrix is coined linear algebra appears automatically.
Stir t
W(X(t)) = X(f t)
,
Linear Algebra Basics Chapter 2
Linear Algebra
• Vectors
• Operations
• Matrix
• Operations
• Transformations
• Scaling
• Rotation
Important for
• Translation resizing
• Singular Value Decomposition
Linear Algebra Basics Chapter 2
Vectors
• Scalar: 𝑥 ∈ ℝ ↑
• Vector: 𝒙 ∈ ℝ𝑁
• Row Vector v ∈ ℝ1×𝑛
𝒙 = 𝑥1 𝑥2 ⋯ 𝑥𝑛]
𝑥1
𝑥
• Column vector v ∈ ℝ𝑛×1 :𝒙= 2 = 𝑥1 𝑥2 ⋯
⋮
𝑥𝑛
• Transpose
Linear Algebra Basics Chapter 2
Vectors Use
Applications
3
• Store data in memory
• Feature vectors
• Pixel values
•
•
Image Coordinates
Histogram for image segmentation.
De +
?
(zz)
• Any point in coordinate system Eideam
• Can be n dimensional distance
• Difference between two points
[𝑥1 − 𝑦1 𝑥2 − 𝑦2
&
𝑥3 − 𝑦3]
of vectors
Linear Algebra Basics Chapter 2
Vectors Operations/ norm[1] x
(1
= 6608]-
E
• Norm – Measure the magnitude of a Xil
vector (size of the vector). IIXII = ,
Types = 20
• p-norm
general
• 2-norm
• L1-norm simplest 1
x =
(1 6608]
-
2-norm examples
+ (5) + (6)
+
82
= Nad
Linear Algebra Basics Chapter 2
Vectors Operations/ norm[1]
Mathematical Example:
Find the Euclidian distance, Manhattan Distance, and Chebyshev Distance, and
Hamming Distance between the two vectors.
El
| /m 0 + 1
=
Zudideanis
62 + T + = G =
1blea -
chebyshev : 1fIc Max (16-21 13-21 10 - E)
=
, ,
=
5
Hamming : 3 1)
=
Ham
Linear Algebra Basics Chapter 2
chebychea
• Distance metrics are used by a lot of
ZuclienAs
②
machine learning algorithms both
supervised and unsupervised. Manhattane
⑪ Hamming
Find
~
given to it. Distance
Linear Algebra Basics Chapter 2
·
5 56
k 5 83
S S
hz R W
8 6
[5 5 83)
6 90
.
,
2
tre + -4)
Row 5
> deaK」
- - 3 3- 34) 6
Euclidean ED fu k 8
5 6o
E》R, 2 : 2
Pt belongs
4
S
&0
to centroid 2
betny o 2,
Cerbr d . , -f 4,ez
et u vpo C. 2
k = f23,5;6 f
Cmal -
s5
3
5
new Centrof
of K2
taking the
*s
average
67s
, =
-12 (3-30 +
m bl,e
42
o
.
dk, 5· 74a
E f k,
ED r k d = 24·S1IS#4
-E 2 (45-69
32 .
. + .
k Ceu b d
Le 5 a t4 +4 = 4
= 4
4
fn ED er, J, , 19. 1S
A, , , 2.5S 8 Bn
clustering
a
How can we use thes for
Pixels & images
Linear Algebra Basics Chapter 2
I
n
-niggorswa
Student age
20
Tuna
O Based on
Ali 10 Tuna O
algorithm
Sarah Lamp
22
chicken sayer's
Favorite
16
Leen
Lamb
Abdullah fool ?
Mona 18 all
lall
h=
Looking
Mohl
I n0
↑
12
-0 N M
-
=
Sager
-
25 F=1
O
-
nearest
neighbor
is Sara
,
So fal .
foot is
Lamb,
same as
Sara
Linear Algebra Basics Chapter 2
22 34]
B =
[362]
2 -
Norm of B = 376222-49
Unrest (B) =
Norm
=
[E]
(234]
B
A
=
:
=
T projectionof
A on B
Linear Algebra Basics Chapter 2
Vectors Operations/ Outer Product[3]
• Outer product
The outer product of vectors, unlike the dot product, produces a matrix rather than a
scalar. This operation has several applications in image processing and computer vision,
particularly in tasks that involve transformations, feature representation, and spatial
relationships.
Linear Algebra Basics Chapter 2
Vectors Operations/ Outer Product[3]
• Outer product
Example:
(EX3)
(3x =
3x3
matrix
Linear Algebra Basics Chapter 2
Vectors Operations/ Outer Product[3]
• Outer product
7
-
It has one drawback.
What is it?
Resize
Incorrect Example
Example
Correct
Linear Algebra Basics Chapter 2
Linear Algebra IMPORTANTE
• Vectors * column Vector-Scalar (inner)
Now rector
• Operations
column Vector know rector-matix (outer)
• Matrix
• Operations Product
• Transformations
• Scaling
• Rotation
• Translation
• Singular Value Decomposition
Linear Algebra Basics Chapter 2
Matrix
• Array 𝑨 ∈ ℝ 𝑚×𝑛 of numbers with shape m by n,
• m rows and n columns
Matrix = is a rectangular array or
table of numbers, symbols,
or expressions, arranged in rows
and columns, which is used to
represent a mathematical object or
property of such an object.
• A row vector is a matrix with single row
• A column vector is a matrix with single column
Linear Algebra Basics Chapter 2
Matrices Use ⑳ numbers
①
reflect intensity ofcolor
𝑓 𝑥, 𝑦 = 𝑥 + 𝑦
Then,
𝑓 0,0 𝑓 0,1 0+0 1+0
𝑓 𝑥, 𝑦 = = Then, our image is this:
𝑓 1,0 𝑓 1,1 0+1 1+1
0 1
𝑓 𝑥, 𝑦 =
1 2
Linear Algebra Basics Chapter 2
Matrices Operation
•
3
Adding a constant.
• Subtracting a constant. increase/decrease
• Multiplication by a constant. brightness
• Addition & Subtraction. D affects image
-
Brightening increased
Example on Image Processing
for underexposure
parts. However,
overdoing it can lead to
50 + = washed-out highlights
with loss of detail
Linear Algebra Basics Chapter 2
Matrix Operations/ Subtracting A Constant[2]
• Subtracting A Constant
Subtracting a constant from a matrix means subtracting that constant value from every
single element of the matrix.
Example
- 50 =
darkening can obscure
details in shadows
Linear Algebra Basics Chapter 2
Matrix Operations/ Multiplication by A Constant[3]
• (Multiplication by A Constant).
multiplying a matrix by a constant means to make a its element’s range larger or smaller by
multiplying a it by a scalar value.
Example
Scaling intensity value of
image pixels. This will
increase the brightness if
Example on Image Processing the constant >1 &
decrease the brightness if
the constant <1.
150 + - =
-
[]
Example on Image Processing
Ge
Masking: Hadamard multiplication can be used to create masks that selectively enhance or suppress specific
image regions. The original image is multiplied by a binary mask matrix (containing 1s and 0s) where 1s allow
the corresponding pixel values to pass through unchanged, and 0s effectively set those pixels to zero. This
allows you to focus on specific areas of interest in the image.
Convolution: This is a much more common operation in image processing for tasks like filtering, blurring,
sharpening, and edge detection. It involves sliding a kernel (small matrix) over the image and performing
element-wise multiplication and summation with the corresponding pixel values.
Masking(Hudamard product
~
Linear Algebra Basics Chapter 2
Matrix Operations/ Multiplication[6] I can't stopboat
Multiplication means to apply the "dot product" of rows and columns.
Example
thinking a ht
BIV thoug
experiment
2x3 2x2
⑤
Transpose means Flipping" a matrix over its diagonal. The rows and columns get swapped.
Example
The determinant is a less frequently used concept compared to other matrix operations in image
processing. However, its significance lies in the underlying principles it helps us understand, which are
essential for working with matrices in computer vision and image processing tasks..
Linear Algebra Basics Chapter 2
Matrix Operations/ Trace[9]
• Tr(A) = sum of diagonal elements
Example
• Properties
• Tr(AB) = Tr(BA)
• Tr(A + B) = Tr(A) + Tr(B)
𝑨𝑇 =𝑨
Zero
𝑨𝑇 = −𝑨
Is matix :
all elements are Is
def(A) =
I
Linear Algebra Basics Chapter 2
Geometric Transformations
Geometric transformations are operations that manipulate geometric shapes (like points, lines, and
polygons) by changing their position, orientation, or size. These transformations can be applied to
vectors and matrices, which represent these shapes in image processing and computer vision.
Types
Linear Transformation (Non-Linear) Transformation
• A Linear transformation meets the following • A non-Linear transformation do not meet
three conditions linearity conditions.
T(v1 + v2) = T(v1) + T(v2)
T(c v1) = c T(v1)
T(0) = 0
• Sequential application of linear transformation is
again a linear transformation. ·
• Order of transformation is important as in case of
matrix multiplication.
Linear Algebra Basics Chapter 2
Geometric Transformations
Linear Transformation
Linear geometric transformations in image processing are operations that alter the geometric
structure of images using linear functions. These transformations are fundamental in image processing
tasks such as image alignment, object detection, and image enhancement.
Types
Scaling
Rotation
Shearing
Reflection
transformations Ent
M
Parameters
Scaling
Shearing
flipping
↑
↑
New
↑
transformation
originaa
matrix
Linear Algebra Basics Chapter 2
Geometric Transformations
Linear Transformation/ Scaling
Given a coordinates of the object O = (Xold, Yold)
Scaling factor for X-axis = Sx
Scaling factor for Y-axis = Sy
Then, the new coordinates of the object O after scaling = (Xnew, Ynew)
XE
-
axis
y =
-
axis
Diagonal Matrix
Cockwe&
Rotation equations θ >0 Rotation Counter-Clockwise
cost Sing
[e] to2)
direction and find out the new coordinates.
Solution: A
=
A +
10 2)
,
+C = (
()
2
]( j
-
,
= ,
c =
( =
-
-
Linear Algebra Basics Chapter 2
Geometric Transformations
Linear Transformation/ Shearing
In a 2D plane, the object size can be changed along X direction as
well as Y direction. So, there are two versions of shearing:
[2][i] ]
after shearing in Y axis = A (1, 3),
B(0, 0), C(1, 2).
A =
=
A
(b)(2) (i]
=
=
BE
=
B =
[8]
B B = =
[8]
[0 P](0] (0] [i] (2]
=
c =
=
Linear Algebra Basics Chapter 2
Geometric Transformations
Linear Transformation/ Reflection
Reflection is a kind of rotation where the angle of rotation is 180 degree.
The reflected object is always formed on the other side of mirror.
The size of reflected object is same as the size of original object.
Answer: New coordinates of the object = A (1, 4, 3), B(4, 4, 4), C(4, 1, 2), D(1, 1, 2).