Chapter 3 Data Representation Data and Computers n

  • Slides: 50
Download presentation
Chapter 3 Data Representation

Chapter 3 Data Representation

Data and Computers n Computers are multimedia devices, dealing with many categories of information.

Data and Computers n Computers are multimedia devices, dealing with many categories of information. Computers store, present, and help us modify n n n Numbers Text Audio Images and graphics Video 2

Analog and Digital Information n Computers are finite. Computer memory and other hardware devices

Analog and Digital Information n Computers are finite. Computer memory and other hardware devices have only so much room to store and manipulate a certain amount of data. The goal of data representation is to represent enough of the world to satisfy our computational needs and our senses of sight and sound. 3

Analog and Digital Information n Information can be represented in one of two ways:

Analog and Digital Information n Information can be represented in one of two ways: analog or digital. Analog data A continuous representation, analogous to the actual information it represents. Digital data A discrete representation, breaking the information up into separate elements. 4

Analog and Digital Information A mercury thermometer exemplifies analog data as it continually rises

Analog and Digital Information A mercury thermometer exemplifies analog data as it continually rises and falls in direct proportion to the temperature. Digital displays only show discrete information. 5

Analog and Digital Information n n Computers cannot work well with analog information, so

Analog and Digital Information n n Computers cannot work well with analog information, so we digitize information by breaking it into pieces and representing those pieces separately. Why do we use binary? Modern computers are designed to use and manage binary values because the devices that store and manage the data are far less expensive and far more reliable if they only have to represent one of two possible values. 6

Electronic Signals n n An analog signal continually fluctuates in voltage up and down.

Electronic Signals n n An analog signal continually fluctuates in voltage up and down. But a digital signal has only a high or low state, corresponding to the two binary digits. All electronic signals (both analog and digital) degrade as they move down a line. That is, the voltage of the signal fluctuates due to environmental effects. 7

Electronic Signals (Cont’d) An analog and a digital signal Degradation of analog and digital

Electronic Signals (Cont’d) An analog and a digital signal Degradation of analog and digital signals n Periodically, a digital signal is reclocked to regain its original shape. 8

Representing Text n n To represent a text document in digital form, we need

Representing Text n n To represent a text document in digital form, we need to be able to represent every possible character that may appear. There is a finite number of characters to represent, so the general approach is to list them all and assign each a binary string. A character set is a list of characters and the codes used to represent each one. By agreeing to use a particular character set, computer manufacturers have made the processing of text data easier. 9

The ASCII Character Set n n n ASCII stands for American Standard Code for

The ASCII Character Set n n n ASCII stands for American Standard Code for Information Interchange. The ASCII character set originally used seven bits to represent each character, allowing for 128 unique characters. Later ASCII evolved so that all eight bits were used which allows for 256 characters. 10

The ASCII Character Set n n Note that the first 32 characters in the

The ASCII Character Set n n Note that the first 32 characters in the ASCII character chart do not have simple character representations that you could print to the screen. Some, however, perform actions with which you are familiar. 11

The ASCII Character Set 8 9 A B C D E F 1000 1001

The ASCII Character Set 8 9 A B C D E F 1000 1001 1010 1011 1100 1101 1110 1111 7 0111 6 0110 5 0101 4 0100 3 0011 2 0010 1 0001 Binary 0 0000 Hex BS HT LF CR ESC 0010 ! " # $ % & ' ( ) * + , - . / 3 0011 0 1 2 3 4 5 6 7 8 9 : < = > ? 4 0100 @ A B C D E F G H I J K L M N O 5 0101 P Q R S T U V W X Y Z [ ] ^ _ 6 0110 ` a b c d e f g h i j k l m n o 7 0111 p q r s t u v w x y z { | } ~ DEL 0 0000 1 0001 2 ; 12

The Unicode Character Set n n n Even the extended version of the ASCII

