Before we begin. HW4 is out! Announcements. Lossy Compression. Eliza. Eliza s impact

Similar documents
18.06 Problem Set 4 Due Wednesday, Oct. 11, 2006 at 4:00 p.m. in 2-106

Outline Data Structures and Algorithms. Data compression. Data compression. Lossy vs. Lossless. Data Compression

Lecture 6: Coding theory

Factorising FACTORISING.

Lossless Compression Lossy Compression

CS 360 Exam 2 Fall 2014 Name

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

CS 491G Combinatorial Optimization Lecture Notes

CS 573 Automata Theory and Formal Languages

Solutions for HW9. Bipartite: put the red vertices in V 1 and the black in V 2. Not bipartite!

How do we solve these things, especially when they get complicated? How do we know when a system has a solution, and when is it unique?

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

Lesson 55 - Inverse of Matrices & Determinants

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

Linear Algebra Introduction

AP Calculus BC Chapter 8: Integration Techniques, L Hopital s Rule and Improper Integrals

CSE 332. Sorting. Data Abstractions. CSE 332: Data Abstractions. QuickSort Cutoff 1. Where We Are 2. Bounding The MAXIMUM Problem 4

Surds and Indices. Surds and Indices. Curriculum Ready ACMNA: 233,

Equivalent fractions have the same value but they have different denominators. This means they have been divided into a different number of parts.

2.4 Theoretical Foundations

Numbers and indices. 1.1 Fractions. GCSE C Example 1. Handy hint. Key point

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

Section 2.3. Matrix Inverses

Necessary and sucient conditions for some two. Abstract. Further we show that the necessary conditions for the existence of an OD(44 s 1 s 2 )

CARLETON UNIVERSITY. 1.0 Problems and Most Solutions, Sect B, 2005

Particle Physics. Michaelmas Term 2011 Prof Mark Thomson. Handout 3 : Interaction by Particle Exchange and QED. Recap

SIMPLE NONLINEAR GRAPHS

A Primer on Continuous-time Economic Dynamics

x dx does exist, what does the answer look like? What does the answer to

CS 2204 DIGITAL LOGIC & STATE MACHINE DESIGN SPRING 2014

for all x in [a,b], then the area of the region bounded by the graphs of f and g and the vertical lines x = a and x = b is b [ ( ) ( )] A= f x g x dx

Common intervals of genomes. Mathieu Raffinot CNRS LIAFA

PAIR OF LINEAR EQUATIONS IN TWO VARIABLES

Lecture 11 Binary Decision Diagrams (BDDs)

Lecture 2: Cayley Graphs

I 3 2 = I I 4 = 2A

Total score: /100 points

How do we solve these things, especially when they get complicated? How do we know when a system has a solution, and when is it unique?

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

Lecture Notes No. 10

Data Structures LECTURE 10. Huffman coding. Example. Coding: problem definition

4.5 THE FUNDAMENTAL THEOREM OF CALCULUS

y = c 2 MULTIPLE CHOICE QUESTIONS (MCQ's) (Each question carries one mark) is...

Introduction to Olympiad Inequalities

6.5 Improper integrals

Lecture Solution of a System of Linear Equation

Math 211A Homework. Edward Burkard. = tan (2x + z)

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

Lecture 8: Abstract Algebra

Chapters Five Notes SN AA U1C5

Lecture 2e Orthogonal Complement (pages )

6. Suppose lim = constant> 0. Which of the following does not hold?

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Now we must transform the original model so we can use the new parameters. = S max. Recruits

TOPIC: LINEAR ALGEBRA MATRICES

2.4 Linear Inequalities and Interval Notation

NON-DETERMINISTIC FSA

The DOACROSS statement

Connectivity in Graphs. CS311H: Discrete Mathematics. Graph Theory II. Example. Paths. Connectedness. Example

Solutions to Problem Set #1

F / x everywhere in some domain containing R. Then, + ). (10.4.1)

