Docsity

Vector Quantization - Lecture Slides | COMP 665, Study notes of Computer Science

Partial preview of the text

Download Vector Quantization - Lecture Slides | COMP 665 and more Study notes Computer Science in PDF only on Docsity!

Vector Quan,za,on

I will post PS 3 tonight

Quan,za,on

  • Talked about scalar quan6za6on last 6me
  • Idea was to map allowed inputs to a smaller

set of quan6zed outputs

  • Can easily be implemented via a table
  • Since the output takes

only 2 values, we could

encode it with fewer bits,

and use separate tables for

encoding and decoding

INPUT OUTPUT 0 64 1 64 127 64 128 192 254 192 255 192

Quan,za,on Errors

  • Closeness of a quan6zed variable to the original
    • Squared difference, , emphasizes large errors
    • Absolute difference, , nonlinear, hard to op6mize
  • Image‐wide metrics
    • Mean‐Squared Error, MSE
    • Mean‐Absolute Error, MAE
    • Signal‐to‐Noise Ra6o, SNR
    • Peak Signal‐to‐Noise Ra6o, PSNR SNR = 1 MN v ij j = 1
N

∑ i = 1

M

∑ MSE € MSE = 1 MN v ij − v ˆ ( (^) ij )

j = 1

N

∑ i = 1

M

∑ € ( v − v ˆ ) 2 € v − v ˆ € MAE = 1 MN v (^) ij − v ˆ (^) ij j = 1

N

∑ i = 1

M

∑

Codebook Quan,za,on

  • Replacing the table‐based encoder with a

metric look‐up

Encoder

Value Code 64 A 192 B

Decoder

INPUT Code A 64 B 192

Channel

Find Closest value

in Codebook

The fundamental difference of this encoding

architecture is that on each input, we search a

“codebook” for the closest representative, and

use its associated code. Generalizes to

continuous inputs.

inputs

€ v

outputs

€ v^ ˆ

Vector vs Scalar Quan,za,on

The applica6on of quan6za6on is not limited to scalar variables, it is ocen applied to vector variables, where it is called Vector Quan6za6on or VQ. Advantage of VQ over SQ:

  • If vector components are correlated, vectors will tend to fall in clusters, and will map to a common code.
  • Even without correla6on, it provides more flexibility to deal with differences in the mean and variance of vector components
  • Generally, has lower noise than scalar quan6za6on

Generalizing to Vectors

  • It is trivial to modify our encoder‐decoder

architecture to handle VQ

Encoder

Value Code 192,80,80 A 80,16,64 B 208,96,96 C 176,64,80 D

Decoder

INPUT Code A 192,80, B 80,16, C 208,96, D 176,64,

Channel

Find Closest value

in Codebook

<r,g,b>

<r,g,b>

Let’s use choosing an image palette for an

indexed image as a example. This real-

world problem occurs when images are

stored in GIF format.

Standard PaleCe Example

  • A 64‐entry code book with independent quan6za6on levels for each primary (happens to be iden6cal to SQ with 2‐bits per primary or 6‐bits/pixel)
  • A 6x6x6=216 entry paleae is used by many for GIFs Original (^) Standard MAE = 30. Original (^) Standard MAE = 30.

Implementa,on

def encode(vector, codebook): dist = sys.maxint index = - for j in xrange(len(codebook)): d = 0 code = codebook[j] for i in xrange(len(vector)): d += (vector[i] - code[i])** if (d < dist): dist = d index = j return index def mse(a, b): d = 0 for i in xrange(len(a)): d += (a[i] - b[i])** return sqrt(d) Two key routines

  1. Search the codebook for the closest vector
  2. Compute error

Most Popular K Colors

  • Each component is first scalar‐quan6zed to 16

levels (giving 161616 = 4096 possible colors)

  • Choose the K = 64 most popular of these as

the codebook

Original (^) Most Popular 64, 12-bit Colors MAE = 15. Original (^) Most Popular 64, 12-bit Colors MAE = 9.

Can we do BeCer?

  • Exploit the image sta6s6cs to reduce the

errors further

  • As we saw earlier and exhaus6ve search for

the global op6mum in intractable

  • Itera6ve refinement towards a local op6mum

can be posed as a greedy op6miza6on

algorithm

  • Linde, Buzo, and Gray (convergence to mean)
Codewords in a 2-dimensional space. Input vectors are marked with an x,
codewords are marked with red circles, and the Voronoi regions are
separated with boundary lines. Closely related to K-means clustering.

Voronoi Cell Analogy

LBG Caveats

  • LBG is a greedy algorithm, falls into local minimums.
  • Selec6ng ini6al vectors:
    • Popularity (what I used)
    • Random
    • Splimng distribu6on
      • At mean along vector component with greatest variance / range
      • Along PCA vectors
  • Empty cell problem:
    • No input correspond to a output vector
    • Solu6on: give to other clusters, e.g. most populate cluster.

Block‐based VQ

  • There is no reason to limit our vectors to 3 dimensions.
  • Let’s consider each 2x2 block of pixels as a 12‐dimensional vector 192,80,80 80,16, 208,96,96 176,64, € 192 80 80 80 16 64 208 96 96 176 64 80                                    

LBG for image compression

  • Taking blocks of images as vector L=NM.
  • If K vectors in code book:
    • need to use bits.
    • Bits per Pixel :
  • The higher the value K , the beaer quality, but lower compression ra6o.
  • Must consider overhead to transmit code book ( a standard code book is unlikely in this case):

Block / K 64 256 1024

2x2 4364 43256 43

4x4 16364 163256 163

8x8 64364 643256 643