SlideShare a Scribd company logo
2
Most read
3
Most read
9
Most read
426
Back
Close
Compression: Images (JPEG)
What is JPEG?
• JPEG: Joint Photographic Expert Group — an international
standard since 1992.
• Works with colour and greyscale images
• Up to 24 bit colour images (Unlike GIF)
• Target photographic quality images (Unlike GIF)
• Suitable for many applications e.g., satellite, medical, general
photography...
427
Back
Close
Basic JPEG Compression Pipeline
JPEG compression involves the following:
• Encoding
• Decoding – Reverse the order for encoding
428
Back
Close
Major Coding Algorithms in JPEG
The Major Steps in JPEG Coding involve:
• Colour Space Transform and subsampling (YIQ)
• DCT (Discrete Cosine Transformation)
• Quantisation
• Zigzag Scan
• DPCM on DC component
• RLE on AC Components
• Entropy Coding — Huffman or Arithmetic
We have met most of the algorithms already:
• JPEG exploits them in the compression pipeline to achieve
maximal overall compression.
429
Back
Close
Quantisation
Why do we need to quantise:
• To throw out bits from DCT.
• Example: (101101)2 = 45 (6 bits).
Truncate to 4 bits: (1011)2 = 11.
Truncate to 3 bits: (101)2 = 5.
• Quantisation error is the main source of Lossy Compression.
• DCT itself is not Lossy
• How we throw away bits in Quantisation Step is Lossy
430
Back
Close
Quantisation Methods
Uniform quantisation
• Divide by constant N and round result
(N = 4 or 8 in examples on previous page).
• Non powers-of-two gives fine control
(e.g., N = 6 loses 2.5 bits)
431
Back
Close
Quantisation Tables
• In JPEG, each F[u,v] is divided by a constant q(u,v).
• Table of q(u,v) is called quantisation table.
• Eye is most sensitive to low frequencies (upper left corner),
less sensitive to high frequencies (lower right corner)
• JPEG Standard defines 2 default quantisation tables, one for
luminance (below), one for chrominance. E.g Table below
----------------------------------
16 11 10 16 24 40 51 61
12 12 14 19 26 58 60 55
14 13 16 24 40 57 69 56
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99
----------------------------------
432
Back
Close
Quantization Tables (Cont)
• Q: How would changing the numbers affect the picture
E.g., if we doubled them all?
Quality factor in most implementations is the scaling factor for
default quantization tables.
• Custom quantization tables can be put in image/scan header.
JPEG Quantisation Example
• JPEG Quantisation Example (Java Applet)
433
Back
Close
Zig-zag Scan
What is the purpose of the Zig-zag Scan:
• To group low frequency coefficients in top of vector.
• Maps 8 x 8 to a 1 x 64 vector
434
Back
Close
Differential Pulse Code Modulation
(DPCM) on DC Component
• Another encoding method is employed
• DPCM on the DC component.
• Why is this strategy adopted:
– DC component is large and varies, but often close to
previous value (like lossless JPEG).
– Encode the difference from previous 8x8 blocks – DPCM
435
Back
Close
Run Length Encode (RLE) on AC
Components
Yet another simple compression technique is applied to the
AC component:
• 1x63 vector (AC) has lots of zeros in it
• Encode as (skip, value) pairs, where skip is the number of
zeros and value is the next non-zero component.
• Send (0,0) as end-of-block sentinel value.
436
Back
Close
Huffman (Entropy) Coding
DC and AC components finally need to be represented by a
smaller number of bits
(Arithmetic coding also supported in place of Huffman coding):
• (Variant of) Huffman coding: Each DPCM-coded DC
coefficient is represented by a pair of symbols :
(Size, Amplitude)
where Size indicates number of bits needed to represent
coefficient and
Amplitude contains actual bits.
• Size only Huffman coded in JPEG:
– Size does not change too much, generally smaller Sizes
occur frequently (= low entropy so is suitable for coding,
– Amplitude can change widely so coding no real benefit
437
Back
Close
Huffman (Entropy) Coding (Cont)
• Example Size category for possible Amplitudes:
-------------------------------------------------
Size Typical Huffman Code for Size Amplitude
0 00 0
1 010 -1,1
2 011 -3,-2,2,3
3 100 -7..-4,4..7
4 101 -15..-8,8..15
. . .
. . .
--------------------------------------------------
• Use ones complement scheme for negative values: i.e 10 is
binary for 2 and 01 for -2 (bitwise inverse). Similarly, 00 for
-3 and 11 for 3.
438
Back
Close
Huffman Coding DC Example
• Example: if DC values are 150, -6, 5, 3, -8
• Then 8, 3, 3, 2 and 4 bits are needed respectively.
Send off Sizes as Huffman symbol, followed by actual values
in bits.
(8huff , 10010110), (3huff , 001), (3huff , 101), (2huff , 11), (4huff , 0111)
where 8huff . . . are the Huffman codes for respective numbers.
• Huffman Tables can be custom (sent in header) or default.
439
Back
Close
Huffman Coding on AC Component
AC coefficient are run-length encoded (RLE)
• RLE pairs (Runlength, Value) are Huffman coded as with
DC only on Value.
• So we get a triple: (Runlength, Size, Amplitude)
• However, Runlength, Size allocated 4-bits each and put
into a single byte with is then Huffman coded.
Again , Amplitude is not coded.
• So only two symbols transmitted per RLE coefficient:
(RLESIZEbytehuff, Amplitude)
440
Back
Close
Example JPEG Compression
441
Back
Close
Another Enumerated Example
442
Back
Close
JPEG Example MATLAB Code
The JPEG algorithm may be summarised as follows,
im2jpeg.m (Encoder) jpeg2im.m (Decoder)
mat2huff.m (Huffman coder)
m = [16 11 10 16 24 40 51 61 % JPEG normalizing array
12 12 14 19 26 58 60 55 % and zig-zag reordering
14 13 16 24 40 57 69 56 % pattern.
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99] * quality;
order = [1 9 2 3 10 17 25 18 11 4 5 12 19 26 33 ...
41 34 27 20 13 6 7 14 21 28 35 42 49 57 50 ...
43 36 29 22 15 8 16 23 30 37 44 51 58 59 52 ...
45 38 31 24 32 39 46 53 60 61 54 47 40 48 55 ...
62 63 56 64];
[xm, xn] = size(x); % Get input size.
x = double(x) - 128; % Level shift input
t = dctmtx(8); % Compute 8 x 8 DCT matrix
% Compute DCTs of 8x8 blocks and quantize the coefficients.
y = blkproc(x, [8 8], ’P1 * x * P2’, t, t’);
y = blkproc(y, [8 8], ’round(x ./ P1)’, m);
443
Back
Close
y = im2col(y, [8 8], ’distinct’); % Break 8x8 blocks into columns
xb = size(y, 2); % Get number of blocks
y = y(order, :); % Reorder column elements
eob = max(y(:)) + 1; % Create end-of-block symbol
r = zeros(numel(y) + size(y, 2), 1);
count = 0;
for j = 1:xb % Process 1 block (col) at a time
i = max(find(y(:, j))); % Find last non-zero element
if isempty(i) % No nonzero block values
i = 0;
end
p = count + 1;
q = p + i;
r(p:q) = [y(1:i, j); eob]; % Truncate trailing 0’s, add EOB,
count = count + i + 1; % and add to output vector
end
r((count + 1):end) = []; % Delete unusued portion of r
y = struct;
y.size = uint16([xm xn]);
y.numblocks = uint16(xb);
y.quality = uint16(quality * 100);
y.huffman = mat2huff(r);
444
Back
Close
Further Information
Further standards:
• Lossless JPEG: Predictive approach for lossless compression
(why?), not widely used
• JPEG 2000: ISO/IEC 15444
– Based on wavelet transform, instead of DCT, no 8 × 8 blocks,
less artefacts
– Often better compression ratio, compared with JPEG
445
Back
Close
Further Information
References:
• http://www.jpeg.org
• Online JPEG Tutorial
• The JPEG Still Picture Compression Standard
• The JPEG 2000 Still Image Compression Standard

More Related Content

What's hot (20)

PPTX
DCT image compression
youssef ramzy
 
PDF
Image compression
GARIMA SHAKYA
 
POTX
Presentation of Lossy compression
Omar Ghazi
 
PPTX
Spatial Filters (Digital Image Processing)
Kalyan Acharjya
 
PPTX
Chapter 8 image compression
asodariyabhavesh
 
PPTX
Image segmentation in Digital Image Processing
DHIVYADEVAKI
 
ODP
image compression ppt
Shivangi Saxena
 
PPT
08 frequency domain filtering DIP
babak danyal
 
PPTX
Chapter 6 color image processing
asodariyabhavesh
 
PPTX
Homomorphic filtering
Gautam Saxena
 
PPTX
Simultaneous Smoothing and Sharpening of Color Images
Cristina Pérez Benito
 
PPTX
Unit3 dip
Imran Khan
 
PPTX
Image Sensing and Acquisition.pptx
RUBIN (A) JEBIN
 
PPTX
COM2304: Intensity Transformation and Spatial Filtering – I (Intensity Transf...
Hemantha Kulathilake
 
PDF
JPEG Image Compression
Hemanth Kumar Mantri
 
PPTX
Image Enhancement using Frequency Domain Filters
Karthika Ramachandran
 
PPT
Image segmentation
Bulbul Agrawal
 
DCT image compression
youssef ramzy
 
Image compression
GARIMA SHAKYA
 
Presentation of Lossy compression
Omar Ghazi
 
Spatial Filters (Digital Image Processing)
Kalyan Acharjya
 
Chapter 8 image compression
asodariyabhavesh
 
Image segmentation in Digital Image Processing
DHIVYADEVAKI
 
image compression ppt
Shivangi Saxena
 
08 frequency domain filtering DIP
babak danyal
 
Chapter 6 color image processing
asodariyabhavesh
 
Homomorphic filtering
Gautam Saxena
 
Simultaneous Smoothing and Sharpening of Color Images
Cristina Pérez Benito
 
Unit3 dip
Imran Khan
 
Image Sensing and Acquisition.pptx
RUBIN (A) JEBIN
 
COM2304: Intensity Transformation and Spatial Filtering – I (Intensity Transf...
Hemantha Kulathilake
 
JPEG Image Compression
Hemanth Kumar Mantri
 
Image Enhancement using Frequency Domain Filters
Karthika Ramachandran
 
Image segmentation
Bulbul Agrawal
 

Viewers also liked (20)

PPT
Image compression
partha pratim deb
 
PPTX
Image Compression
Paramjeet Singh Jamwal
 
PPTX
Image compression
Bassam Kanber
 
PPTX
Image processing and compression techniques
Ashwin Venkataraman
 
PPT
Image compression
Ale Johnsan
 
DOC
Seminar Report on image compression
Pradip Kumar
 
PPT
Compression
Ashish Kumar
 
DOCX
image compression using matlab project report
kgaurav113
 
PPT
Jpeg 2000 For Digital Archives
Richard Bernier
 
PPTX
Jpeg
Anju Anjujosepj
 
PDF
intoPIX - Everything about Jpeg2000
guestd38f1
 
PDF
Signal Compression and JPEG
guest9006ab
 
PPTX
Image processing ppt
Raviteja Chowdary Adusumalli
 
PDF
Video Compression Basics
Sanjiv Malik
 
PPTX
Fundamentals of Data compression
M.k. Praveen
 
PPTX
MPEG video compression standard
anuragjagetiya
 
PPTX
Spandana image processing and compression techniques (7840228)
indianspandana
 
PDF
Data compression introduction
Rahul Khanwani
 
PPT
Data compression
VIKAS SINGH BHADOURIA
 
PPT
Image processing
Varun Raj
 
Image compression
partha pratim deb
 
Image Compression
Paramjeet Singh Jamwal
 
Image compression
Bassam Kanber
 
Image processing and compression techniques
Ashwin Venkataraman
 
Image compression
Ale Johnsan
 
Seminar Report on image compression
Pradip Kumar
 
Compression
Ashish Kumar
 
image compression using matlab project report
kgaurav113
 
Jpeg 2000 For Digital Archives
Richard Bernier
 
intoPIX - Everything about Jpeg2000
guestd38f1
 
Signal Compression and JPEG
guest9006ab
 
Image processing ppt
Raviteja Chowdary Adusumalli
 
Video Compression Basics
Sanjiv Malik
 
Fundamentals of Data compression
M.k. Praveen
 
MPEG video compression standard
anuragjagetiya
 
Spandana image processing and compression techniques (7840228)
indianspandana
 
Data compression introduction
Rahul Khanwani
 
Data compression
VIKAS SINGH BHADOURIA
 
Image processing
Varun Raj
 
Ad

Similar to Compression: Images (JPEG) (20)

PDF
CyberSec_JPEGcompressionForensics.pdf
MohammadAzreeYahaya
 
PPTX
lossy compression JPEG
Mahmoud Hikmet
 
PPTX
JPEG
MANISH T I
 
PDF
CMOS Image Sensor Design_h20_10_jpeg.pdf
AhmedHamouda68
 
PPTX
Data compression
Sherif Abdelfattah
 
PPTX
JPEG and MPEG Compression in Digital Image Processing.pptx
thirrunavukkarasurr1
 
PPT
Image Compression Digital Image processing
MasudAfjal1
 
PDF
SOC Application Studies: Image Compression
Dr. A. B. Shinde
 
PPT
Image compression- JPEG Compression & its Modes
kanimozhirajasekaren
 
PPT
M4L1.ppt
dudoo1
 
PPT
Multimedia image compression standards
Mazin Alwaaly
 
PDF
Multimedia communication jpeg
Dr. Kapil Gupta
 
ODP
MPEG-1 Part 2 Video Encoding
Christian Kehl
 
DOC
image compression in data compression
Zaabir Ali
 
PPT
Why Image compression is Necessary?
Prabhat Kumar
 
PPTX
Jpeg standards
NikhilBanerjee7
 
PDF
W13JPEGCompression techinques detail.pdf
SaraswathiD14
 
PPT
Ch7 031102
ziaullahaffan
 
PPT
image processing for jpeg presentati.ppt
naghamallella
 
PPTX
Image compression and jpeg
theem college of engineering
 
CyberSec_JPEGcompressionForensics.pdf
MohammadAzreeYahaya
 
lossy compression JPEG
Mahmoud Hikmet
 
CMOS Image Sensor Design_h20_10_jpeg.pdf
AhmedHamouda68
 
Data compression
Sherif Abdelfattah
 
JPEG and MPEG Compression in Digital Image Processing.pptx
thirrunavukkarasurr1
 
Image Compression Digital Image processing
MasudAfjal1
 
SOC Application Studies: Image Compression
Dr. A. B. Shinde
 
Image compression- JPEG Compression & its Modes
kanimozhirajasekaren
 
M4L1.ppt
dudoo1
 
Multimedia image compression standards
Mazin Alwaaly
 
Multimedia communication jpeg
Dr. Kapil Gupta
 
MPEG-1 Part 2 Video Encoding
Christian Kehl
 
image compression in data compression
Zaabir Ali
 
Why Image compression is Necessary?
Prabhat Kumar
 
Jpeg standards
NikhilBanerjee7
 
W13JPEGCompression techinques detail.pdf
SaraswathiD14
 
Ch7 031102
ziaullahaffan
 
image processing for jpeg presentati.ppt
naghamallella
 
Image compression and jpeg
theem college of engineering
 
Ad

More from danishrafiq (9)

PPT
Usability issues in mobile web
danishrafiq
 
PDF
Compression: Video Compression (MPEG and others)
danishrafiq
 
PPT
Lecture5---Gantt Chart
danishrafiq
 
PPT
Ccna day5
danishrafiq
 
PPT
Ccna day4
danishrafiq
 
PPT
Ccna day3
danishrafiq
 
PPT
Ccna day2
danishrafiq
 
PPT
Ccna day1
danishrafiq
 
PPT
Presentation wpf
danishrafiq
 
Usability issues in mobile web
danishrafiq
 
Compression: Video Compression (MPEG and others)
danishrafiq
 
Lecture5---Gantt Chart
danishrafiq
 
Ccna day5
danishrafiq
 
Ccna day4
danishrafiq
 
Ccna day3
danishrafiq
 
Ccna day2
danishrafiq
 
Ccna day1
danishrafiq
 
Presentation wpf
danishrafiq
 

Recently uploaded (20)

PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 

Compression: Images (JPEG)

  • 1. 426 Back Close Compression: Images (JPEG) What is JPEG? • JPEG: Joint Photographic Expert Group — an international standard since 1992. • Works with colour and greyscale images • Up to 24 bit colour images (Unlike GIF) • Target photographic quality images (Unlike GIF) • Suitable for many applications e.g., satellite, medical, general photography...
  • 2. 427 Back Close Basic JPEG Compression Pipeline JPEG compression involves the following: • Encoding • Decoding – Reverse the order for encoding
  • 3. 428 Back Close Major Coding Algorithms in JPEG The Major Steps in JPEG Coding involve: • Colour Space Transform and subsampling (YIQ) • DCT (Discrete Cosine Transformation) • Quantisation • Zigzag Scan • DPCM on DC component • RLE on AC Components • Entropy Coding — Huffman or Arithmetic We have met most of the algorithms already: • JPEG exploits them in the compression pipeline to achieve maximal overall compression.
  • 4. 429 Back Close Quantisation Why do we need to quantise: • To throw out bits from DCT. • Example: (101101)2 = 45 (6 bits). Truncate to 4 bits: (1011)2 = 11. Truncate to 3 bits: (101)2 = 5. • Quantisation error is the main source of Lossy Compression. • DCT itself is not Lossy • How we throw away bits in Quantisation Step is Lossy
  • 5. 430 Back Close Quantisation Methods Uniform quantisation • Divide by constant N and round result (N = 4 or 8 in examples on previous page). • Non powers-of-two gives fine control (e.g., N = 6 loses 2.5 bits)
  • 6. 431 Back Close Quantisation Tables • In JPEG, each F[u,v] is divided by a constant q(u,v). • Table of q(u,v) is called quantisation table. • Eye is most sensitive to low frequencies (upper left corner), less sensitive to high frequencies (lower right corner) • JPEG Standard defines 2 default quantisation tables, one for luminance (below), one for chrominance. E.g Table below ---------------------------------- 16 11 10 16 24 40 51 61 12 12 14 19 26 58 60 55 14 13 16 24 40 57 69 56 14 17 22 29 51 87 80 62 18 22 37 56 68 109 103 77 24 35 55 64 81 104 113 92 49 64 78 87 103 121 120 101 72 92 95 98 112 100 103 99 ----------------------------------
  • 7. 432 Back Close Quantization Tables (Cont) • Q: How would changing the numbers affect the picture E.g., if we doubled them all? Quality factor in most implementations is the scaling factor for default quantization tables. • Custom quantization tables can be put in image/scan header. JPEG Quantisation Example • JPEG Quantisation Example (Java Applet)
  • 8. 433 Back Close Zig-zag Scan What is the purpose of the Zig-zag Scan: • To group low frequency coefficients in top of vector. • Maps 8 x 8 to a 1 x 64 vector
  • 9. 434 Back Close Differential Pulse Code Modulation (DPCM) on DC Component • Another encoding method is employed • DPCM on the DC component. • Why is this strategy adopted: – DC component is large and varies, but often close to previous value (like lossless JPEG). – Encode the difference from previous 8x8 blocks – DPCM
  • 10. 435 Back Close Run Length Encode (RLE) on AC Components Yet another simple compression technique is applied to the AC component: • 1x63 vector (AC) has lots of zeros in it • Encode as (skip, value) pairs, where skip is the number of zeros and value is the next non-zero component. • Send (0,0) as end-of-block sentinel value.
  • 11. 436 Back Close Huffman (Entropy) Coding DC and AC components finally need to be represented by a smaller number of bits (Arithmetic coding also supported in place of Huffman coding): • (Variant of) Huffman coding: Each DPCM-coded DC coefficient is represented by a pair of symbols : (Size, Amplitude) where Size indicates number of bits needed to represent coefficient and Amplitude contains actual bits. • Size only Huffman coded in JPEG: – Size does not change too much, generally smaller Sizes occur frequently (= low entropy so is suitable for coding, – Amplitude can change widely so coding no real benefit
  • 12. 437 Back Close Huffman (Entropy) Coding (Cont) • Example Size category for possible Amplitudes: ------------------------------------------------- Size Typical Huffman Code for Size Amplitude 0 00 0 1 010 -1,1 2 011 -3,-2,2,3 3 100 -7..-4,4..7 4 101 -15..-8,8..15 . . . . . . -------------------------------------------------- • Use ones complement scheme for negative values: i.e 10 is binary for 2 and 01 for -2 (bitwise inverse). Similarly, 00 for -3 and 11 for 3.
  • 13. 438 Back Close Huffman Coding DC Example • Example: if DC values are 150, -6, 5, 3, -8 • Then 8, 3, 3, 2 and 4 bits are needed respectively. Send off Sizes as Huffman symbol, followed by actual values in bits. (8huff , 10010110), (3huff , 001), (3huff , 101), (2huff , 11), (4huff , 0111) where 8huff . . . are the Huffman codes for respective numbers. • Huffman Tables can be custom (sent in header) or default.
  • 14. 439 Back Close Huffman Coding on AC Component AC coefficient are run-length encoded (RLE) • RLE pairs (Runlength, Value) are Huffman coded as with DC only on Value. • So we get a triple: (Runlength, Size, Amplitude) • However, Runlength, Size allocated 4-bits each and put into a single byte with is then Huffman coded. Again , Amplitude is not coded. • So only two symbols transmitted per RLE coefficient: (RLESIZEbytehuff, Amplitude)
  • 17. 442 Back Close JPEG Example MATLAB Code The JPEG algorithm may be summarised as follows, im2jpeg.m (Encoder) jpeg2im.m (Decoder) mat2huff.m (Huffman coder) m = [16 11 10 16 24 40 51 61 % JPEG normalizing array 12 12 14 19 26 58 60 55 % and zig-zag reordering 14 13 16 24 40 57 69 56 % pattern. 14 17 22 29 51 87 80 62 18 22 37 56 68 109 103 77 24 35 55 64 81 104 113 92 49 64 78 87 103 121 120 101 72 92 95 98 112 100 103 99] * quality; order = [1 9 2 3 10 17 25 18 11 4 5 12 19 26 33 ... 41 34 27 20 13 6 7 14 21 28 35 42 49 57 50 ... 43 36 29 22 15 8 16 23 30 37 44 51 58 59 52 ... 45 38 31 24 32 39 46 53 60 61 54 47 40 48 55 ... 62 63 56 64]; [xm, xn] = size(x); % Get input size. x = double(x) - 128; % Level shift input t = dctmtx(8); % Compute 8 x 8 DCT matrix % Compute DCTs of 8x8 blocks and quantize the coefficients. y = blkproc(x, [8 8], ’P1 * x * P2’, t, t’); y = blkproc(y, [8 8], ’round(x ./ P1)’, m);
  • 18. 443 Back Close y = im2col(y, [8 8], ’distinct’); % Break 8x8 blocks into columns xb = size(y, 2); % Get number of blocks y = y(order, :); % Reorder column elements eob = max(y(:)) + 1; % Create end-of-block symbol r = zeros(numel(y) + size(y, 2), 1); count = 0; for j = 1:xb % Process 1 block (col) at a time i = max(find(y(:, j))); % Find last non-zero element if isempty(i) % No nonzero block values i = 0; end p = count + 1; q = p + i; r(p:q) = [y(1:i, j); eob]; % Truncate trailing 0’s, add EOB, count = count + i + 1; % and add to output vector end r((count + 1):end) = []; % Delete unusued portion of r y = struct; y.size = uint16([xm xn]); y.numblocks = uint16(xb); y.quality = uint16(quality * 100); y.huffman = mat2huff(r);
  • 19. 444 Back Close Further Information Further standards: • Lossless JPEG: Predictive approach for lossless compression (why?), not widely used • JPEG 2000: ISO/IEC 15444 – Based on wavelet transform, instead of DCT, no 8 × 8 blocks, less artefacts – Often better compression ratio, compared with JPEG
  • 20. 445 Back Close Further Information References: • http://www.jpeg.org • Online JPEG Tutorial • The JPEG Still Picture Compression Standard • The JPEG 2000 Still Image Compression Standard