An example that my last class loved was lossy image compression using the singular value decomposition.
The SVD says that the transformation corresponding to any real matrix (not necessarily square) can be decomposed into three steps: a rotation that forgets some dimensions, a stretch along the coordinate axes, and finally a rotation. In other words, every matrix can be written the form HDA, with the rows of A being orthonormal, the columns of H being orthonormal, and D being a square diagonal matrix with nonnegative nonincreasing entries on the diagonal.
Consider a photograph that is an $768times 1024$ array of $(red,green,blue)$ triples, which we can just as well store as 3 matrices $R$, $G$, and $B$ of real numbers. Now even though the matrix $R$ has nothing to do with transforming space, we can consider it as such, and using SVD write $R=HDA$. Call the numbers on the diagonal of $D$ by $lambda_1geq lambda_2 geq cdots geq lambda_sgeq 0$, and let $D_k'$ be $diag(lambda_1,dots,lambda_k,0,0,dots)$, an $stimes s$ diagonal matrix, and let $D_k$ be $diag(lambda_1,dots,lambda_k)$. Let $H_k$ be the $768times k$ matrix formed from the first $k$ columns of $H$, and similarly let $A_k$ be the $ktimes 1024$ matrix formed from the first $k$ rows of $A$. Then
$$R = HDA approx HD_k' A = H_k D_k A_k,$$
where $approx$ is because of continuity, which is appropriate if the $lambda$'s that were replaced with zeros were small.
Now for the punch-line. We need $3cdot 768 cdot 1024$ (about 2 megabytes) real numbers initially to store the photograph. But to store $H_k$, $D_k$, and $A_k$ for each of the three colors, we need only $3(768cdot k+k+kcdot 1024)=5379 k$ real numbers. With $k=25$, that gives a compression ratio of about 18. That is, file size goes from around 2 mb to around 130 kb. That is, it is faster by a factor of 20 to transmit the three matrices $H_{25}, D_{25}, A_{25}$ than it is to transmit their product.
SVD is fast enough to compute that you can do this instantly (using Mathematica, say) with a picture of the audience, and they can marvel at their own blurry (but quite recognizable) faces. Also, showing the actual file sizes on disk of the original bitmap and the compressed image is quite impressive. At least, it is if your calculations come out extremely close.
What's really impressive about this example (to me, at least) is that the matrix that we start with is just a table of data and not a transformation. But by considering it as if it were a transform, we gain power over it anyway. This is great motivation for linear algebra; students find it much easier to imagine encountering a table of data than a linear transformation.
No comments:
Post a Comment