You are on page 1of 7

Journal of Engineering Research and Studies E-ISSN0976-7916

Research Article
REAL TIME VIDEO COMPRESSION IMPLEMENTED USING
ADAPTIVE BLOCK TRANSFER / MOTION COMPENSATION
FOR LOWER BIT RATES
S.L. Lahudkar# and R.K. Prasad*
Address for Correspondence
# : Ph.D student , Bharati Vidyapeeth Deemed University, Pune
*: Guide; Head Dept. of Electronics & Telecommunication , AIT Pune
Affiliation: 1) Bharati Vidyapeeth Deemed University College of Engineering, Pune
2) JSPMs Imperial College of Engineering & Research, Pune
ABSTRACT
The aim of this paper is to achieve considerable amount of compression in real-time images by using adaptive block
transform with lower bit rates. The project aims to achieve the above mentioned objective by developing a code on a Turbo
C++ platform / MATLAB. The project discusses important features of adaptive block transform in compression of still
images, including the extent to which the quality of image is degraded by the process of discrete cosine transform
compression and decompression. Image quality is measured objectively, using peak signal-to-noise ratio or picture quality
scale, and subjectively, using perceived image quality. The effects of different functions, image contents and compression
ratios are assessed. A comparison with a discrete-cosine-transform-based compression system is given. Our results provide a
platform for reduced memory space and bandwidth requirements in on-line applications like video conferencing. Our project
also discusses the challenges faced while developing an efficient solution for bandwidth and memory problems on a Turbo
C++ platform. The still image formats used are essentially BMP (Bitmap), JPEG (Joint Photographic Experts Group)
and GIF (Graphical Inter-Face).On similar lines the real-time image formats we have worked with are MPEG(Motion
Picture Experts Group) and AVI(Audio-Visual Interface) .
KEY WORDS Compression, JPEG, Discrete Cosine Transform, Inverse Discrete Cosine Transform, Quantization, Run
Length Coding, Entropy, Adaptive Block Transfer.
1.0 INTRODUCTION: the sender's data more concisely, but nevertheless
1.1 Types of compression: There are two basic perfectly. Lossless compression is possible because
compression schemes: most real-world data has statistical redundancy. For
1.1.1: Lossless vs. lossy compression: The example, in English text, the letter 'e' is much more
advantage of lossy methods over lossless methods is common than the letter 'z', and the probability that the
that in some cases a lossy method can produce a letter 'q' will be followed by the letter 'z' is very
much smaller compressed file than any known small. Another kind of compression, called lossy data
lossless method, while still meeting the requirements compression, is possible if some loss of fidelity is
of the application. Lossy methods are most often used acceptable. For example, a person viewing a picture
for compressing sound, images or videos. The or television video scene might not notice if some of
compression ratio (that is, the size of the compressed its finest details are removed or not represented
file compared to that of the uncompressed file) of perfectly. Similarly, two clips of audio may be
lossy video codecs are nearly always far superior to perceived as the same to a listener even though one is
those of the audio and still-image equivalents. Audio missing details found in the other. [1] Lossy data
can be compressed at 10:1 with no noticeable loss of compression algorithms introduce relatively minor
quality, video can be compressed immensely with differences and represent the picture, video, or audio
little visible quality loss, eg 300:1. [5] Lossily using fewer bits. Lossless compression schemes are
compressed still images are often compressed to reversible so that the original data can be
1/10th their original size, as with audio, but the reconstructed, while lossy schemes accept some loss
quality loss is more noticeable, especially on closer of data in order to achieve higher compression.
inspection. When a user acquires a lossily- However, lossless data compression algorithms will
compressed file, (for example, to reduce download- always fail to compress some files; indeed, any
time) the retrieved file can be quite different from the compression algorithm will necessarily fail to
original at the bit level while being indistinguishable compress any data containing no discernible patterns.
to the human ear or eye for most practical purposes. Attempts to compress data that has been compressed
Many methods focus on the idiosyncrasies of the already will therefore usually result in an expansion,
human anatomy, taking into account, for example, as will attempts to compress encrypted data. In
that the human eye can see only certain frequencies practice, lossy data compression will also come to a
of light. The psycho-acoustic model describes how point where compressing again does not work,
sound can be highly compressed without degrading although an extremely lossy algorithm, which for
the perceived quality of the sound. Flaws caused by example always removes the last byte of a file, will
lossy compression that are noticeable to the human always compress a file up to the point where it is
eye or ear are known as compression artifacts.[5] empty.[2]
Lossless compression algorithms usually exploit 2.0 Theory:
statistical redundancy in such a way as to represent 2.1: What is JPEG?

