mobile communications › ... › mc19_lecture11_images_3apr.pdf · • even-length coding just...

49
Lecture 11 COMP61242 1 Mobile Communications Mobile Communications Lecture 11 Lecture 11 – 1/04/19 1/04/19 Image coding Image coding COMP61242 Barry Cheetham

Upload: others

Post on 04-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 1

Mobile CommunicationsMobile CommunicationsLecture 11 Lecture 11 –– 1/04/191/04/19

Image codingImage coding

COMP61242Barry Cheetham

Page 2: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 2

•Typical smartphone screen: 1280x720 = 921600 pixels(HD)(same as HDTV)

camera: 12 Mpixels (12 x HD)‘selfie’ : 12 Mp with 3 byes per RGB pixelSize 36 Mbytes if uncompressed (raw)

• Camera settings: FHD (1920x1080), HD (1280x720), VGA (640x480)• Movies & Video Clips:

– For HD quality video & 25 frames per second– Might need 1280 x 720 3 x 25 69 Mbytes/second– That is 41 Gbytes for a 20 minute video clip– That is 497 Gbytes for a 2 hour movie– Rather a lot!.

•Compression is needed!

Images & videoImages & video

Page 3: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 3

PhysiologyPhysiology

• Human eye assumed to have 3 colour sensors: red, green & blue

• Cannot resolve more than 8 bits per colourso 38 = 24 bits/pixel is acceptable

• Can represent coloured image by 3 components: RGB • Or by a luminance (monochrome) component & two

chrominance (colour) components.• Human eye less sensitive to chrominance than luminance.• Also relatively insensitive to rapidly changing (higher

frequency) fine-detailed aspects of the image.

Page 4: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 4

FrequencyFrequency--domain processingdomain processing

• Allows mobile device to take physiological features into account when digitising images.

• Avoids encoding what the eye will not see by:– transforming the image into freq-domain– efficiently encoding only the features that will be

perceived– reversing the transform at the receiver

• As with MP3, Discrete Cosine Transform is used• But it must be a 2-dimensional DCT.

Page 5: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 5

Discrete Cosine Transform (DCT)Discrete Cosine Transform (DCT)

• Given {x[n]}0,N-1 its ‘1-D’ DCT is:

1

0/ where

