Docsity

Image Processing Machine Problem 2: Implementing DPCM and Block Transform Coding with KLT , Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE547 Image Processing Sept 11, 2008
Machine Problem 2 (ver. 1.1)
Lecturer: Prof. Thomas Huang Due: Sept 25, 2008
1 Introduction
In this machine problem you are asked to write a MATLAB program which will implement two
form of image coding, differential pulse code modulation (DPCM) and block transform coding with
Karhunen L`oeve Transform (KLT).
2 Description
There are three main sections to the MP, which will be written in MATALB. The first is to build
a Lloyd-Max quantizer, which you will use for the other two parts. The second part will be to
implement a DPCM encoder and decoded. Finally, you will also build a block transform encoder
and deocder.
2.1 Lloyd-Max Quantizer
The first matlab function must have the name lloydmax with the following definition:
function [x, y] = lloydmax(pts, levels)
The input pts is the set of points we want to quantize, and levels is the number of levels we
want to quantize to. The output xis a (levels+1)-vector of decision boundaries, and yis a
levels-vector of quantized values.
The output of the quantizer must satisfy
xi=yi−1+yi
2∀i∈ {2, . . . , levels}(1)
yi=Rxi+1
xixp(x)dx
Rxi+1
xip(x)dx ∀i∈ {1, . . . , levels}(2)
Where x1is smaller than the smallest value of pts, and xlevels+1 is larger than the largest value
of pts. The function p(x) is the number of points in pts that is equal to x1. The interpretation of
the result is that values between xiand xi+1 should be quantized to yi.
One way to implement this function is to start with equally spaced values of xi, and then
compute the values of yi. Then, use the new values of yito update xiand iterate until convergence.
You may have to do some fix-up if you get into a case where a bin is empty.
1In general, p(x) should be a normalized histogram over distribution of pts, but in our case, we will use a discrete
set of points.
MP2-1
pf3
pf4

Partial preview of the text

Download Image Processing Machine Problem 2: Implementing DPCM and Block Transform Coding with KLT and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

ECE547 Image Processing Sept 11, 2008

Machine Problem 2 (ver. 1.1)

Lecturer: Prof. Thomas Huang Due: Sept 25, 2008

1 Introduction

In this machine problem you are asked to write a MATLAB program which will implement two form of image coding, differential pulse code modulation (DPCM) and block transform coding with Karhunen L`oeve Transform (KLT).

2 Description

There are three main sections to the MP, which will be written in MATALB. The first is to build a Lloyd-Max quantizer, which you will use for the other two parts. The second part will be to implement a DPCM encoder and decoded. Finally, you will also build a block transform encoder and deocder.

2.1 Lloyd-Max Quantizer

The first matlab function must have the name lloydmax with the following definition:

function [x, y] = lloydmax(pts, levels)

The input pts is the set of points we want to quantize, and levels is the number of levels we want to quantize to. The output x is a (levels+1)-vector of decision boundaries, and y is a levels-vector of quantized values. The output of the quantizer must satisfy

xi = yi− 1 + yi 2 ∀i ∈ { 2 ,... , levels} (1)

yi =

∫ (^) xi+ ∫^ x i^ xp(x)^ dx xi+ xi p(x)^ dx^

∀i ∈ { 1 ,... , levels} (2)

Where x 1 is smaller than the smallest value of pts, and xlevels+1 is larger than the largest value of pts. The function p(x) is the number of points in pts that is equal to x^1. The interpretation of the result is that values between xi and xi+1 should be quantized to yi. One way to implement this function is to start with equally spaced values of xi, and then compute the values of yi. Then, use the new values of yi to update xi and iterate until convergence. You may have to do some fix-up if you get into a case where a bin is empty.

(^1) In general, p(x) should be a normalized histogram over distribution of pts, but in our case, we will use a discrete set of points.

2.2 DPCM

You will encode and decode images to 3 bits per pixel using DPCM. The first function you will need to write is:

function [code, y] = dpcmencode(img)

This will take an image (you may assume that it will be 256 × 256) and encode it using DPCM. We will encode the image in a column-wise fashion. The output code will be a 256 × 256 matrix. The first row value will simply be is the first row of the source (in full 8 bits). The remainder of each column will encode the differences of adjacent pixels (in 3 bits). To figure out the quantization levels, compute the adjacent differences (see the MATLAB diff command) and run those through your Lloyd-Max quantizer. Since we are quantizing to 3 bits, you should encode to 8 levels. Thus, the nonleading values of code should be integers between 1 and 8 inclusive. Return the quantized values in y so that you can use them for decoding. In a real application, the quantization level would have been decided beforehand by studying a large set of images. Important: If you simply quantize the differences to the lower levels, you will get really poor performance. (There will probably be obvious banding.) You must feed back the error from the previous quantization step as shown in the notes for good results. Then, write a function which takes the encoded data and reproduces the image:

function img = dpcmdecode(code, y)

2.3 Block Transform with KLT

We will also encode and decode images to 3 bits per pixel using block transforms and KLT. The signature of the encoding function looks like:

function [code, basis, mn, y] = kltencode(img)

2.3.1 Transform

First, you will break the image into 4 × 4 disjoint blocks and rearrange each block into a column vector. You may find the im2col command in the Image Processing Toolkit useful. At the end, you should have a 16 × 4096 matrix, where each column is one block. Then, you should perform KLT (a.k.a PCA), extracting the mean component and 16 different orthogonal eigenvectors. (You will probably use the MATLAB eig command to produce the eigenvalues and eigenvectors.) Return the mean in mn and the eigenvectors in basis for decoding. (Again, in a real application, we study a large set of blocks and identify the mean and a basis beforehand.)

2.3.2 Assign bits

Then, you must encode each block. Since we want 3 bits per pixel, we have 48 bits for a block. We need to distribute the bits properly. The equation from the notes is

bi = θ +

log 2

λi (det(Mx))^1 /N

(a) Your name. (b) The RMS error and PSNR^2 for the DPCM encoding. (c) The number of bits you assigned to each channel for the block transform. (d) The RMS error and PSNR for the block transform.

Please email a copy of the archive to [email protected]

4 Additional Resource

MathWorks Inc. provides an excellent documentation on how to use MATLAB. You may learn more about MATLAB from their website at: http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.shtml

(^2) Peak SNR is 20 log 10 255 rms. See^ http://en.wikipedia.org/wiki/Peak signal-to-noise ratio