JERS/Vol. II/ Issue III/July-September, 2011/147-153


Journal of Engineering Research and Studies E-ISSN0976-7916

"Joint Photographic Expert Group". Voted as


international standard in 1992. [4]
Works with color and grayscale images, e.g.,
satellite, medical, ...
2.2 Motivation
The compression ratio of lossless methods (e.g.,
Huffman, Arithmetic, LZW) is not high enough for
image and video compression, especially when the
distribution of pixel values is relatively flat. [4] JPEG
uses transform coding, it is largely based on the
following observations: Fig 3. Representation of Horizontal & Vertical
Observation 1: A large majority of useful image coefficients of DCT
contents change relatively slowly across images, i.e., Most software implementations use fixed point
it is unusual for intensity values to alter up and down arithmetic. Some fast implementations approximate
several times in a small area, for example, within an coefficients so all multiplies are shifts and adds.
8 x 8 image block. Translate this into the spatial 2.4.2 Quantization [1,9]
frequency domain, it says that, generally, lower F'[u, v] = round ( F[u, v] / q[u, v] ).
spatial frequency components contain more Quantization error is the main source of the
information than the high frequency components Lossy Compression.
which often correspond to less useful details and Uniform Quantization
noises.[4] Each F[u,v] is divided by the same constant
2.3 JPEG overview N.
2.3.1 Encoding Non-uniform Quantization -- Quantization Tables
Eye is most sensitive to low frequencies
(upper left corner), less sensitive to high
frequencies (lower right corner)
Table 1.Luminance Quantization Table q(u, v)

Fig 1. JPEG Encoder


2.4 Major Steps for JPEG Encoding [4]
DCT (Discrete Cosine Transformation)
Table 2.Chrominance Quantization Table q(u, v)
Quantization
Zigzag Scan
DPCM on DC component
RLE on AC Components
Entropy Coding
2.4.1 Discrete Cosine Transform (DCT) [1, 8]

The numbers in the above quantization tables can be


scaled up (or down) to adjust the so called quality
Fig 2. Conversion from Spatial to Frequency factor.
Domain Custom quantization tables can also be put in
Discrete Cosine Transform (DCT): image/scan header.
2.4.3 Zig-zag Scan [1,5]
Why? -- to group low frequency coefficients
in top of vector.
Maps 8 x 8 to a 1 x 64 vector
caled up (or down) to adjust the so called quality
Inverse Discrete Cosine Transform (IDCT): factor.

JERS/Vol. II/ Issue III/July-September, 2011/147-153


Journal of Engineering Research and Studies E-ISSN0976-7916

then compares this prediction with the actual pixel