The Unicode Character Set n n n Even the extended version of the ASCII character set is not enough for international use. The Unicode character set uses 16 bits per character. The Unicode character set can represent 216, or over 65 thousand characters. Unicode was designed to be a superset of ASCII. That is, the first 256 characters in the Unicode character set correspond exactly to the extended ASCII character set. 13

The Unicode Character Set Figure 3. 6 A few characters in the Unicode character

The Unicode Character Set Figure 3. 6 A few characters in the Unicode character set 14

Data Compression n It is important that we find ways to store and transmit

Data Compression n It is important that we find ways to store and transmit data efficiently, which leads computer scientists to find ways to compress it. n Data compression is a reduction in the amount of space needed to store a piece of data. n Compression ratio is the size of the compressed data divided by the size of the original data. 15

Data Compression n A data compression technique can be q q n lossless, which

Data Compression n A data compression technique can be q q n lossless, which means the data can be retrieved without any loss of the original information, lossy, which means some information may be lost in the process of compaction. As examples, consider these 3 techniques: q q q keyword encoding run-length encoding Huffman encoding 16

Keyword Encoding n n Frequently used words are replaced with a single character. For

Keyword Encoding n n Frequently used words are replaced with a single character. For example… Note, that the characters used to encode cannot be part of the original text. 17

Keyword Encoding n Consider the following paragraph, The human body is composed of many

Keyword Encoding n Consider the following paragraph, The human body is composed of many independent systems, such as the circulatory system, the respiratory system, and the reproductive system. Not only must all systems work independently, they must interact and cooperate as well. Overall health is a function of the well-being of separate systems, as well as how these separate systems work in concert. 18

Keyword Encoding n This version highlights the words that can be replaced. The human

Keyword Encoding n This version highlights the words that can be replaced. The human body is composed of many independent systems, such as the circulatory system, the respiratory system, and the reproductive system. Not only must each system work independently, they must interact and cooperate as well. Overall health is a function of the well-being of separate systems, as well as how those separate systems work in concert. 19

Keyword Encoding n This is the encoded paragraph: The human body is composed of

Keyword Encoding n This is the encoded paragraph: The human body is composed of many independent systems, such ^ ~ circulatory system, ~ respiratory system, + ~ reproductive system. Not only & each system work independently, they & interact + cooperate ^ %. Overall health is a function of ~ %- being of separate systems, ^ % ^ how # separate systems work in concert. 20

Keyword Encoding n n n There a total of 349 characters in the original

Keyword Encoding n n n There a total of 349 characters in the original paragraph including spaces and punctuation. The encoded paragraph contains 314 characters, resulting in a savings of 35 characters. The compression ratio for this example is 314/349 or approximately 0. 9. 21

Run-Length Encoding n n A single character may be repeated over and over again

Run-Length Encoding n n A single character may be repeated over and over again in a long sequence. This type of repetition doesn’t generally take place in English text, but often occurs in large data streams. In run-length encoding, a sequence of repeated characters is replaced by a flag character, followed by the repeated character, followed by a single digit that indicates how many times the character is repeated. 22

Run-Length Encoding Some examples: n AAAAAAA would be encoded as *A 7 n *n

Run-Length Encoding Some examples: n AAAAAAA would be encoded as *A 7 n *n 5*x 9 ccc*h 6 some other text *k 8 eee can be decoded into the following original text nnnnnxxxxxccchhhhhh some other text kkkkeee 23

Run-Length Encoding n n The original text contains 51 characters, and the encoded string

Run-Length Encoding n n The original text contains 51 characters, and the encoded string contains 35 characters, giving us a compression ratio in this example of 35/51 or approximately 0. 68. Since we are using one character for the repetition count, it seems that we can’t encode repetition lengths greater than nine. Instead of interpreting the count character as an ASCII digit, we could interpret it as a binary number. 24

Huffman Encoding n n n Why should the character “X”, which is seldom used

