Transcript for:
Matrix Rank and Image Compression Concepts

this video is sponsored by skillshare this is a rank one Matrix because every row is simply a constant multiple of the first second row is twice the first the third row is -4 times the first you could also say the same thing about the columns just constant multiples of each other like the third column is twice the first but what's nice about rank one matrices is they can be written in this form where you take the first row put it here and these are just those constants we are multiplying by using matrix multiplication as normal this multiplies to our 3x3 rank one Matrix what we just did was in a simple way data compression the 3X3 Matrix requires nine numbers to store but writing in this way only requires six numbers to store it went from 3 * 3 to 3 + 3 if we had a 10x10 rank one Matrix we could write it as a 10x1 matrix times a 1x10 so in this case we go from 100 numbers to 20 again 10 * 10 to 10 + 10 now this Matrix is not a rank one Matrix however it is the sum of two different rank one matrices and this is one of the most important Concepts in linear algebra every Matrix can be represented as a sum of rank one matrices this is the idea behind singular value decomposition or SVD but I'm going to start with an application of that which is image compression because digital images are really just matrices where each entry is a number representing the pixel value or color a 1,00 by 1000 pixel image is represented by a 1,00 by 1000 Matrix each entry being that pixel value and as we just saw any Matrix can be represented as a sum of rank one matrices each holding much less data than the original so to compress an image the idea is simple use only some of the rank one matrices throw out the rest and hopefully you get something that looks similar to the original image so let's see an example here's a 5x5 image of the number four we'll say a black pixel is represented by the number zero and a white pixel by the number one anything in between is just a shade of gray which is darker if it's closer to zero and lighter if it's closer to one so here's the Matrix representing our image you can easily see the number four made up of all ones now this Matrix can also be written as the sum of three rank one matrices finding these matrices and understanding why there's three of them is what singular value decomposition position is about by the way but ignore that for now now with these three rank one matrices what I'm going to do is just throw out this last one and then combine the two that remain to get a new Matrix so now if we were to make the associated image with these pixel values we get this here and by the way for any pixel value greater than one the pixel color is just white and any negative pixel value is black a little weird since we fixed our values between 0 and 1 but still here we have a compressed image where you can still kind of tell the original image was a four we lost some data lost some detail but we can still make out what the original image was the original image was a 5x5 Matrix meaning we had to store 25 numbers but this new image represented as two rank one matrices only requires 20 numbers to be stored this is the idea behind image compression now I could have compressed the image even more and only used the first rank one Matrix reducing 25 numbers to just 10 and this is what we'd get in that case this is probably too much compression since it's hard to tell this was originally a four but using SVD we can kind of choose how much detail we want to retain by choosing how many of the rank one matrices to throw out now to show a little of the math I'm not going to derive singular value decomposition but here's what you should know if you're learning it or soon will be SVD says any Matrix a can be factored into the product of Three Special matrices U Sigma and V transpose where the middle Matrix Sigma is always diagonal or pseudo diagonal which isn't really a word but basically Sigma is always the same size as a so if a is rectangular Sigma might look like this where it is diagonal but with padded zeros but same idea anyways this doesn't seem to say anything about a being a sum of rank one matrices I mean this is a product but it's also a sum because of that middle Matrix and it's easier to see if we just use numbers so if a is this Matrix then its singular value decomposition is this here and how you get that is not what this video is about but because Sigma will always be diagonal this can all be Rewritten as the first number in Sigma times the first column of that first Matrix U times the first row of the last Matrix V transpose plus the second number along the diagonal of Sigma times the second column of U time the second row of V transpose this isn't obvious by just looking but it's basic matrix multiplication it's just another way to rewrite this when that middle Matrix is diagonal and look at that these are just rank one matrices which get added up they're each multiplied by a constant but they're still rank one this is what SVD tells us on the surface it just looks like there's always a way to factor a matrix into three other matrices but it really says any Matrix can be represented as the sum of rank one matrices each weighted by the numbers along the diagonal of that middle Matrix Sigma and what image compression does is it throws away the rank one matrices with the smallest weights so when we threw away that last Matrix in our previous example that wasn't random it was the one with the smallest weight that I didn't show the SVD of our original Matrix is this here that I just found with wolf from alpha notice it has three nonzero values along the diagonal of Sigma that means the original Matrix can be written as the sum of three rank one matrices as we saw the one I threw away was the one multiplied by 73 the smallest number so before when I wrote These out I had multiplied the weights in which is why you didn't see them but if I write it in more proper form with the weights on the outside you get this and then you throw away the smallest weighted rank one Matrix and use the rest which is exactly what we did to get our compressed image and with more complicated images you can choose how many of the lowest weight rank one matrices you want to throw out so that is the idea behind image compression and if you want to learn how to program something like this you can take several kinds of programming courses over at skillshare the sponsor of this video skillshare is the largest online learning community for creatives with thousands of classes led by industry experts from artificial intelligence to 3D animation productivity data science and more and with skillshare you can help take your career skills Hobbies passions or side hustles to the next level for example if you want to Learn Python C or JavaScript they have several classes made for beginners so anyone can just dive in but then they also have classes like data science and machine learning or cyber security where you can focus on more specific topics that especially people in this audience might be more interested in these all involve a learn by doing approach where you get to create and share projects after completing a class and you can even get feedback from the community all while learning at your own pace so get started with skillshare today and the first first 500 people to use my link in the description will receive a one-month free trial so get started today [Music] [Music]