value at the position "X", and encodes the difference
(prediction residual) losslessly.
It can use any one of the following seven
predictors.[2,4]
Table 3.Prediction table
Predictor Prediction
Fig 4. Zig- Zag Scanning
1 A
2.4.4. Differential Pulse Code Modulation 2 B
(DPCM) on DC component 3 C
DC component is large and varied, but often 4 A+B-C
close to previous value. 5 A + (B - C) / 2
6 B + (A - C) / 2
Encode the difference from previous 8 x 8 7 (A + B) / 2
blocks -- DPCM [5] Since it uses only previously encoded
2.4.5. Run Length Encode (RLE) on AC neighbors, the very first pixel I(0, 0) will
components have to use itself. Other pixels at the first
1 x 64 vector has lots of zeros in it row always use P1, at the first column
Keeps skip and value, where skip is the always use P2.
number of zeros and value is the next non- Effect of Predictor (test result with 20
zero component. images):
Send (0,0) as end-of-block sentinel value.
[5]
2.4.6 Entropy Coding
Categorize DC values into SIZE (number of
bits needed to represent) and actual bits. [4]
Example: if DC value is 4, 3 bits are needed.
Send off SIZE as Huffman symbol, followed by
actual 3 bits.
For AC components two symbols are used:
Symbol_1: (skip, SIZE), Symbol_2: actual Fig 6. Compression ratio at various Prediction
bits. Symbol_1 (skip, SIZE) is encoded using Levels
the Huffman coding, Symbol_2 is not 2.5.2 Sequential Mode
encoded. Each image component is encoded in a single left-to-
Huffman Tables can be custom (sent in right, top-to-bottom scan.
header) or default. Baseline Sequential Mode, the one that we described
above, is a simple case of the Sequential mode:
It supports only 8-bit images (not 12-bit images)
It uses only Huffman coding (not Arithmetic coding)
[2,4]
2.5.3. Progressive Mode
Goal: display low quality image and
successively improve.
Two ways to successively improve image:
1. Spectral selection: Send DC component
and first few AC coefficients first, then
Fig 5. JPEG Bit Stream gradually some more ACs. [3]
2.5 JPEG Modes 2. Successive approximation: send DCT
Lossless Mode coefficients MSB (most significant bit)
Sequential Mode to LSB (least significant bit).
Progressive Mode Effectively, it is sending quantized DCT
Hierarchical Mode coefficients frist, and then the
2.5.1 Lossless Mode difference between the quantized and
A special case of the JPEG where indeed there is no the non-quantized coefficients with
loss. It does not use DCT-based method! Instead, it finer quantization stepsize.[3]
uses a predictive(differential coding) method: 2.5.4 Hierarchical Mode
A predictor combines the values of up to three (a) Down-sample by factors of 2 in each dimension,
neighboring pixels (not blocks as in the Sequential e.g., reduce 640 x 480 to 320 x 240
mode) as the predicted value for the current pixel, (b) Code smaller image using another JPEG mode
indicated by "X" in the figure below. The encoder (Progressive, Sequential, or Lossless).

JERS/Vol. II/ Issue III/July-September, 2011/147-153


Journal of Engineering Research and Studies E-ISSN0976-7916

insignificant DCT coefficients to zero. The variable


length coder (VLC) performs run length coding on
the quantized coefficients compressing long runs of
DCT coefficients.
The coder sends the compressed data to the
decoder, which applies inverse process to reconstruct
the frame. The variable run length decoder(VLC-1)
reconstructs the quantized data and inverse
quantization block (Quant-1) block multiples by the
quantization parameter to recreate the DCT
coefficients. Next the IDCT block transforms the
Fig 7. Three level Hierarchical JPEG Encoder DCT coefficients back to the spatial domain. Finally
(c) Decode and up-sample encoded image the inverse estimation block. (MEC-1). [6]
(d) Encode difference between the up-sampled and
the original using Progressive, Sequential, or
Lossless.
Can be repeated multiple times.
Good for viewing high resolution image on
low resolution display.
Fig 8. Encoder / Decoder for low power & Low Bit
3. 0 Methodology:
Rate
3.1 Transmitter
4.0 Innovations Implemented:
1. Implementation of RT Video
4.1 Adaptive Block Size Transform:
conferencing using DCT / ABT
Traditionally, 8 8 transforms have been used for
(MATLAB)
image and video coding. However, there is evidence
 Camera interfacing
to suggest that 4 4 transforms can reduce ringing
 Converting video data into frames
artifacts at edges and discontinuities. It is capable of
(JPEG)
coding an 8 8 block using either an 8 8 transform,
 JPEG encoding
two 8 4 transforms, two 4 8 transforms, or four 4
 Applying color space transformation
4 transforms. This feature enables coding that takes
 Down sampling
advantage of the different transform sizes as needed
 Block splitting
for optimal image quality.[7]
 DCT using Adaptive Block Transfer
 Quantization
 Transmitting compressed data serially
through com port
3.2 Receiver
 Receiving compressed data serially
through com port
 De Quantization Fig 9. ABT applied to 8 x 8 Block with and
 Block splitting without Pre-filtering
 IDCT 4.2 Motion Compensation:
 JPEG Decoder Motion compensation is the process of generating a
 Integrating frames to a video file using prediction of a video frame by displacing the
