Data Representation and Boolean Arithmetic Fall 2019 John K
Total Page:16
File Type:pdf, Size:1020Kb
IWKS 2300 Data Representation and Boolean Arithmetic Fall 2019 John K. Bennett Data Representation Almost anything can be represented digitally: Numbers, and anything that can be expressed numerically Sounds, Audio, etc. Pictures, Video, etc. Digitizing an Analog Value An Analog Signal ... Frequency and Amplitude Different Analog Signals Digital Representation of Analog Signals • We sample the amplitude at time(i). • Record x,y pairs: time(i), amplitude. • The smaller the time increment, the more faithfully we represent the analog wave form. • We can also increase A/D converter precision. • It’s just numbers ... How Fast Must We Sample? Nyquist Sampling Theorem: We must sample at least twice the highest frequency of interest. Example: An Audio Compact Disc 44,100 samples per second Each sample is a 16-bit number 2 channels (L+R) =>176,400 bytes per second 72 minutes capacity, => 762MB data A Brief Sidequest Into Color Human Perception of Color • Receptors (cones) for med and high-brightness color vision** • Sensitivity peaks in Short (blue), Middle (green), Long (red) wavelengths. • Thus, three parameters, corresponding to levels of stimulus to the three types of cone cell, can in principle describe any color sensation. **Also low-brightness, monochromatic "night-vision" rods (peak sensitivity around 490–495 nm). Human Perception of Emitted Light • We do not usually refer to colors using the LMS space defined by the cone spectral sensitivities. Instead, we use these tristimulus values conceptualized as various amounts of three primary colors in an additive color model • Most wavelengths of light will not stimulate only one type of cone cell, because the sensitivity curves of the three cone cells overlap. To have a single component that describes the perceived brightness, “imaginary” primary colors and corresponding color-matching functions were formulated. The resulting tristimulus values are defined by the CIE 1931 color space, in which they are denoted X, Y, and Z. • The CIE XYZ color space is intended to encompass all color sensations that an “average” person can experience. The Visible Color Gamut: CIE 1931 The CIE 1931 XYZ color space was created by the International Commission on Illumination (CIE) in 1931. It was derived from a series of experiments done in the late 1920s by William David Wright and John Guild. Their experimental results were combined into the specification of the CIE RGB color space, from which the CIE XYZ color space was derived. How To Interpret a Gamut The Meaning of X, Y, and Z • When judging the relative luminance (brightness) of different colors in well-lit situations, humans tend to perceive light within the green parts of the spectrum as brighter than red or blue light of equal power. The luminosity function that describes the perceived brightness of different wavelengths is thus roughly analogous to the frequency response of M cones. • The CIE model capitalizes on this fact by defining Y as luminance (or “brightness”). Z is roughly equal to blue stimulation, or the S cone response, and X is a mix (a linear combination) of cone response curves chosen to be nonnegative. The XYZ tristimulus values are thus analogous to, but not equal to, the LMS cone responses of the human eye. Defining Y as luminance has the useful result in that for any given Y value, the XZ plane will contain all possible chromaticities at that luminance. We Can Only Approximate the Human Gamut What’s Wrong With CIE 1931 • An equal mixture of two equally bright colors will not generally lie on the midpoint of that line segment. Thus, a given distance on the xy chromaticity diagram does not correspond to the degree of difference between two colors. • In the early 1940s, David MacAdam studied the nature of visual sensitivity to color differences, and summarized his results in the concept of a MacAdam ellipse. • Based on the work of MacAdam, the CIE 1960, CIE 1964, and CIE 1976 color spaces were developed, with the goal of achieving perceptual uniformity (have an equal distance in the color space correspond to equal differences in perceived color). MacAdam Ellipses MacAdam compared perception of color differences at 25 points on the chromaticity diagram. He found that the size and orientation of the ellipses of equivalent perception on the diagram varied widely depending on the test color. These 25 ellipses measured by MacAdam, for a particular observer are shown here. How to Avoid These Distortions? • A number of attempts have been made to define a color space that is not as distorted as the CIE XYZ space. The most notable of these are the CIELUV and CIELAB color spaces. Although both of these spaces are less distorted than the CIE XYZ space, they are not completely free of distortion. This means that the MacAdam ellipses become nearly (but not exactly) circular in these spaces. • The CIE 1976 (L*, u*, v*) color space, commonly known by its abbreviation CIELUV, is a simple-to- compute transformation of the 1931 CIE XYZ color space that attempts perceptual uniformity. The CIE 1936 and 1976 LUV Gamuts Emitted (Additive) Color Mixing Combine Perceived As Red + Green Yellow Red + Blue Magenta Green + Blue Cyan Red + Green + Blue White Reflected (Substractive) Color We do not perceive only emitted light. Most light that we perceive is reflected off of objects. When light is reflected, what we actually perceive is the light that is not absorbed, i.e., if all colors of light except those of the red wavelengths are absorbed, we perceive a red object. Subtractive Color Mixing When the source of color is pigment or dye, the result of combining colors is different from when the source of color is light. Subtractive color mixing occurs when light is reflected off a surface or is filtered through a translucent object. For example, a red pigment or filter only appears red because it absorbs (subtracts) all of the light that is not red and only reflects or allows the red light. Similarly, a green pigment only reflects green light and a green filter only passes green light. Combine Absorbs Leaves Cyan + Magenta Red + Green Blue Cyan + Yellow Red + Blue Green Magenta + Yellow Green + Blue Red Cyan + Magenta + Yellow Red + Green + Blue Black CMYK Colors With reflected (subtractive) color we are basically mixing pigments to absorb different colors of light rather than mixing light colors. The black created by mixing Cyan, Magenta and Yellow is not generally satisfactory, so we usually add an actual black. It’s the Same Color Wheel; We are just mixing it differently … End of color sidequest RGB Color Model Color is expressed as an RGB value – three numbers that indicate the relative contribution of each of these primary colors. Digital Color Representation We need to make choices about: • Range of values (minimum, maximum) • Number of steps between min and max This equates to choosing the number of pixels in x and y (e.g., 1024x768), and the number of bits for each color (typically in the range 2-8 bits per color, plus the same number for alpha). Example: 8 bits each for R,G, & B, + 8 bits for alpha (transparency) = 32 bits/pixel Raster/Bitmapped Graphics • Storage of data is on a pixel-by-pixel basis Common formats include: Bitmap (BMP), GIF, JPEG, and PNG • Each pixel in a BMP image is just its RGB values • GIF, JPG, and PNG images use compression • How much data is for a BMP image? Typical image size might be 1024 by 768 pixels (= 786,432 pixels) 786,432 pixels * 4 bytes per pixel = 3,145,728 bytes (for one picture) • A 4096 x 2304 24 bpp picture would be 28,311,552 bytes. • A 60 minute 37 fps movie this size would be 3,771,098,726,400 bytes (before compression) Digital Images What Are the Advantages of Digital Representation? • Noise immunity in storage and transmission • Ease of storage/manipulation/transformation • Uniformity -- It's all just bits! So How Do We Represent Numbers in Binary? quantity decimal binary 3-bit register 0 0 000 1 1 001 2 10 010 3 11 011 4 100 100 5 101 101 6 110 110 7 111 111 8 1000 overflow 9 1001 overflow 10 1010 overflow Number Representation Base 10: 3 2 1 0 (9038)ten 910 010 310 810 9038 Base 2: 4 3 2 1 0 (10011)two 1 2 0 2 0 2 1 2 1 2 19 General Case: n i (xn xn1...x0 )b xi b i0 Binary Representation of Numeric Values Sign Magnitude Sign Magnitude (e.g., -2 = 1010) 1 0 One’s Complement 0 0 1 1 = 3 (invert: e.g., -2 = 1101) + 1 0 1 0 = -2 Two’s Complement 1 1 0 1 = -5 (invert and add 1: e.g., -2 = 1101) Two zeros: 0 != -0 Two’s Complement One’s Complement 1 1 1 1 1 1 1 0 0 1 1 = 3 0 0 1 1 = 3 + 1 1 1 0 = -2 + 1 1 0 1 = -2 0 0 0 1 = 1 = 0 1 0 0 0 0 Only one zero: 0 = -0 Two zeros: 0 != -0 Invertible: --n = n Representing 2’s Complement Negative Numbers (4-bit system) 0 0000 0000 -0 The representation of all positive numbers begins with a “0” 1 0001 1111 -1 The representation of all negative numbers 2 0010 1110 -2 begins with a “1“ 3 0011 1101 -3 To convert a two’s comp. number: 4 0100 1100 -4 Inside CPU: complement number and 5 0101 1011 -5 add 1 (easy to do with full adders) On Paper: leave all trailing 0’s and first 6 0110 1010 -6 1 from right intact, then flip all the 7 0111 1001 -7 remaining bits moving left Example: 2 - 5 = 2 + (-5) = 0 0 1 0 + 1 0 1 1 1 1 0 1 = -3 Overflow in 2’s Complement Binary Addition Assuming 4-bit numbers (3 bits plus sign): 0 0 0 1 1 1 1 1 1 0 0 1 = -7 1 0 1 1 = -5 + 0 1 0 1 = 5 + 0 1 1 1 = 7 1 1 1 0 = -2 0 0 1 0 = 2 No overflow Overflow (but we don’t care) How it works: Like decimal addition 0 1 1 1 When signs are opposite, 0 1 0 1 carry into or out of sign bit = 5 can be ignored + 0 1 1 1 = 7 When signs are the same, 1 1 0 0 = -4 carry into sign bit (that changes sign) indicates Overflow (we do care) overflow (that must be handled) Building a Binary Adder 16 a 16-bit 16 out 16 adder b Adder: a chip designed to add two (two’s comp.) integers Implementation: Half adder: designed to add 2 bits Full adder: designed to add 3 bits Adder: designed to add two n-bit numbers.