Huffman Encoding n n n Why should the character “X”, which is seldom used in text, take up the same number of bits as the blank, which is used very frequently? Huffman codes use variable-length bit strings to represent each character. A few characters may be represented by five bits, and another few by six bits, and yet another few by seven bits, and so forth. 25

Huffman Encoding n If we use only a few bits to represent characters that

Huffman Encoding n If we use only a few bits to represent characters that appear often and reserve longer bit strings for characters that don’t appear often, the overall size of the document being represented will be smaller. 26

Huffman Encoding n An example of a Huffman alphabet 27

Huffman Encoding n An example of a Huffman alphabet 27

Huffman Encoding n n DOORBELL would be encoded in binary as 10111101001100100. If we

Huffman Encoding n n DOORBELL would be encoded in binary as 10111101001100100. If we used a fixed-size bit string to represent each character (say, 8 bits), then the binary from of the original string would be 64 bits. The Huffman encoding for that string is 25 bits long, giving a compression ratio of 25/64, or approximately 0. 39. An important characteristic of any Huffman encoding is that no bit string used to represent a character is the prefix of any other bit string used to represent a character. 28

Representing Audio Information n n We perceive sound when a series of air compressions

Representing Audio Information n n We perceive sound when a series of air compressions vibrate a membrane in our ear, which sends signals to our brain. A stereo sends an electrical signal to a speaker to produce sound. This signal is an analog representation of the sound wave. The voltage in the signal varies in direct proportion to the sound wave. 29

Representing Audio Information n n To digitize the signal we periodically measure the voltage

Representing Audio Information n n To digitize the signal we periodically measure the voltage of the signal and record the appropriate numeric value. The process is called sampling. In general, a sampling rate of around 40, 000 times per second is enough to create a reasonable sound reproduction. 30

Representing Audio Information Figure 3. 8 Sampling an audio signal 31

Representing Audio Information Figure 3. 8 Sampling an audio signal 31

Representing Audio Information n A compact disk (CD) stores audio information digitally. On the

Representing Audio Information n A compact disk (CD) stores audio information digitally. On the surface of the CD are microscopic pits that represent binary digits. A low intensity laser is pointed at the disc. The laser light reflects strongly if the surface is smooth and reflects poorly if the surface is pitted. 32

Representing Audio Information Figure 3. 9 A CD player reading binary information 33

Representing Audio Information Figure 3. 9 A CD player reading binary information 33

Audio Formats n Audio Formats q n WAV, AU, AIFF, VQF, and MP 3

Audio Formats n Audio Formats q n WAV, AU, AIFF, VQF, and MP 3 is dominant q q MP 3 is short for MPEG-2, audio layer 3 file. MP 3 employs both lossy and lossless compression. n n First it analyses the frequency spread and compares it to mathematical models of human psychoacoustics (the study of the interrelation between the ear and the brain), and it discards information that can’t be heard by humans. Then the bit stream is compressed using a form of Huffman encoding to achieve additional compression. 34

Representing Images and Graphics n n Colour is our perception of the various frequencies

Representing Images and Graphics n n Colour is our perception of the various frequencies of light that reach the retinas of our eyes. Our retinas have three types of colour photoreceptor cones which respond to different sets of frequencies. These photoreceptor categories correspond to the colours of red, green, and blue. 35

Representing Images and Graphics n n Colour is often expressed in a computer as

Representing Images and Graphics n n Colour is often expressed in a computer as an RGB (red-green-blue) value, which is actually three numbers that indicate the relative contribution of each of these three primary colours. For example, an RGB value of (255, 0) maximizes the contribution of red and green, and minimizes the contribution of blue, which results in a bright yellow. 36

Representing Images and Graphics Figure 3. 10 Three-dimensional color space 37

Representing Images and Graphics Figure 3. 10 Three-dimensional color space 37

Representing Images and Graphics 38

Representing Images and Graphics 38

Representing Images and Graphics n n n The amount of data that is used

