I compressed the image santosa.jpg using MATLAB's imwrite function. We can
specify the quality as a number between 0 and 100. For example, we first read
the image with the command:
A=imread('santosa.jpg');
Then we can compress the image in matrix A with quality, say, 10 and save it as santosa10_4.jpg using:
imwrite(A,'santosa10_4.jpg','jpeg','quality',10);
Notice as the quality goes down, the file size (in bytes) gets smaller and the image become less recognizable. We can approximate the compression ratio by dividing the original image's file size by the compressed image's file size. A compression factor of size x indicates the compression ratio is x:1.