L-07 - Data Compression - FINAL - XI Grade

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 20

Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 1

Computational
Thinking
Lecture - 7
Data Compression

Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 2


• All data in a computer is represented in binary, whether it is
Data numbers, text, images or sound. The computer software
processes the data according to its content.

Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 3


What is
compression?
Term: Compression
• In computing, compression is the
act of encoding a file to make it
smaller in size.
• Compressed file types are essential
for the online services we enjoy,
such as streaming video and viewing
websites.

Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 4


Compression
Without compression, we would:
• Fit less music, videos or photos onto your smart phone or
computer
• Struggle to stream or download videos from the internet
• Struggle to upload media to the internet
• Find browsing websites a slower experience

There are two types of compressing the file:


• Lossy
• Lossless

Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 5


Lossy Compression
• Lossy means that data is lost and can
not be recovered once the file is
compressed

• A compression technique to reduce the


size of a computer file. The file can
never be restored to its original state as
redundant data is permanently
removed. This may result in a
noticeable loss in quality.

• You cannot go back from lossy


compression to original.
Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 6
Colors’ Encoding
Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 7
• Jpeg will reduce the RAW BITMAP image
by a factor of between 5 and 15 (or even
greater) depending on the quality of the
original.

• An image that is 2048 pixels wide and 1536


pixels high is equal to 2048 × 1536 pixels;
in other words, 3 145 728 pixels or ~3
Mega Pixels.
• An uncompressed image can often be
referred to as a TIFF or BMP image (file
extension .TIF or .BMP).
• File size = number of pixels. In the previous
example, a 3-megapixel image would be 3
megapixels × 3 colours. In other words, 9
megabytes (each pixel occupies 3 bytes
because it is made up of the three main
colours: red, green and blue). Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022
An image is 800 pixels by 600 pixels.
Calculate:

• the total number of pixels in the original


image

• the number of bytes occupied by this file

• the file size of the jpeg image (in kilobytes) if


the original image was reduced by a factor of
8.

Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 9


Lossless
Compression
• Lossless means that no
data is lost and the original
contents of the file can be
completely recovered.

• The file size is compressed,


the picture quality remains
the same - it does not get
worse. Also, the file can be
decompressed to its
original quality.

Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 10


Why to use lossless
compression?
Lossless compression
There are some files that programmers do not
want to lose data from. For example:
• text files
• spreadsheets
• financial records
• emails

Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 11


Metadata
Files contain extra data called metadata.
Metadata includes data about the file
itself, such as:
• file type
• date created
• author
• height x width
• resolution

Without this metadata, the image data


would not be correctly interpreted,
which means the image could not be
correctly displayed.
Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 12
Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 13
How to see the photo’s metadata (Windows)
Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 14
How to see the photo’s
metadata (MacOS)

Victor Basharov - ADA School // Baku, Azerbaijan –


Fall 2022

15
Pictures’
Encoding

Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 16


Run-length Encoding

• 00000011111111000000 - 20 characters
• 608160 - 6 characters

Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 17


Sound’s Encoding
Victor Basharov - ADA School // Baku, Azerbaijan – Fall 2022 18
Self-check
• What is compression?
• What files could be compressed?
• What compressed file formats do you know?
• List pros and cons of lossy/lossless compression
• How can we use metadata?

Victor Basharov - ADA School // Baku, Azerbaijan – Spring 2022 19


Questions?

You might also like