Welcome. Balanced search trees. Balanced Search Trees. Inge Li Gørtz

Math 520 Final Exam Topic Outline Sections 1 3 (Xiao/Dumas/Liaw) Spring 2008

If we have a function f(x) which is well-defined for some a x b, its integral over those two values is defined as

Mathematics Number: Logarithms

Section 4.4. Green s Theorem

1 This diagram represents the energy change that occurs when a d electron in a transition metal ion is excited by visible light.

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Matrix Algebra. Matrix Addition, Scalar Multiplication and Transposition. Linear Algebra I 24

Exam 1 Study Guide. Differentiation and Anti-differentiation Rules from Calculus I

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points:

SECTION A STUDENT MATERIAL. Part 1. What and Why.?

Note 12. Introduction to Digital Control Systems

Review of Gaussian Quadrature method

p-adic Egyptian Fractions

Eigenvectors and Eigenvalues

Lecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations.

Solids of Revolution

Minimal DFA. minimal DFA for L starting from any other

Section 6: Area, Volume, and Average Value

Things to Memorize: A Partial List. January 27, 2017

Momentum and Energy Review

Chapter 8 Roots and Radicals

PYTHAGORAS THEOREM WHAT S IN CHAPTER 1? IN THIS CHAPTER YOU WILL:

Matrix- System of rows and columns each position in a matrix has a purpose. 5 Ex: 5. Ex:

Probability The Language of Chance P(A) Mathletics Instant Workbooks. Copyright

CS241 Week 6 Tutorial Solutions

Finite State Automata and Determinisation

Chapter Five - Eigenvalues, Eigenfunctions, and All That

Discrete Structures, Test 2 Monday, March 28, 2016 SOLUTIONS, VERSION α

Convert the NFA into DFA

Lecture 3: Equivalence Relations

Lesson 2: The Pythagorean Theorem and Similar Triangles. A Brief Review of the Pythagorean Theorem.

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

Spacetime and the Quantum World Questions Fall 2010

Data Compression Techniques (Spring 2012) Model Solutions for Exercise 4

Chapter 3. Vector Spaces. 3.1 Images and Image Arithmetic

Exercise 3 Logic Control

Transcription:

Announements Lossy Compression 1-211 Funmentl Dt Strutures n Algorithms Peter Lee Ferury 18, 2003 Homework # is ville Due on Mony, Mrh 17, 11:9pm Get strte now! Quiz #2 Aville on Tuesy, Fe.2 Some questions will e esier if you hve some prts of HW working Re Chpter 8 HW is out! Before we egin Eliz Eliz ws one of the first AI progrms J. Weizenum, 19 At the time, it impresse people who use it Eliz hs een implemente mny, mny times gnu ems hs one try M-x otor Eliz s impt Mny stories of Eliz s impt some people eme so epenent tht Weizenum eventully h to withrw its use some psyhitrists sw Eliz s wy for the profession to hnle mny more ptients Eliz might e use for most ptients, n the humn otor reserve for only the most serious ses 1

Eliz s rules Eliz is remrkly simple progrm Some smple rules: X me Y X you Y I rememer X Why o you rememer X just now? My <fmily-memer> is X Who else in your fmily is X? X <fmily-memer> Y Tell me more out your fmily X Tht is very interesting Why Eliz? The nme ws hosen for its ility to onverse inresingly well The Greek legen of Pygmlion the mysogynist King of Cyprus fell in love with n ivory sttue, Glte tking pity, Aphroite me Glte ome live Pygmlion then mrrie Glte Why Eliz? ont George Bernr Shw wrote ply, Pygmlion, se on the legen Professor Higgins retes ly from low-lss okney flower venor, Eliz Doolittle first filme in 1938 Lter, pte into the politilly orret My Fir Ly Wrp-Up on LZW Compression Byte metho LZW We strt with trie tht ontins root n n hilren one hil for eh possile hrter eh hil lele 0 n When we ompress s efore, y wlking own the trie ut, fter emitting oe n growing the trie, we must strt from the root s hil lele, where is the hrter tht use us to grow the trie LZW: Byte metho exmple Suppose our entire hrter set onsists only of the four letters: {,,, } Let s onsier the ompression of the string 2