3.3 Low Power Design of DCT / IDCT for Lower reference frame. Typically, the prediction is formed
Bit Rates: for a block (an 8 8 pixel tile) or a macroblock (a 16
Low bit rate wireless video systems have 16 pixel tile) of data. The displacement of data due
applications in cellular videophones, wireless to motion is defined by a motion vector, which
surveillance systems. captures the shift along both the x- and y-axes.The
Fig below shows the encoder and decoder efficiency of the codec is affected by the size of the
for lower bit rate systems. predicted block, the granularity of sub-pixel data that
Starting at the encoder the Motion Estimation can be captured, and the type of filter used for
block(MEC) performs the temporal compression by generating sub-pixel predictors. VC-1 uses 16 16
computing the difference between the current frame blocks for prediction, with the ability to generate
and the previous frame . The temporal compressed mixed frames of 16 16 and 8 8 blocks. Two sets
data is sent to DCT which is a key component in of filters are used by VC-1 for motion compensation.
spatial compression of data. The DCT block The first is an approximate bicubic filter with four
transforms the data into spatial frequency taps. The second is a bilinear filter with two taps.
coefficients. The quantization block divides each [7,10]
DCT coefficient by a quantization parameter setting

JERS/Vol. II/ Issue III/July-September, 2011/147-153


Journal of Engineering Research and Studies E-ISSN0976-7916

5.0 Experimental Results:


Reference code
vid = videoinput('winvideo',1);
vidRes = get(vid, 'VideoResolution');
imWidth = vidRes(1);
imHeight = vidRes(2);
nBands = get(vid, 'NumberOfBands');
hImage = image( zeros(imHeight, imWidth, nBands) );
figSize = get(hFig,'Position');
figWidth = figSize(3);
figHeight = figSize(4);
set(gca,'unit','pixels','position',[ 275 170 250 250 ]);
%'position',[ ((figWidth - imWidth)/2) ((figHeight - imHeight)/2) imWidth imHeight ]);
preview(vid,hImage);
wait(5000);
function GetFR_Callback (src, evt)
index= get(src,'Value');
set(msgs,'String',strcat('Framerate = ',num2str(framerate), ' fps'));
end
function startR_Callback(src, evt)
set(msgs,'String','RECORDING VIDEO...');
set(vid,'FramesPerTrigger',100);
interval = 1;
set(vid,'FrameGrabInterval',interval);
capturetime = 20;
numframes = floor(capturetime * framerate / interval);
set(vid,'FramesPerTrigger', numframes);
set(vid,'LoggingMode','disk');
fname = strcat('I',int2str(cnt),'.avi');
avifil = avifile(fname,'fps',framerate,'colormap','rgb');
set(vid,'DiskLogger',avifil);
start(vid);
wait(vid,Inf);
avifil = get(vid,'DiskLogger');
avifil = close(avifil);
set(msgs,'String','FILE RECORDED!!!');
% stoppreview(vid);
cnt = cnt+1;
% delete(vid);
% clear vid;
return;
end
function closeW_Callback(src, evt)
stoppreview(vid);
delete(vid);
close(gcf);
close all;
clear all;
end
function Compress_Callback(src, evt)
set(msgs,'String','COMPRESSING.');
fname = strcat('I',int2str(ccnt),'.avi');
cname = strcat('C',int2str(ccnt),'.avi');
dctavi = avifile(cname,'colormap','rgb');
finfo = aviinfo(fname);
icmp = finfo.FileSize;
for i = 1:finfo.NumFrames
mov = aviread(fname ,i);
[a,map] = frame2im(mov); %video converted 2 image
coeff=1000;
red = double(a(:,:,1));
green = double(a(:,:,2));
blue = double(a(:,:,3));
red_dct=dct2(red);
green_dct=dct2(green);
blue_dct=dct2(blue);
red_pow = red_dct.^2;
green_pow = green_dct.^2;
red_pow=red_pow(:);
green_pow=green_pow(:);
blue_pow=blue_pow(:);
[B_r,index_r]=sort(red_pow);

JERS/Vol. II/ Issue III/July-September, 2011/147-153


Journal of Engineering Research and Studies E-ISSN0976-7916

