영상 압축과 jpeg 표준 - kocwelearning.kocw.net/contents4/document/lec/2012/seoultech/... ·...

25
/ MPEG 동영상압축 표준 / 멀티미디어 시스템 소개 / 영상 압축과 JPEG 영상 압축 표준

Upload: others

Post on 19-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

/ MPEG 동영상압축 표준

/ 멀티미디어 시스템 소개

/ 영상 압축과 JPEG 영상 압축 표준

Page 2: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

1. A Typical Data Compression System

01 데이터 압축 알고리즘

Compression ratio = Original data / Compressed data

Two types of compression

Lossless compression

Lossy compression

Encoder Decoder Input Data

Stream

Data

Storage or

Transmission

Output Data

Stream

11112220044444 41322054 e.g.

3-bit data

2-bit data

0 1 2 3 4 5 6 7

0 0 1 1 2 2 3 3

e.g.

Page 3: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

2. Run Length Encoding(RLE)

01 데이터 압축 알고리즘

Utilizes repetitiveness of data run

How to represent a run ?

By count and original data

반복되는 자료에만 RLE를 사용하고, run을 나타내기 위해 특수 문자를 prefix 함

ABCDDDDDDDDEEEEEEEE ABC+8D+9E

AAAABBBBBCCCCCCCCDEEEE

4A5B8C1D4E(compression ratio = 22/10 = 2.2)

MyDogHasFleas

1M1y1D1o1g1H1a1s1F1l1e1a1s(comp. ratio = 13/26 = 0.5)

이 특수 문자가 원 자료에 나온다면 길이 1의 run으로

encoding함( +1+) e.g.

Page 4: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

2. Run Length Encoding(RLE)

01 데이터 압축 알고리즘

Good for images with solid backgrounds like binary cartoon images.

text file이나 photo image에는 효율이 떨어짐

Huffman Coding

빈번히 발생하는 자료 적은 수의 bits

드물게 발생하는 자료 많은 수의 bits를 할당하는

가변 길이 coding

Page 5: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

3. Huffman Coding

01 데이터 압축 알고리즘

David A. Huffman, 1952

Variable length code whose length is inversely proportional

to that character’s frequency

문자들의 발생 빈도가 다를 경우,

발생 빈도가 높은 문자에 적은 수의 bits를,

빈도 수가 적은 문자에 많은 수의 bits를 할당함

T O U P E E

111 0100 10111 10110 100 100

48 bits 23 bits

Page 6: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

3. Huffman Coding

01 데이터 압축 알고리즘

[1장에서 발생된 영문자에 대한 허프만 코드]

영문자 빈도수(%) 코드 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

8.23 1.26 4.04 3.40

12.32 2.28 2.77 3.94 8.08 0.14 0.43 3.79 3.06 6.81 7.59 2.58 0.14 6.67 7.64 8.37 2.43 0.97 1.07 0.29 1.46 0.09

0000 110000 1101 01011 100 11001 10101 00100 0001 110001001 1100011 00101 10100 0110 0100 10110 1100010000 0111 0011 111 10111 0101001 0101000 11000101 010101 1100010001

A I O N R D

Y V W

H L

S

E

M G P U

T C

F

K X

J

B

Z Q

0 1

[그림9.4] 영문자의 이짂 트리

Page 7: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

4. Algorithm for Huffman Coding

01 데이터 압축 알고리즘

1st pass : Accumulate the character frequency and generate codebook.

2nd pass : Do compression with the codebook.

Creating codes by constructing a binary tree

4

Consider all characters as free nodes.

Assign two free nodes with lowest frequency to a parent nodes

with weights equal to sum of their frequencies.

Remove the two free nodes and add the newly created

parent node to the list of free nodes.

Repeat step2 and 3 until there is one free node left .

It becomes the root of tree.

3

2

1

Page 8: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

4. Algorithm for Huffman Coding

01 데이터 압축 알고리즘

Example

R K K K K K K K

K K K R R K K K

K K R R R R G G

K K B C C C R R

G G G M C B R R

B B B M Y B B R

G G G G G G G R

G R R R R G R R

[그림9.5] 일곱 가지색에 의한 8×8 샘플 영상

Page 9: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

4. Algorithm for Huffman Coding

01 데이터 압축 알고리즘

19 17 16 S 4 2 1 R K G B C M Y

19 17 16 5 4 R K G B C

19 17 16 5 R K G B

19 17 16 R K G

Y M

3 2

3

4

1

C

7

Y M

C

12

Y M

B

6

K R

36

G

28

Y M

B C

7 K R G

C B

Y M

19 17 R K

5 G

28

Y M

B C

Page 10: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

4. Algorithm for Huffman Coding

01 데이터 압축 알고리즘

색상 빈도수

빨강색

검정색

녹색

파란색

남색

자홍색

노랑색

19

17

14

7

4

2

1

색상 코드

빨강색

검정색

녹색

파란색

남색

자홍색

노랑색

00

01

10

111

1100

11010

11011

[그림9.5] 그림9.5에 관한 빈도수 표

[그림9.5] 그림9.5에 관한 허프만 코드

Page 11: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

5. Modified Huffman Coding

01 데이터 압축 알고리즘

Difficulties in Huffman Coding

Variable length code의 유지 관리가 어려움

Encoding에 두 단계가 필요함

수정된 Huffman coding에서는 고정된 codebook을

사용하여 문자 출현 빈도 수를 계산하는 과정을 생략함

Modified Huffman Coding

Used in fax transmissions

Uses one fixed table, and combines variable