Byte LZW: Compress exmple Byte LZW: Compress exmple Ditionry: Ditionry: 1 Byte LZW: Compress exmple Byte LZW: Compress exmple Ditionry: Ditionry: 10 103 Byte LZW: Compress exmple Byte LZW: Compress exmple Ditionry: Ditionry: 7 7 1033 1033 3

Byte LZW output So, the input ompresses to 1033 whih gin n e given in it form, just like in the inry metho or ompresse gin using Huffmn Byte LZW: Unompress exmple The unompress step for yte LZW is the most omplite prt of the entire proess, ut is lrgely similr to the inry metho Byte LZW: Unompress exmple Byte LZW: Unompress exmple 1033 1033 Ditionry: Ditionry: Byte LZW: Unompress exmple Byte LZW: Unompress exmple 1033 1033 Ditionry: Ditionry:

Byte LZW: Unompress exmple Byte LZW: Unompress exmple 1033 1033 Ditionry: Ditionry: 7 LZW pplitions LZW is n extremely useful lossless metho for ompressing t LZW is use in the GIF n ompresse TIFF stnrs for imge t Unisys hols the ptent on LZW, ut llows free nonommeril use Quiz Brek LZW performne Suppose we hve file of N s: 1. Wht woul the output look like fter LZW ompression? 2. Wht, roughly, is the size of the output (in ig-oh terms)? 3. How ig woul the output e if we use Huffmn inste? Lossy Compression

Lossy ompression Tehniques Often, we n tolerte some loss of t through the ompress/ eompress yle. Imges, n espeilly vieo/uio, n e huge HDTV it rte is >1Gps! Big prolem for storge n network Lossy ompression is se on mthemtil trnsformtions Disrete Cosine Trnsform (DCT) Use in JPEG lgorithm Wvelet se imge ompression Use in MPEG- Mny, mny, others Imge files Consier this olor imge 2 8 10 12 1 One-imensionl rry of 3 with height ytes Three two-imensionl rrys, one for eh olor omponent This is prt of fmous imge 1 2 8 10 12 1 1 (Do you know who? Hint: Sply) The imge is 1x1 itmp imge enlrge Here is the Re prt of the imge Green Prt 2 2 8 8 10 10 12 12 1 1 1 1 2 8 10 12 1 1 2 8 10 12 1 1