Representing Images and Graphics n n n The amount of data that is used to represent a colour is called the colour depth. Hi. Color is a term that indicates a 16 -bit colour depth. Five bits are used for each number in an RGB value and the extra bit is sometimes used to represent transparency. True. Color indicates a 24 -bit colour depth. Therefore, each number in an RGB value gets eight bits. 39

Representing Images and Graphics n n n Hi. Color uses 5 bits for each

Representing Images and Graphics n n n Hi. Color uses 5 bits for each number. q Since 25 = 32, there are 32 different levels for each of the 3 primary colours. So there are 323 (or 215) possible colours. q This is a total of 32, 768 different colours. True. Color uses eight bits for each colour component. q 28* 28 = 224 or 16, 777, 216 colours. Some monitors can use as many as 32 bits for colour depth. q This is potentially 4, 294, 967, 296 colours! 40

Representing Images and Graphics n n The human eye is able to distinguish about

Representing Images and Graphics n n The human eye is able to distinguish about 200 intensity levels in each of the three primaries red, green, and blue. All in all, up to 10 million different colours can be distinguished. So modern monitors are examples of solutions without a problem. q If the human eye can distinguish only 10 million colours, why develop monitors that can display over 4 billion? 41

Indexed Colour n A particular application such as a browser may support only a

Indexed Colour n A particular application such as a browser may support only a certain number of specific colours, creating a palette from which to choose. For example, Netscape Navigator’s colour palette has only 216 colours. 42

Digitized Images and Graphics n n Digitizing a picture is the act of representing

Digitized Images and Graphics n n Digitizing a picture is the act of representing it as a collection of individual dots called pixels. The number of pixels used to represent a picture is called the resolution. As an example, the resolution of many monitors is 1024 X 768, or 786, 432 pixels. If the colour of each pixel is stored as 24 bits (3 bytes) of data, the screen alone requires 2, 359, 296 bytes (2 mega. Bytes) of memory. 43

Digitized Images and Graphics Figure 3. 12 A digitized picture composed of few individual

Digitized Images and Graphics Figure 3. 12 A digitized picture composed of few individual pixels 44

Digitized Images and Graphics Figure 3. 12 A digitized picture composed of many individual

Digitized Images and Graphics Figure 3. 12 A digitized picture composed of many individual pixels 45

Digitized Images and Graphics n n The storage of image information on a pixelby-pixel

Digitized Images and Graphics n n The storage of image information on a pixelby-pixel basis is called a raster-graphics format. There are several popular raster file formats including: q q q BMP (bitmap) GIF (Graphics Interchange Format) JPEG (Joint Photographic Experts Group) 46

Vector Graphics n n Instead of assigning colours to pixels as we do in

Vector Graphics n n Instead of assigning colours to pixels as we do in raster graphics, a vector-graphics format describes an image in terms of lines and geometric shapes. A vector graphic is a series of commands that describe a line’s direction, thickness, and colour. The file size for these formats tend to be small because every pixel does not have to be represented. 47

Vector Graphics n n n Vector graphics can be resized mathematically, and these changes

Vector Graphics n n n Vector graphics can be resized mathematically, and these changes can be calculated dynamically as needed. This makes them particularly useful for defining scalable fonts. However, vector graphics is not a good technique for representing real-world images. 48

Representing Video n n A video codec (COmpressor/DECompressor) refers to the methods used to

Representing Video n n A video codec (COmpressor/DECompressor) refers to the methods used to shrink the size of a movie to allow it to be played on a computer or over a network. Almost all video codecs use lossy compression to minimize the huge amounts of data associated with video. 49

Representing Video n Codecs use two types of compression spatial and temporal. q q

Representing Video n Codecs use two types of compression spatial and temporal. q q Spatial compression A technique based on removing redundant information within a frame. This problem is essentially the same as that faced when compressing still images. Temporal compression A technique based differences between consecutive frames. If most of an image in two frames hasn’t changed, why should we waste space to duplicate all of the similar information? 50