Академический Документы
Профессиональный Документы
Культура Документы
x = (x1 , x2 , . . . , xN )
where N is even.
I Your task: Send an approximation s (a list of numbers) of this data
via the internet to a colleague.
I In order to reduce transfer time, the length of your approximation
must be N/2.
I How do you suggest we do it?
x = (x1 , x2 , . . . , xN )
where N is even.
I Your task: Send an approximation s (a list of numbers) of this data
via the internet to a colleague.
I In order to reduce transfer time, the length of your approximation
must be N/2.
I How do you suggest we do it?
x = (x1 , x2 , . . . , xN )
where N is even.
I Your task: Send an approximation s (a list of numbers) of this data
via the internet to a colleague.
I In order to reduce transfer time, the length of your approximation
must be N/2.
I How do you suggest we do it?
x = (x1 , x2 , . . . , xN )
where N is even.
I Your task: Send an approximation s (a list of numbers) of this data
via the internet to a colleague.
I In order to reduce transfer time, the length of your approximation
must be N/2.
I How do you suggest we do it?
x = (6, 12, 15, 15, 14, 12, 120, 116) → s = (9, 15, 13, 118)
x = (6, 12, 15, 15, 14, 12, 120, 116) → s = (9, 15, 13, 118)
x2k − x2k −1
dk = , k = 1, . . . , N/2
2
x2k − x2k −1
dk = , k = 1, . . . , N/2
2
x2k − x2k −1
dk = , k = 1, . . . , N/2
2
x2k − x2k −1
dk = , k = 1, . . . , N/2
2
(6, 12, 15, 15, 14, 12, 120, 116) → (9, 15, 13, 118 | 3, 0, −1, −2)
(6, 12, 15, 15, 14, 12, 120, 116) → (9, 15, 13, 118 | 3, 0, −1, −2)
(6, 12, 15, 15, 14, 12, 120, 116) → (9, 15, 13, 118 | 3, 0, −1, −2)
(6, 12, 15, 15, 14, 12, 120, 116) → (9, 15, 13, 118 | 3, 0, −1, −2)
I The transformation
I The transformation
x1 + x2
−1
1 0 0 0 0 0 0 x1
x3 + x4
1 0 0 0 1 0 0 0 x2
0 −1
x5 + x6
0 1 0 0 0 0 x3
1 x7 + x8
0 1 0 0 0
1 0 0 ·
= x4
0 0 1 0 0
0 −1 0 2
x2 − x1
x5
0 0 1 0 0
0 1 0
x −x
x6
0 0 0 1 0 0 0 −1 4 3 x7
x − x5
6
0 0 0 1 0 0 0 1 x8
x8 − x7
x1 + x2
−1
1 0 0 0 0 0 0 x1
x3 + x4
1 0 0 0 1 0 0 0 x2
0 −1
x5 + x6
0 1 0 0 0 0 x3
1 x7 + x8
0 1 0 0 0
1 0 0 ·
= x4
0 0 1 0 0
0 −1 0 2
x2 − x1
x5
0 0 1 0 0
0 1 0
x −x
x6
0 0 0 1 0 0 0 −1 4 3 x7
x − x5
6
0 0 0 1 0 0 0 1 x8
x8 − x7
I Learning how to code the HWT and its inverse provides a good
review of linear algebra.
I We’ll use N = 8 as an example. Let
1 1
2 2 0 0 0 0 0 0
0 0 1 1
2 2 0 0 0 0
0 0 1 1
0 0 2 2 0 0
1 1
0 0 0 0 0 0 H
2 2
W8 = = −
1 1
−2 2 0 0 0 0 0 0 G
0 0 − 12 12
0 0 0 0
0 0 − 12 1
0 0 0 0
2
0 0 0 0 0 0 − 12 1
2
I Learning how to code the HWT and its inverse provides a good
review of linear algebra.
I We’ll use N = 8 as an example. Let
1 1
2 2 0 0 0 0 0 0
0 0 1 1
2 2 0 0 0 0
0 0 1 1
0 0 2 2 0 0
1 1
0 0 0 0 0 0 H
2 2
W8 = = −
1 1
−2 2 0 0 0 0 0 0 G
0 0 − 12 12
0 0 0 0
0 0 − 12 1
0 0 0 0
2
0 0 0 0 0 0 − 12 1
2
I Then
H Hx
W8 x = − x = −
G Gx
I Let’s look at
x1
x2
1 1
0 0 0 0 0 0
2 2
x3
0 0 1 1 0 0 0 0
2 2 x4
H ·x=
·
0 0 0 0 21 12 0 0 x5
0 0 0 0 0 0 21 12
x6
x7
x8
I Then
H Hx
W8 x = − x = −
G Gx
I Let’s look at
x1
x2
1 1
0 0 0 0 0 0
2 2
x3
0 0 1 1 0 0 0 0
2 2 x4
H ·x=
·
0 0 0 0 21 12 0 0 x5
0 0 0 0 0 0 21 12
x6
x7
x8
We have
x1
x2
1 1
0 0 0 0 0 0
2 2
x3
1 1
0 0 0 0 0 0 x4
H ·x =
2 2 ·
1 1 x5
0 0 0 0 2 2 0 0
1 1 x6
0 0 0 0 0 0 2 2
x7
x8
x1 + x2 x1 x2
1 x3 + x4 = x3
x4
· 1/2
=
2 x5 + x6 x5 x6 1/2
x7 + x8 x7 x8
I Thus to code WN · x, we
I Partition the input x into
x2 x1
x4 x3
X =
..
.
xN−1 xN
1/2 −1/2
I Compute s = X · ,d=X·
1/2 1/2
I Return [s | d]
I Thus to code WN · x, we
I Partition the input x into
x2 x1
x4 x3
X =
..
.
xN−1 xN
1/2 −1/2
I Compute s = X · ,d=X·
1/2 1/2
I Return [s | d]
I Thus to code WN · x, we
I Partition the input x into
x2 x1
x4 x3
X =
..
.
xN−1 xN
1/2 −1/2
I Compute s = X · ,d=X·
1/2 1/2
I Return [s | d]
I Thus to code WN · x, we
I Partition the input x into
x2 x1
x4 x3
X =
..
.
xN−1 xN
1/2 −1/2
I Compute s = X · ,d=X·
1/2 1/2
I Return [s | d]
I Thus to code WN · x, we
I Partition the input x into
x2 x1
x4 x3
X =
..
.
xN−1 xN
1/2 −1/2
I Compute s = X · ,d=X·
1/2 1/2
I Return [s | d]
HWT1D[x_]:=Module[{X,s,d,y},
X=Partition[x,2,2];
s=X.{1/2,1/2};
d=X.{-1/2,1/2};
y=Join[s,d];
Return[y];
];
The coding for the inverse is similar but with a different twist at the end.
We need an algorithm for computing
1 0 0 0 −1 y1 − y5
0 0 0 y1
1 0 0 0 1 0 0 0 y2 y1 + y5
0 1 0 0 0 −1 0 0 y3 y2 − y6
0 1 0 0 0 1 0 0 y y + y
W8−1 ·y = · 4 = 2 6
0 0 1 0 0
0 −1 0 y5 y3 − y7
0 0 1 0 0 0 1 0 y6 y3 + y7
0 0 0 1 0
0 0 −1 y7 y4 − y8
0 0 0 1 0 0 0 1 y8 y4 + y8
I We return
(a1 , b1 , a2 , b2 , a3 , b3 , a4 , b4 )
I We return
(a1 , b1 , a2 , b2 , a3 , b3 , a4 , b4 )
I We return
(a1 , b1 , a2 , b2 , a3 , b3 , a4 , b4 )
IHWT1D[y_]:=Module[{Y,a,b,x},
Y=Transpose[Partition[y,Length[y]/2]];
a=Y.{1,-1};
b=X.{1,1};
x=Transpose[{a, b}];
Return[Flatten[x]];
];
HaarTransform1D.nb
2 3
129 128 121 51 127 224 201 179 159 140
6
6 148 116 130 75 184 191 182 185 186 180 77
6
6 175 169 166 195 195 192 168 173 166 158 77
6
6 157 171 169 182 199 205 191 191 180 172 77
6
6 73 89 96 100 122 143 166 190 188 180 77
6
6 93 107 103 81 70 77 106 139 165 181 77
6
6 106 105 112 132 144 147 189 183 158 184 77
6
6 102 100 106 124 140 157 179 175 168 175 77
4 91 105 112 93 86 85 100 104 110 106 5
97 97 112 102 113 111 105 94 103 104
Graphically, we have
B = WN AWMT
B = WN AWMT
B = WN AWMT
B = WN AWMT
Graphically, we have
H h i
W4 AW4T = − A H T | GT
G
HA h i
= − H T | GT
GA
HAH T HAGT
=
GAH T GAGT
a11 + a12 + a21 + a22 a13 + a14 + a23 + a24
1
I HAH T = 4
a31 + a32 + a41 + a42 a33 + a34 + a43 + a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24 A11 A12
A= =
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
a11 + a12 + a21 + a22 a13 + a14 + a23 + a24
1
I HAH T = 4
a31 + a32 + a41 + a42 a33 + a34 + a43 + a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24 A11 A12
A= =
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
a11 + a12 + a21 + a22 a13 + a14 + a23 + a24
1
I HAH T = 4
a31 + a32 + a41 + a42 a33 + a34 + a43 + a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24 A11 A12
A= =
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
a11 + a12 + a21 + a22 a13 + a14 + a23 + a24
1
I HAH T = 4
a31 + a32 + a41 + a42 a33 + a34 + a43 + a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24 A11 A12
A= =
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Partition A in 2 × 2 blocks as
a11 a12 a13 a14
a21 a22 a23 a24
A= = A11 A12
a31 a32 a33 a34 A21 A22
a41 a42 a43 a44
I Writing code for the 2D Haar transform is easy and a good review
of some basic properties from linear algebra.
I Given an M × N matrix A, we wish to compute
B = WM AWNT
LeftHaar[a_]:=Transpose[Map[HWT1D,Transpose[a]]];
I Writing code for the 2D Haar transform is easy and a good review
of some basic properties from linear algebra.
I Given an M × N matrix A, we wish to compute
B = WM AWNT
LeftHaar[a_]:=Transpose[Map[HWT1D,Transpose[a]]];
I Writing code for the 2D Haar transform is easy and a good review
of some basic properties from linear algebra.
I Given an M × N matrix A, we wish to compute
B = WM AWNT
LeftHaar[a_]:=Transpose[Map[HWT1D,Transpose[a]]];
I Writing code for the 2D Haar transform is easy and a good review
of some basic properties from linear algebra.
I Given an M × N matrix A, we wish to compute
B = WM AWNT
LeftHaar[a_]:=Transpose[Map[HWT1D,Transpose[a]]];
I Writing code for the 2D Haar transform is easy and a good review
of some basic properties from linear algebra.
I Given an M × N matrix A, we wish to compute
B = WM AWNT
LeftHaar[a_]:=Transpose[Map[HWT1D,Transpose[a]]];
B T = (CWNT )T = WN C T
B T = (CWNT )T = WN C T
B T = (CWNT )T = WN C T
B T = (CWNT )T = WN C T
B T = (CWNT )T = WN C T
HaarTransform2D.nb
y12
CE1 =
y12 + y22 + · · · + yN2
y12 + y22
CE2 =
y12 + y22 + · · · + yN2
.. ..
. .
y12 + y22 + · · · + yN2
CEN = =1
y12 + y22 + · · · + yN2
Here is the cumulative energy plot for one iteration of the transformed
image:
Here is the cumulative energy plot for two iterations of the transformed
image:
Now simply add the two smallest probabilities to create a new node
with probability 2/7. Branch the two small nodes off this one and resort
the three remaining nodes:
Since only two nodes remain on top, we simply add the probabilities of
these nodes together to get 1 and obtain our finished tree:
Now assign to each left branch the value 0 and to each right branch
the value 1:
I We can read the new bit stream for each character right off the
tree!
I Here are the new bit streams for the four characters:
I We can read the new bit stream for each character right off the
tree!
I Here are the new bit streams for the four characters:
Char. Binary
s 02
e 112
a 1002
w 1012
HaarImageCompression.nb