Blue Prt The re imge, gin 2 8 10 12 1 1 2 8 10 12 1 1 173 1 1 1 18 132 123 132 10 1 173 181 181 181 189 173 198 189 189 189 181 1 18 1 1 173 181 198 20 198 181 1 20 20 20 20 198 189 181 181 198 20 20 222 231 21 181 1 231 222 20 198 189 181 181 181 20 222 222 222 231 222 198 181 231 21 189 173 1 1 173 181 181 189 198 222 239 231 20 21 20 189 173 18 18 18 18 1 1 18 1 198 222 231 21 239 181 1 10 123 123 11 11 123 10 18 10 18 1 20 239 27 1 82 82 90 82 90 107 123 123 11 132 10 1 198 231 123 198 7 9 7 82 82 99 107 11 11 123 132 132 18 21 239 239 107 82 82 7 90 107 123 11 11 123 11 11 123 198 2 90 7 7 99 7 11 123 132 123 123 11 11 10 1 189 27 99 99 82 90 107 123 123 123 123 123 132 10 1 181 198 27 239 1 132 107 18 10 132 132 123 132 18 10 10 1 21 198 231 1 1 132 1 1 10 10 10 18 18 132 10 1 222 27 239 222 181 181 10 1 10 18 18 18 10 132 1 20 222 21 198 181 181 181 181 173 18 1 18 10 10 1 198 222 239 Byte vlues (0 2) inite intensity of the olor t eh pixel The re imge, gin 173 1 1 1 18 132 123 132 10 1 173 181 181 181 189 173 2 198 189 189 189 181 1 18 1 1 173 181 198 20 198 181 1 20 20 20 20 198 189 181 181 198 20 20 222 231 21 181 1 231 222 20 198 189 181 181 181 20 222 222 222 231 222 198 181 231 21 189 173 1 1 173 181 181 189 198 222 239 231 20 21 20 189 173 18 18 18 18 1 1 18 1 198 222 231 21 239 181 1 10 123 123 11 11 123 10 18 10 18 1 20 239 27 8 1 82 82 90 82 90 107 123 123 11 132 10 1 198 231 123 198 7 9 7 82 82 99 107 11 11 123 132 132 18 21 10 239 239 107 82 82 7 90 107 123 11 11 123 11 11 123 198 2 90 7 7 99 7 11 123 132 123 123 11 11 10 1 189 12 27 99 99 82 90 107 123 123 123 123 123 132 10 1 181 198 27 239 1 132 107 18 10 132 132 123 132 18 10 10 1 21 1 198 231 1 1 132 1 1 10 10 10 18 18 132 10 1 222 27 239 222 181 181 10 1 10 18 18 18 10 132 1 20 222 1 21 198 181 181 181 181 173 18 1 18 10 10 1 198 222 239 2 8 10 12 1 1 Byte vlues (0 2) inite intensity of the olor t eh pixel JPEG JPEG JPEG in nutshell Joint Photogrphi Expert Group Vote s interntionl stnr in 1992 Works well for oth olor n grysle imges B G R RGB to YIQ (optionl) Y I Q for eh plne (sn) Mny steps in the lgorithm Some requiring sophistition in mthemtis We ll skip mny prts n fous on just the min elements of JPEG DPCM Zig-zg Qunt DCT RLE Huffmn 11010001 for eh 8x8 lok 7

JPEG in nutshell Liner trnsform oing B G R RGB to YIQ (optionl) Y I Q for eh plne (sn) For vieo, uio, or imges, one key first step of the ompression will e to enoe vlues over regions of time or spe DPCM RLE Zig-zg Qunt DCT for eh 8x8 lok The si strtegy is to selet set of liner sis funtions φ i tht spn the spe sin, os, wvelets, efine t isrete points Huffmn 11010001 Liner trnsform oing Cosine trnsform Coeffiients: In mtrix nottion: Where A is n nxn mtrix, n eh row efines sis funtion Disrete Cosine Trnsform Bsis funtions DCT seprtes the imge into spetrl su-ns of iffering importne With input imge A, the output oeffiients B re given y the following eqution: N 1 n N 2 give the imge s height n with 8

JPEG in nutshell Quntiztion B G R RGB to YIQ (optionl) DPCM RLE Y Zig-zg I Q Qunt for eh plne (sn) DCT for eh 8x8 lok The purpose of quntiztion is to enoe n entire region of vlues into single vlue For exmple, n simply elete loworer its: 101101 oul e enoe s 1011 or 101 When iviing y power-of-two, this mounts to eleting whole its Other ivision onstnts give finer ontrol over it loss Huffmn 11010001 JPEG uses stnr quntiztion tle JPEG quntiztion tle JPEG in nutshell q = B G R RGB to YIQ (optionl) Y I Q for eh plne (sn) DPCM Zig-zg Qunt DCT for eh 8x8 lok RLE Eh B(k 1,k 2 ) is ivie y q(k 1,k 2 ). Eye is most sensitive to low frequenies (upper-left). Huffmn 11010001 Zig-zg sn JPEG in nutshell Purpose is to onvert 8x8 lok into 1x vetor, with low-frequeny oeffiients t the front B G R RGB to YIQ (optionl) Y I Q for eh plne (sn) DPCM Zig-zg Qunt DCT for eh 8x8 lok RLE Huffmn 11010001 9