[B_g,index_g]=sort(green_pow);
[B_b,index_b]=sort(blue_pow);
index_r=flipud(index_r);
index_g=flipud(index_g);
im_dct_r=zeros(size(red));
im_dct_g=zeros(size(green));
im_dct_b=zeros(size(blue));
im1=zeros(size(red,1),size(red,2),3);
for ii=1:coeff
im_dct_r(index_r(ii))=red_dct(index_r(ii));
im_dct_g(index_g(ii))=green_dct(index_g(ii));
im_dct_b(index_b(ii))=blue_dct(index_b(ii));
end
im1(:,:,1)=im_dct_r;
im1(:,:,2)=im_dct_g;
im1(:,:,3)=im_dct_b;
im1=uint8(im1);
dctavi = addframe(dctavi,im1) ; % dct avi file
end
ccnt = ccnt +1;
dctavi = close(dctavi);
% close all
% clear all
cinfo = aviinfo(cname);
ccmp = cinfo.FileSize;
cmpr = double ((ccmp / icmp) * 100);
set(msgs,'String','FILE COMPRESSED!!!');
set(cr,'String',num2str(cmpr));

Fig 10. DCT applied to a video frame


Original image Leveled off image

After 1-D DCT Total DCT

Fig 11. Total DCT of a video frame

JERS/Vol. II/ Issue III/July-September, 2011/147-153


Journal of Engineering Research and Studies E-ISSN0976-7916

Fig 12. Rate / Distortion curves with & without ABT

Fig 13. Motion compensated frame

6.0 CONCLUSION: REFERENCES


Digital video compression, although only recently 1. Ken Cabeen and Peter Gent, Image Compression &
Discrete Cosine Transform
becoming a standardized technology, is strongly 2. Alexandre Krivolulhefts, A Method for Progressive
based upon the information coding technologies Near Lossles Compression, Proceedings of IEEE
developed over the past 40 years. The large variety of International Conference on Image Processing, pp 185-
188, 2003.
bandwidth and video quality requirements for the 3. I.Avcibas, N.Memon, B.Sankur and K. Sayood, A
transmission and storage of digital video information Progressive Lossless/ Near Loss Less Image
Compression Algorithm, IEEE signal processing
has demanded that a variety of video compression
letters 9(10), pp 312-314, 2002.
techniques and standards be developed. The major 4. W.B. Pennebaker, J.L. Mitchell, "The JPEG Still
international standards recommended by IS0 and the Image Data Compression Standard", Van Nostrand
Reinhold, 1993.
ITU make use of common video coding methods. 5. V Bhaskaran and K. Konstantinides, "Image and Video
They address avast landscape of application Compression Standards: Algorithms and
requirements, from low- to high bitrate environments, Architectures", 2nd ed. Kluwer Academic Publishers,
1997.)
as well as stored video and multimedia to real-time 6. Nathenial J, August , Dong Sam Ha, Low Power
videoconferencing and high-quality broadcast Design of DCT and IDCT for Low Bit rate Video
Codecs, IEEE Transactions on Multimedia Vol.6, No.
television.
3, June 2004,pp(414 - 420).
The near future will drive video compression 7. Jay Loomis and Mike Wasson, VC-1 Technical
systems to incorporate support for more interactive Overview, Microsoft Corporation, Oct. 2007.
8. Andrew B. Watson, Image Compression using
functions, with the ability to define and download Discrete Cosine Transform, Mathematica Journal,
new functions to the encoder. New encoding methods 4(1), 2004, pp 84-88.
currently being explored by the MPEG-4 and MPEG- 9. M.A Robertson and R.L. Stevenson, DCT
Quantization Noise in Compressed Images, IEEE
7 standards look toward object-based encoding in Transactions on Circuits & Systems for Video
which the encoder is not required to follow the Technology, Vol. 15, No.1 , Jan. 2005, pp 27 - 38.
10. S. Dhahri, A. Zitouni, H. Chaouch, and R. Tourki,
international video transmission signal formats.
Adaptive Motion Estimator Based on Variable Block
These object-based techniques are expected to Size Scheme, World Academy of Science, Engineering
produce significant improvements in both encoder & Technology, 50, 2009, pp 384 390.
efficiency and functionality for the end user.

JERS/Vol. II/ Issue III/July-September, 2011/147-153

You might also like