length encoding and run length encoding.

Page 12: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

1. JPEG (Joint Photographic Experts Group)

02 JPEG 영상 압축 표준

Still image compression standard

Can achieve compression ratios of up to 20 to 1 without noticeable reduction in image quality.

Works well for continuous tone images:

photographic or real-world images

Not good for

Cartoons and computer generated images

Binary (black/white) images

High quality medical images

Page 13: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

2. RGB color model

02 JPEG 영상 압축 표준

영상 입출력 장치에 직접 이용되는 색 좌표계

Red, Green, Blue를 이용한 색 표현

white

red

green blue

yellow magenta

cyan

black

Page 14: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

3. YCbC r Color Model

02 JPEG 영상 압축 표준

색상(chromaticity) 정보와 명도(luminance) 정보를 분리하는 color model

Y : 광도, Cb : 푸른 정도, C r : 붉은 정도

RGB YCbCr

Y = 0.29900 · R + 0.58700 · G + 0.11400 · B

Cb = -0.16874 · R - 0.33126 · G + 0.5000 · B

C r = 0.50000 · R - 0.41869 · G - 0.08131 · B

YCbCr RGB

R = 1.00000 · Y + 1.40200 · C r

G = 1.00000 · Y - 0.34414 · Cb - 0.71414 · C r

B = 1.00000 · Y + 1.77200 · Cb

Page 15: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

4. Luminance/Chrominance Color Space

02 JPEG 영상 압축 표준

RGB color space YCbC r color space

Human visual system은 명암보다 색상 차에 둔감하므로 chrominance components에서 다수의 정보를 제거함으로써 압축률을 높이고자 함

Page 16: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

5. 6 steps of baseline JPEG encoding

02 JPEG 영상 압축 표준

Transform image to luminance/chrominance space (YCbCr).

Reduce the color components (optional). Reducing color resolution

Partition image into 8x8 pixel blocks and subtract 128 from each value.

Perform DCT(Discrete Cosine Transform) on each block.

Quantize resulting DCT coefficients.

Entropy encode the quantized coefficients (modified Huffman coding).

2

1

4

3

6

5

Page 17: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

6. JPEG encoder

02 JPEG 영상 압축 표준

FDCT Quantizer Entropy encoder

Table specifications

Table specifications

8×8 blocks

Source image data

Compressed image data

TISO0680-93/d004

[DCT-based encoder simplified diagram]

DCT-based encoder

Page 18: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

6. JPEG encoder

02 JPEG 영상 압축 표준

Entropy decoder

Dequantizer IDCT

Table specifications

Table specifications

8×8 blocks

Compressed image data

Reconstructed image data

TISO0700-93/d006

[DCT-based decoder simplified diagram]

DCT-based decoder

Page 19: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

7. Discrete Cosine Transform(DCT)

02 JPEG 영상 압축 표준

DCT can be defined for any rectangular array of pixels, but in image compression the basic block is generally an 8 × 8 array, or 64 pixels.

DC component

AC components

measure of the average value of the 64 image samples

DC coefficients

Page 20: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

7. Discrete Cosine Transform(DCT)

02 JPEG 영상 압축 표준

Forward Transform

16

)12(cos

16

)12(cos )(

4

1)(

7

0

7

0

vyuxy,xfCCv,uF

x y

vu

u, v = 0, 1, …, 7

Inverse Transform

16

)12(cos

16

)12(cos )(

4

1)(

7

0

7

0

vyuxv,uFCCy,xf

u v

vu

x, y = 0, 1, …, 7 otherwise 1 ,0for

2

1 uu CuC

otherwise 1 ,0for 2

1 vv CvC

Page 21: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

8. DCT Coefficients

02 JPEG 영상 압축 표준

Study of the human visual system (HVS) reveals some important results for compression with DCT:

When a block of pixels from a continuous-tone image is

transformed, many of the DCT coefficients have values

close to 0.

The HVS is fairly sensitive to small errors in DC and

low-frequency coefficients, but much less sensitive to

amplitude errors in higher-frequency coefficients.

The HVS is quite insensitive to errors in these coefficients;

values close to 0 may be set to 0 with very little effect on

image quality.

Page 22: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

9. Quantization

02 JPEG 영상 압축 표준

각 image block의 DCT 계수들을 quantize함

이 단계에서 많은 DCT 계수들을 0으로 만들어서 압축률 상승에 크게 기여함

필연적으로 정보의 소실 발생

Quantization Table

[luminance table] [chrominance table]

Page 23: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

10. Quantization of cu,v

02 JPEG 영상 압축 표준

Quantized coefficient Cu,v (u, v = 0, 1, …, 7)

50 2 .Q

cfloor

Q

Qc

floorCv,u

v,u

v,u

v,u

v,u

v,u

DCT concentrates energy into the “top left” coefficients (DC components).

Then the quantized coefficients from a block are arranged and grouped to form descriptors.

Page 24: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

11. Encoding Example

02 JPEG 영상 압축 표준

[Quantized] [The DCT is performed.]

[Subtract 128 from each value] [Input image]

Page 25: 영상 압축과 JPEG 표준 - KOCWelearning.kocw.net/contents4/document/lec/2012/SeoulTech/... · 2013-07-09 · Creating codes by constructing a binary tree 4 Consider all characters

12. Zigzag Scanning

02 JPEG 영상 압축 표준

DCT concentrates energy into the “top left” coefficients (DC components).

The probability of a coefficient’s being nonzero is much higher in the top left than at the bottom right.

It follows the diagonal zigzag pattern.