Finl stges Exmple: GIF The DPCM (ifferentil pulse oe moultion) n RLE (run length enoing) steps tke vntge of ommon hrteristi of mny imges: An 8x8 lok is often not too ifferent thn the previous one Within lok, there re often long sequenes of zeros 72KB Exmple: JPEG t mx qulity Exmple: JPEG t 0% 378KB 2KB Exmple: JPEG t 2% Exmple: JPEG t min qulity 7KB 28KB 10

Mtrix eomposition Suppose A is n m n mtrix, e.g.: SVD A = 120 100 120 100 10 10 10 10 0 0 70 80 10 120 10 10 We n eompose A into three mtries, U, S, n V, suh tht A = U S V T Deomposition exmple Singulr vlue eomposition A = 120 100 120 100 10 10 10 10 0 0 70 80 10 120 10 10 U = 0.709-0.772-0.32 0.1009 0.01-0.000-0.139-0.987 0.300 0.7121-0.98 0.1113 0.709 0.18 0.2-0.01 S = 38.1 0 0 0 0 20.1 0 0 0 0 7.82 0 0 0 0 0.9919 V = 0.209-0.19 0.00-0.3137 0.338-0.1330-0.71-0.873 0.300-0.17-0.188 0.8081 0.09 0.829 0.217-0.109 Orthonorml: U U T = I Digonl, with eresing singulr vlues Orthonorml: V V T = I Suh ftoring of mtrix, or eomposition is lle n SVD. Extly how to fin U, V, n S is eyon the sope of this ourse. But you ll fin out in your mtrix/liner lger ourse Note: Very importnt lso for grphis/nimtion lgorithms So wht out ompression? Let: s i e the i th eigen vlue in S U i e the i th olumn in U V i e the i th olumn in V Then, nother formul for mtrix A is A = s 1 U 1 V 1 T + s 2 U 2 V 2 T +.+ s K U K V K T SVD exmple A = 120 100 120 100 10 10 10 10 0 0 70 80 10 120 10 10 U 1 U = 0.709-0.772-0.32 0.1009 0.01-0.000-0.139-0.987 0.300 0.7121-0.98 0.1113 0.709 0.18 0.2-0.01 S = 38.1 0 0 0 0 20.1 0 0 0 0 7.82 0 0 0 0 0.9919 V = 0.209-0.19 0.00-0.3137 0.338-0.1330-0.71-0.873 0.300-0.17-0.188 0.8081 0.09 0.829 0.217-0.109 V 1 s 1 A1 = s 1 U 1 V 1 T = 11 9 117 112 10 9 11 10 70 9 72 9 19 12 12 1 This is lle the rnk-1 pproximtion 11

Let s form rnk-1 sum A1 = s 1 U 1 V 1 T A1 = 11 9 117 112 10 9 11 10 70 9 72 9 19 12 12 1 Error Mtrix A - A1 is 3 12 0 1 1 0 10 1 2 11 1 2 Reltively smll with rnk-1 pproximtion. Wht o we lern here? To ompute A1 we only nee: just one olumn from U, just one olumn from V, n just one singulr vlue An we get: pretty goo pproximtion to the originl mtrix 9 ytes inste of 1 A ig svings in storge! How out rnk-2 pproximtion? A2 = s 1 U 1 V 1 T + s 2 U 2 V 2 T We get A2 = 122 98 119 100 10 9 11 10 2 7 9 81 17 123 11 19 Error Mtrix A - A2 2 2 1 0 0 1 1 0 2 3 1 1 3 3 1 1 Anlysis To get n ie of how lose the pproximtion to the originl mtrix is, we n lulte: Men of Rnk1 error mtrix =3.812 Men of Rnk2 error mtrix =1.370 Where men is the verge of the ll entries We relly on t gin muh y lulting the rnk-2 pproximtion (why?) SVD exmple Oservtion A = 120 100 120 100 10 10 10 10 0 0 70 80 10 120 10 10 U = 0.709-0.772-0.32 0.1009 0.01-0.000-0.139-0.987 0.300 0.7121-0.98 0.1113 0.709 0.18 0.2-0.01 S = 38.1 0 0 0 0 20.1 0 0 0 0 7.82 0 0 0 0 0.9919 V = 0.209-0.19 0.00-0.3137 0.338-0.1330-0.71-0.873 0.300-0.17-0.188 0.8081 0.09 0.829 0.217-0.109 First eigen vlue is signifintly lrger thn the rest The ontriution from the rnk-1 sum is very signifint ompre to the sum of ll other rnk pproximtions. So even if you leve out ll other rnk sums, you still get pretty goo pproximtion with just two vetors. 12