212cos][ ][

N

nkk NknnxkDCT

MmNknmnxkDCTN

k

M

/2

12cos/2

12cos],[],[1

0

1

0

• Given {x[n.m]}0,N-1, 0,M-1 its ‘2-D’ DCT is:

• Low values of k & ℓ correspond to slowly changing features.

• Higher values correspond to fine detail. dct(dct(…))

Page 6: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 6

Some imagesSome images

Page 7: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 7

More imagesMore images

• Find these in course web-site

• All are bit-map (.bmp) not jpg

Page 8: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 8

Red, green & blueRed, green & blue• ‘Peppers.bmp’ image may be read from res/raw folder into an Android app by:

int res_id=getResources().getIdentifier(“Peppers.bmp”, "raw", getPackageName() );InputStream image_is = getResources().openRawResource(res_id);int filesize = image_is.available(); //Get image file size in bytesbyte[ ] image_array = new byte[filesize]; // Array to hold imageimage_is.read(image_array); image_is.close();// Creates a 512 x 512 x 3 matrix of unsigned 8-bit integers.// See Task 3 to display coloured image on smartphone screen

• Can separate image array into 512x512 red, green & blue matrices R, G & B• For processing it is often best to convert these to a:

– luminance matrix Y– chrominance (colour) matrix I – chrominance (colour) matrix Q

Page 9: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 9

Converting from RGB to YIQ (NTSC)Converting from RGB to YIQ (NTSC)• Could have Y = 0.33R + 0.33G + 0.33B

CR = R – Y (‘Red difference’ chrominance)CG = Y – G (‘Green difference’ chrominance)

Then: CR = 0.66R – 0.33G – 0.33Band: CG = 0.33R – 0.66G + 0.33B

• Instead: Y = 0.3*R + 0.59*G + 0.11*BI = 0.6*R – 0.28*G – 0*32*B

Q = 0.21*R – 0.52*G + 0.31*B

(PAL & SECAM use different numbers but similar idea).

Page 10: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 10

In matrix formIn matrix form

BGR

QIY

31.052.021.032.028.06.0

11.059.03.0

To convert from YIQ back to RGB form, invert the matrix:

QIY

BGR

73.11.1164.028.01

62.095.01

Page 11: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 11

Demo: Demo: ‘‘bigDCT2bigDCT2’’ methodmethod

• Apply DCT2 to Y, I & Q• Huge matrices, but DCT2 is efficient (like fft)• Run ‘Lecture4imageBigDCT2.m’ & observe the graphs.• Own versions of dct2 & idct2 provided.

Page 12: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 12

peppers.bmppeppers.bmp

50 100 150 200 250 300 350 400 450 500

50

100

150

200

250

300

350

400

450

500

Page 13: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 13

Luminance (Y)Luminance (Y)Luminance (Y)

100 200 300 400 500

50

100

150

200

250

300

350

400

450

5000

50

100

150

200

250

Page 14: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 14

I & Q I & Q chominancechominance

Chrominance (I+128) in range [0 255]

100 200 300 400 500

50

100

150

200

250

300

350

400

450

5000

50

100

150

200

250Chrominance (Q) in range [0 255]

100 200 300 400 500

50

100

150

200

250

300

350

400

450

5000

50

100

150

200

250

Page 15: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 15

DCT2 Luminance spectrum (DCT2 Luminance spectrum (linlin scale)scale)

Page 16: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 16

CommentComment

• Observe how energy is concentrated a the lower frequencies.

• In fact there seems little energy at higher frequencies in either direction.

• Look at the spectrum on a log scale with colour representing amplitude.

Page 17: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 17

Luminance DCT2 spectrum (logLuminance DCT2 spectrum (log--scale)scale)Original DCT2 spec trum of lum inance (Y ) on log scale

100 200 300 400 500

50

100

150

200

250

300

350

400

450

500-15

-10

-5

0

5

Page 18: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 18

Set small amplitudes to zeroSet small amplitudes to zero

Page 19: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 19

Resulting luminanceResulting luminance

Page 20: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 20

Do the same for I & QDo the same for I & Q

Page 21: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 21

Comments on demoComments on demo• Coloured picture converted to Y, I & Q.• Take DCT2 of each & plot mag-spectrum.• Notice concentration of energy in top corner.• Set to zero any values < some threshold.• Creates lots of zeros.• Go back to an image via an inverse DCT2.• Can see reconstructed image

& its modified spectrum (with lots of blue).• Any perceivable loss of quality?

Page 22: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 22

Data reductionData reduction

• Number of non-zero coeffs for Y reduced from 262,000 to 8,692.

• About 3% are left• All the rest are now zero.• Similar for I & Q ??• Send only the non-zero values - quite a reduction!• Coding the non-zero values is hard – where do they occur?• Image compression is not done like this.• Let’s see how JPEG does it:

Page 23: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 23

Whole image DCTWhole image DCT• Not such a good idea• DCT processing smears out local detail & can be costly in

terms of memory & hardware• Distortion from one part of image will affect other parts.• Applying DCT processing to whole sound file also not good.• So we split the image into 8 by 8 pixel tiles.• Some modern coders are now using 16x16 pixel tiles• Whole image DCT seems to work with less detailed images.• JPEG 2000 used wavelets on whole image but not

computationally efficient.

Page 24: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 24

• Assume image is 640x480 RGB pixels.• Convert each RGB pixel to:

– a measure of luminance (Y) plus – two chrominance measurements (I,Q or U,V).– then we have three 640x480 byte-matrices Y, I & Q

• Reduce I & Q to 320x240 by averaging 2x2 blocks.• Consider Y,I & Q divided into 8-bit ‘tiles’ (4800 or 1200)

JPEG image compression: Step 1JPEG image compression: Step 1

Page 25: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 25

JPEG compression: Step 2JPEG compression: Step 2• Use 2D Discrete Cosine Transform (DCT2) • Apply it to each 88 tile of Y, I & Q• Get 2 frequency axes: Fx & Fy

– often shown with (0,0) in top corner rather than bottom corner• High-frequency components usually small.

(0,0) (0,0)

One 8x8 tile before DCT2 Result of DCT2 for 1 tile

Page 26: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 26

• Quantize DCT coeffs using quantisation table below.• Divide each coeff by table entry, then round to integer.• Controls number of bits per coeff needed accuracy

JPEG image compression: Step 3JPEG image compression: Step 3

Page 27: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 27

QuantisationQuantisation• Encoder integer divides DCT coeffs by 2n to ‘lose’ n bits.

• 21 4 = 5 (rem 1 discarded)• 10101 101• At decoder:• 5 x 4 = 20• 10100• ‘Quantisation error’ incurred – a ‘lossy’ process.

Page 28: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 28

• Bottom corner DCT component of each 8x8 tile has both frequencies zero.

• Sorry – it’s the top corner in some graphs• Represents average value of tile.• Also known as the ‘DC-DC component’• Changes slowly from tile to tile. • Differences often small but very noticeable• Encode differences in DC-DC components between tiles• Uniform luminance area then has all zero differences.

JPEG image compression: Step 4JPEG image compression: Step 4

Page 29: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 29

JPEG image compression: Step 5JPEG image compression: Step 5

• ‘zig-zag’ scan to read out coeffs

• Count the number of successive zeros

• Here there are 38.

• Record ’38’ as ‘run length code.

Page 30: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 30

•A run length encoding method:– (Z0, N0), (Z1, N1), (Z2, N2), (Z3, N3), …

Zi: number of consecutive zerosNi: next non-zero number

•Example•0 0 0 0 0 2 3 0 0 0 0 0 0 0 0 1•(5,2), (0,3), (8,1)

•Real JPEG employs lots of tricks here.

Step 5 (continued)Step 5 (continued)

Page 31: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 31

• Apply Huffman encoding to the quantised numbers.• Assume there are just four of these: A, B, C, D • Even-length coding just allocates a 2-bit integer to each.• Use ’00’ for A, ’01’ for B, ’10’ for C & ’11’ for D.• Can do better than this using variable length coding.• Huffman codes use fewer bits for common numbers &

more bits for less common numbers.• A bit like ‘Morse code’, but codes are ‘self-terminating’.• Always know when each Huffman code-word ends. • Can use a default Huffman coding look-up table.• Or we can generate our own ‘image specific’ table. • Latter incurs overhead but may save bits overall.

JPEG image compression: Step 6JPEG image compression: Step 6

Page 32: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 32

Huffman coding 1Huffman coding 1• Given 4 numbers: A, B, C, D occurring with frequency• 5 %, 25%, 10% & 60 % respectively: • Probabilities are: 0.05, 0.25, 0.1, 0.6

D: 0.6

B: 0.25

C: 0.1

A: 0.050.15

0.41

• Arrange in decreasing order of probabilities • Then link the two with lowest probability. • Add probs & repeat. Sometimes ordering changes.

Page 33: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 33

Huffman coding 2Huffman coding 2• Label corners 0 or 1 as shown below:

C: 0.6

B: 0.25

C: 0.1

A: 0.050.25

0.61

0

1

0

1

0

1

Page 34: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 34

Huffman coding 3Huffman coding 3

• Read backwards from end of tree to each of A, B, C & D

D: 0.6

B: 0.25

C: 0.1

A: 0.050.15

0.41

0

1

0

1

0

1

D: 0 B: 10 C: 110 A: 111

Page 35: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 35

Huffman coding resultHuffman coding resultA 111B 10C 110D 0

• Self terminating & more efficient than:A 00B 01C 10D: 11

for the given probabilities.

• But a little more difficult to decode.

Page 36: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 36

What is saving for this example?What is saving for this example?• For 100 symbols, we need 200 bits with fixed (even)

length coding.• With the Huffman coding for previous sample we need:

5 x 3 (for A) + 25 x 2 (for B)+ 10 x 3 (for C)+ 60 x 1 (for D)

• That is 15 + 50 + 30 + 60 = 155 bits• So we save 45 bits out of every 200.• A saving of 22.5 %.

Page 37: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 37

DecodingDecoding• With this Huffman coding example, assume we receive:

10001100111• This represents: 10, 0, 0, 110, 0, 111

B D D C D A • If there is a bit-error in the 3rd bit, we receive:

10101100111• This represents: 10, 10, 110, 0, 111

B B C D A• Second coeff (B) is wrong and the rest are out of sync.

A: 111B: 10C:110D: 0

Page 38: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 38

Another exampleAnother example

D: 0.6

B: 0.13

C: 0.12

A: 0.1

0.15

0.4

E: 0.05

0.25

1

0

1

0

1

0

10

1

A: 110; B: 100; C: 101; D: 0; E: 111

• Five coeffs A,B,C,D,E with frequencies 10%,13%,12%,60%, 5% :

Page 39: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 39

BitBit--saving for this examplesaving for this example

•With 5 coeffs & fixed (even) length coding, need 3 bits per coeff.•For 100 coeffs, need 300 bits.•With Huffman coding, we only need:

10 x 3 (for A) + 13 x 3 (for B)+ 12 x 3 (for C)+ 60 x 1 (for D) + 5 x 3 (for E)

• That is: 30+39+36+60x 15 = 180 bits• So we save 120 bits out of every 300•A bit-saving of 40%

Page 40: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 40

Disadvantage of Huffman codingDisadvantage of Huffman coding• Huffman coding is used for both image compression & mp3

music encoding.• It is highly efficient & lossless • Other aspects of mp3, JPEG & MPEG make them ‘lossy’.• Disadvantage of Huffman is its sensitivity to bit-errors.• Due to its variable length & self terminating code-words.• If one code-word has a bit-error it may be mis-interpreted as

part of a longer or shorter code-word.• On previous slide 010110100…encodes A4 A3 A3 A4,A4…• If first 0 1, we get 110110100 which is A1 A1 A4 A2 …• Many symbols after the bit-error may be affected.• Whole mp3 or JPEG file may be unusable.• Many ‘tricks’ for avoiding this problm, eg frame restart flags

Page 41: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 41

JPEG image compression: SummaryJPEG image compression: Summary

step 1 step 3step 2 step 5step 4 step 6

Huffman

Page 42: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 42

Demonstration softwareDemonstration software• Course web-site has the following progs:

– AMmages.html & some matlab progs• Also a selection of image files.• Encoder implements steps 1-3 .• Decoder reads the data & reconstructs the image.• No run-length coding has been implemented yet.• No Huffman coding yet.• Other aspects are shown to work.

Page 43: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 43

• Films have 24 frames/second displayed for (1/24) s.• TVs used to display 25 frames/s with each image

scanned from top to bottom.• Scan ‘interleaved’ to increase update rate to 50 frames/s

– even & odd lines updated in alternate frames• Computers/ smartphones display image at 60+ frames/s

– ‘progressive scan’

Displaying moving pictures

Page 44: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 44

Digitally encoding moving picturesDigitally encoding moving pictures

• Encoding each frame as JPEG would be inefficient• Would not exploit temporal redundancy due to similarity

of each frame to those before & after.• Could we send differences between complete frames?

– OK for static scenes– Not so efficient where frames ‘pan’ from side to side or ‘zoom’

• Best to use ‘motion compensation’– Find similarity between parts of images in successive frames– send motion information where similarity is strong– then encode any remaining differences as JPEG– (when parts of images are similar, they are ‘correlated’)

Page 45: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 45

Motion compensationMotion compensation• Consider three consecutive frames• Notice similarity of the figure walking towards the tree.• Search for matching block in consecutive frames.• Encode the movement & remaining differences.• MPEG standard does not specify search algorithm

Page 46: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 46

MPEG video compressionMPEG video compression

• Encode each frame as an ‘I-frame’, ‘P-frame’ or ‘B-frame’.

• I-frame is an Image encoded as JPEG• P-frame encodes positions of moving blocks predicted

from Previous I & P frames, & remaining differences.• B-frame encodes positions of moving blocks estimated from

Both previous & next I & P frames, & remaining differences.

Page 47: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 47

MPEG video with audioMPEG video with audioSynchronization of the audio & video streams in MPEG-1.

Page 48: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 48

SummarySummary• Uncompressed images use a lot of data• Moving images (video) even more so• Compression can save memory, & comms bandwidth• Also saves download time & cost of storage media.• JPEG compresses images by ~10x• MPEG compresses video by ~100x• In both cases, compression is ‘lossy’. Not like ‘zip’.• Perceived loss of quality is small, but not zero.• Built-in quality/compression trade-off

– in choice of coefficient quantization matrix– other steps are largely lossless

• Sensitivity to bit-errors increased because of HC

Page 49: Mobile Communications › ... › MC19_Lecture11_Images_3Apr.pdf · • Even-length coding just allocates a 2-bit integer to each. • Use ’00’ for A, ’01’ for B, ’10’

Lecture 11 COMP61242 49

Extra problemExtra problem

• Symbols A,B,C,D E,F,G have probabilities:• 0.12, 0.13, 0.07, 0.07, 0.1, 0.36, 0.15• Devise a Huffman code for these symbols & probabilities.• Consider how it would be decoded.• Compare it with equal length coding. • Estimate the percentage bit-saving that may be expected

over a large number of DCT samples with the given probabilities, by using this Huffman code rather than equal length (or fixed length) coding.