What are compressed and uncompressed files, how does it all work and why compressed files take less storage?

1.97K views

What are compressed and uncompressed files, how does it all work and why compressed files take less storage?

In: Technology

27 Answers

Anonymous 0 Comments

A nice example that I always use to explain compression is using images. Consider a completely WHITE image of size 3000×4000 (about your phone camera resolution).

In the simplest case (it is seldom the case), each pixel of an uncompressed image is stored using 3 numbers to describe its color; for example, in 8-bit RGB color space (red green blue) we use the red blue and green components of a color to describe it. A white pixel has the 3 components equal to 255, so a white pixel is represented by 3 numbers all equal to 255.

Without any compression, a 3000×4000 image is composed by 12M*3 numbers… this means that we need 36 000 000 numbers to store an uncompressed file. This corresponds also the number of bytes that we need to store that uncompressed file (because you are using 8 bits, or 1 byte, for each number). This means that without compression an image taken by your phone would require a bit less than 36GB of memory of storage 🙂

Now suppose you want to compress a white image. The simplest way that we can store the image is to literally say that the image is composed of all equal WHITE pixels. Thus in this extreme case, the only thing that you need to store is the color of ALL the pixels: white (255). In other words, instead of storing 36 000 000 bytes we need to store only 1 byte. Then, the device that we are using to visualize the image (phone in this example) needs to ‘recreate’ the original image by replicating the one pixel for 36M times. So we compressed 36GB into 1B!

In practice, there are many compression algorithms, specific for text (zip), for sound (mp3), for images and videos (jpeg and mpeg), and whatever physical phenomena that you can digitalize. So compression algorithms can be more or less very complex. However the idea behind is still the same of my example, and that is to use the recurrent information in the data to be compressed. In our case the recurrent information is the fact that all pixels are white.

You are viewing 1 out of 27 answers, click here to view all answers.