Some smples (128x128) Smples ont Originl mge 9K Rnk 1 pprox 311 ytes Rnk 1 pprox 13K Rnk 8 pprox 7K Some size oservtions Note tht theoretilly the sizes of the ompresse imges shoul e Rnk 1 = + (128 + 128 + 1)*3 Bmp Heer U 1 V 1 + S 1 ytes/pixel Rnk 8 = + (128+128+1)*3*8 = K Rnk 1 = + (128 + 128 + 1)*3*1 = 12K Rnk 32 = + (128 + 128 + 1)*3*32 = 2K Rnk = 8K (pretty lose to the originl) Mtl Coe for SVD Mtl is omputer lger system (www.mthworks.om) Here is Mtl oe tht n perform SVD on n imge. A=imre(':\temp\rhino','mp'); N = size(a)[1]; R = A(:,:,1); // extrt Re mtrix G = A(:,:,2); // extrt Green Mtrix B = A(:,:,3); // extrt lue mtrix Apply SVD to eh of the mtries [ur,sr,vr]=sv(oule(r)); [ug,sg,vg]=sv(oule(g)); [u,s,v]=sv(oule(b)); Complete Mtl Coe for SVD t.. Mtl outputs A=imre(':\temp\rosemry','mp'); s=size(a) %imges(a) R = A(:,:,1); G = A(:,:,2); B = A(:,:,3); [ur,sr,vr]=sv(oule(r)); [ug,sg,vg]=sv(oule(g)); [u,s,v]=sv(oule(b)); %initilize mtries to zero mtries Rk=zeros(s(1),s(2)); Gk=zeros(s(1),s(2)); Bk=zeros(s(1),s(2)); k = 8; % k is the esire rnk % form the rnk sums for i=1:k, Rk=Rk + sr(i,i)*ur(:,i)*trnspose(vr(:,i)); en for i=1:k, Gk=Gk + sg(i,i)*ug(:,i)*trnspose(vg(:,i)); en for i=1:k, Bk=Bk + s(i,i)*u(:,i)*trnspose(v(:,i)); en % Now form the rnk-k pproximtion of A Ak = A; Ak(:,:,1)=Rk; Ak(:,:,2)=Gk; Ak(:,:,3)=Bk; % now plot the rnk-k pproximtion of imge imges(ak) originl originl Rnk-1 Rnk-1 Rnk- Rnk- Rnk-8 Rnk-8 Originl imges were pproximtely 128x128 13

Aptive rnk methos All populr imge ompression progrms pply ompression lgorithm to suloks of the imge This exploits the uneven hrteristis of the originl imge If prts of the imge re less omplex thn the others, then smller numer of singulr vlues re neee to otin "lose" pproximtion Aptive Rnk Methos t.. So inste of piking sme rnk for eh su-lok, we eie how mny singulr vlues to pik from eh su-lok y looking t the following: Perent of r vlues = s 1 + s 2 +.+ s r s 1 + s 2 +.+ s k Where k is the mx numer of non zero singulr vlues of A. Results of Aptive Rnking Metho We pplie the ptive rnking metho to Dnny Sletor. Here re the results. Originl 9K 80% of singulr vlues 2K 0% of singulr vlues 1K 10% of singulr vlues 1K 1