:

## Unleashing Your Rank Four Self

Maple 14

I have gotten some comments about my new avatar, including a few commenting that while my picture is clear on the blog contributors sidebar, it is "blurry" on my blog posts. I just wanted clear this up.  I am not in the witness protection program; I just really love singular values.  My new avatar, just like my old one, is a rank 4 approximation of a picture of me using the singular value decomposition.

 Original - Rank 323 Compressed - Rank 4 Original - Rank 150 Compressed - Rank 4

Of course, I did this compression in Maple. I described how to do it in one of my first ever Mapleprimes posts. But here it is again using the new 'thin' option for SVD which should allow it to work for larger images than it did before.

```# Read in your face # and convert to YUV (I like the compression artifacts better than the ones from RGB)face := ImageTools:-Read("YourFace.jpg"): face := ImageTools:-RGBtoYUV(face);
m := ImageTools:-Height(face); n := ImageTools:-Width(face); N := min(m, n);
# Colour images are 3 dimensional arrays, use ArrayTools to view it as a tall matrixfaceM := Alias(face, [3*m, n]);
# compute the "thin" SVD of the face matrixU, S, V := LinearAlgebra:-SingularValues(faceM, 'output' = ['U', 'S', 'Vt'], 'thin');

# create the rank 4 version of the face by zeroing out all but the first four singular values:face1 := LinearAlgebra:-MatrixMatrixMultiply(U.LinearAlgebra:-DiagonalMatrix(S[1 .. 4], N, N),     V, 'order' = 'C_order');
ImageTools:-Preview(ImageTools:-YUVtoRGB(ArrayTools:-Reshape(face1, m, n, 3)));

ImageTools:-Write("YourFace-rank4.jpg",     ImageTools:-YUVtoRGB(ArrayTools:-Reshape(face1, m, n, 3)));
```

Rank 4 seems to be the sweet spot for 300x300ish images.  For other sizes, you might want to try higher or lower ranks accordingly.

Here is the code in a worksheet: Rank4-face.mw. Post your Rank 4 faces in the comments!

This has been branched into the following page(s):
﻿