0.4falsefalse1101.0
1.0
2.0
3.0
5.0
8.0
13.0
21.0
34.0
55.0
1
2
2
3
3
5
5
8
8
13
13
21
21
34
34
55
55
89
89
144
fibonacci (generic function with 1 method)1.61803396316670641.6180339887498950.051.0
0.0
1.0
0.05
0.9975
0.1
0.9925
0.149875
0.985006
0.1995
0.975031
0.24875
0.962594
0.297502
0.947719
0.345632
0.930437
0.393017
0.910786
0.439539
0.888809
0.485079
0.864555
0.529519
0.838079
0.572747
0.809442
0.614651
0.778709
0.655123
0.745953
0.694058
0.71125
0.731356
0.674683
0.766919
0.636337
0.800653
0.596304
0.83247
-0.185312
-1.10488
-0.130068
-1.11415
-0.074361
-1.12065
-0.0183286
-1.12437
0.0378898
-1.12528
0.094154
-1.12339
0.150323
-1.11868
0.206258
-1.11117
0.261816
-1.10085
0.316858
-1.08776
UndefVarError: esult not defined
Here is what happened, the most recent locations are first:
UndefVarError: esult not defined
Here is what happened, the most recent locations are first:
f (generic function with 1 method)Singular Value Decomposition
Lorem ipsum SVD est.
0×0 Matrix{Float64}Step 1: upload your favorite image:
true
"asdf"
200
The (black-and-white) image data is now available as a Julia 2D array:
MethodError: no method matching getindex(::Missing, ::String)
Here is what happened, the most recent locations are first:
- extract_img_data
(upload_data::Missing) from Other cell: line 3extract_img_data(upload_data) = let# every 4th byte is the Red pixel valuereds = UInt8.(upload_data["data"][1:4:end])# shuffle and flip to get it in the right shape( reshape(reds, (upload_data["width"], upload_data["height"]))') / 255.0 - Show more...
This notebook defines a type BWImage that can be used to turn 2D Float arrays into a picture!
You can use img_data like any other Julia 2D array! For example, here is the top left corner of your image:
Step 2: running the SVD
The Julia standard library package LinearAlgebra contains a method to compute the SVD.
Let's look at the result.
Let's verify the identity
Are they equal?
It looks like they are not equal - how come?
Since we are using a computer, the decomposition and multiplication both introduce some numerical errors. So instead of checking whether the reconstructed matrix is equal to the original, we can check how close they are to each other.
One way to quantify the distance between two matrices is to look at the point-wise difference. If the sum of all differences is close to 0, the matrices are almost equal.
There are other ways to compare two matrices, such methods are called matrix norms.
The 👀-norm
Another popular matrix norm is the 👀-norm: you turn both matrices into a picture, and use your 👀 to see how close they are:
How similar are these images?
missingIn some applications, like image compression, this is the most imporant norm.
Step 3: compression
Blabla
UndefVarError: img_data not defined
Here is what happened, the most recent locations are first:
Showing the first missing singular pairs.
UndefVarError: 📚 not defined
Here is what happened, the most recent locations are first:
Store fewer bytes
JPEG works in a similar way
Individual pairs
Going further
More stuff to learn about SVD
To keep things simple (and dependency-free), this notebook only works with downscaled black-and-white images that you pick using the button. For color, larger images, or images from your disk, you should look into the Images.jl package!
show (generic function with 381 methods)