0% found this document useful (0 votes)
28 views11 pages

Learning Objectives: CSM25 Secure Information Hiding

The document discusses JPEG compression and its application in the discrete cosine transform (DCT) domain. It aims to help students understand JPEG compression, which operates on luminance and chrominance color spaces rather than RGB. JPEG works by applying the DCT to divided image blocks, then quantizing and entropy coding the transformed values for lossy compression. The document reviews image representation formats, the blockwise DCT transform used in JPEG, and provides MATLAB functions for applying the forward and inverse DCT.

Uploaded by

Sam Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views11 pages

Learning Objectives: CSM25 Secure Information Hiding

The document discusses JPEG compression and its application in the discrete cosine transform (DCT) domain. It aims to help students understand JPEG compression, which operates on luminance and chrominance color spaces rather than RGB. JPEG works by applying the DCT to divided image blocks, then quantizing and entropy coding the transformed values for lossy compression. The document reviews image representation formats, the blockwise DCT transform used in JPEG, and provides MATLAB functions for applying the forward and inverse DCT.

Uploaded by

Sam Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Learning Objectives

The DCT domain and JPEG


CSM25 Secure Information Hiding
Be able to work with and JPEG images and other representations
in the transform domain.
Dr Hans Georg Schaathun Understand what happens during JPEG compression, and its
potential consequence to watermarking and steganography.
University of Surrey
Be able to apply simple LSB embedding in the JPEG domain.

Spring 2009 – Week 3

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 1 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 2 / 47

Overview Overview

The elements of JPEG JPEG is not a file format

Operates on luminence and chrominance (YCbCr) (not on RGB) JPEG is a compression system
Grayscale images have luminence component only. The system employs three different compression techniques
Downsampling JPEG is not a file format.
Works in the DCT domain (not the spatial domain) Files with extension .jpeg are often JFIF or EXIF.
Quantisation JFIF is traditionally the most common file format for JPEG.
EXIF is made for digital cameras and contain extra meta
Entropy coding (lossless compression) information.

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 4 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 5 / 47
Overview Image Representation Alternatives to RGB

Reading The RGB colour representations

RGB : A colour is a vector (R, G, B)


Core Reading
R is amount of red light.
Digital Image Processing Using MATLAB. G is amount of green light.
B is amount of blue light.
Chapter 6: colour images Each pixel can be either
Representation A colour vector (R, G, B); or
Processing a reference to an array of colour vectors (the palette)
Conversion Each coefficient can be
Chapter 8.5: JPEG compression ∈ [0, 1]; floating point (double in matlab)
Chapter 4: Frequency domain processing ∈ {0, 1, . . . , 255}; 8-bit integer (uint8 in matlab)
∈ {0, 1, . . . , 216 − 1}; 16-bit integer (uint16 in matlab)

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 6 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 8 / 47

Image Representation Alternatives to RGB Image Representation The blockwise DCT domain

Alternatives to RGB Block-wise

NTSC : (Y , I, Q)
    
Y 0.299 0.587 0.114 R
 I  = 0.596 −0.274 −0.322 G
Q 0.211 −0.523 0.312 B Each colour-channel (Y,Cb,Cr) considered separately
where R, G, B ∈ [0, 1]. M × N matrix divided into 8 × 8 blocks
YCbCr : (Y , Cb, Cr ) Each block is handled separately
      
Y 16 65.481 128.553 24.966 R
Cb = 128 + −37.797 −74.203 112.000  G
Cr 128 112.000 −93.786 −18.214 B

where R, G, B ∈ [0, 1] and Y , Cb, Cr ∈ [0, 255].

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 9 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 10 / 47
Image Representation The blockwise DCT domain Image Representation The blockwise DCT domain

The DCT transform The DCT transform

Several different DCT transform.


We use the following. The inverse is similar

M−1
X N−1
r
X α(u)α(v ) (2x + 1)uπ (2y + 1)v π
M−1 f (x, y ) = Tf (u, v ) cos cos
X N−1
r
X α(u)α(v ) (2x + 1)uπ (2y + 1)v π MN 2M 2N
Tf (u, v ) = f (x, y ) cos cos u=0 v =0
MN 2M 2N
x=0 y =0 where
where
(
1, if a = 0,
( α(a) =
1, if a = 0, 2, otherwise.
α(a) =
2, otherwise. M = N = 8,
M = N = 8,

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 11 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 12 / 47

Image Representation The blockwise DCT domain Image Representation The blockwise DCT domain

Matlab Transform image

Matlab functions
dct2 (2D DCT transform)
idct2 (Inverse)
blkproc ( X, [M N], FUN ) Linear combination of patterns (see
For instance right)
blkproc ( X, [8 8], @dct2 ) DC (upper left) gives average colour
Use help system for details intensity
Do not use imread for JPEG images Low frequency: coarse structure
converts images to the spatial domain. High frequency: fine details
you don’t even know the compression parameters...

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 13 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 14 / 47
Compression Downsampling Compression Downsampling

What is sampling? What do we save?

Fact
The human eye is more sensitive to changes in luminance than in Original: M × N pixels ×3 components .
chrominance.
Compressed:
To sample is to collect measurements. M N 1
Each pixel is a sample (measuring the colour of the image). 2× × +M ×N =1 M ×N
2 2 2
Lower resolution means fewer samples.
Reducing resolution = downsampling Ratio
Basic M × N image: N · M samples per component (Y , Cb, Cr ). Compressed 1 12 MN 1
= = .
Original 3MN 2
Y is more useful than Cb and Cr .
Therefore we can downsample Cb and Cr We just saved 50%
M/2 × N/2 is common for Cb and Cr
Still use M × M for Y

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 16 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 17 / 47

Compression Downsampling Compression Downsampling

Chrominance versus Luminence Downsampling in JPEG

1 Translation to YCbCr.
Fact 2 Downsampling
The human eye is more sensitive to changes in luminance than in 3 DCT transform
chrominance.
Each downsampled component matrix Y , Cb, Cr is
Watermarking tend to embed in Y (luminence) Divided into 8 × 8 blocks
Embedding in Cb and Cr would more easily be destroyed by DCT transformed blockwise
JPEG An 8 × 8 block in Cb can be associated with 1,2 or 4 Y blocks
depending on downsampling.

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 18 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 19 / 47
Compression Quantisation Compression Quantisation

What is quantisation? Quantisation in JPEG


Rounding in general

Rounding numbers is quantisation.


Measuring gives continuous numbers
Whether you measure pixel luminence, or the length of
your garage.
Quantisation in the DCT domain
No matter how close to points are, Each coefficient is divided by the quantisation constant.
there is a point in between. The result is rounded to nearest integer.
However, our precision is limited.
Different quantisation constants for each coefficient in the block.
We give lengths to the nearest unit.
Luminence is categorised into 256 intervals (8bit
integers).
Computer memory is finite,
256 different possibilites for a byte

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 20 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 21 / 47

Compression Quantisation Compression Source Coding

Example Entropy Coding


Quantisation in JPEG

Recall
−26 −3 −6 2 2 −1 0 0
 
2
DCT matrix
3 2
Quantisation matrix
3  0
 −2 −4 1 1 0 0 0
6−415 −30 −61 27 56 −20 −2 0 7 616 11 10 16 24 40 51 61 7  −3 1 5 −1 −1 0 0 0
6 4 −22 −61 10 13 −7 −9 5 7 612 12 14 19 26 58 60 55 7
6 7 6 7
 
6 −47
6
7 77 −25 −29 10 5 −67 614
7 6
13 16 24 40 57 69 56 7
7
 −4 1 2 −1 0 0 0 0 
6 −49 12 34 −15 −10 6 2 2 7 ./ 614 17 22 29 51 87 80 62 7
6 7 6 7  
6 12
6
6 −8
−7 −13 −4 −2 2 −3 3 7 618
7 6 22 37 56 68 109 103 77 7
7  1 0 0 0 0 0 0 0
6 3 2 −6 −2 1 4 2 7
7 624
6 35 55 64 81 104 113 92 7
7  
4 −1 0 0 −2 −1 −3 4 −15 449 64 78 87 103 121 120 1015  0 0 0 0 0 0 0 0
0 0 −1 −4 −1 0 1 2 72 92 95 98 112 100 103 99  
 0 0 0 0 0 0 0 0
Quantised DCT matrix
2 3
6−26 −3 −6 2 2 −1 0 07
6 0
6
−2 −4 1 1 0 0 07
7 0 0 0 0 0 0 0 0
6 −3 1 5 −1 −1 0 0 07
6 7
≈ 6 −4 1 2 −1 0 0 0 07 Observe
6 7
6 1 0 0 0 0 0 0 07
6 7
0 is extremely common
6 0 0 0 0 0 0 0 07
6 7
4 0 0 0 0 0 0 0 05
0 0 0 0 0 0 0 0 ±1 is common
Two-digit numbers are very rare
Example from Wikipedia.
This is typical

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 22 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 23 / 47
Compression Source Coding Steganography in JPEG Into the compressed domain

Entropy Coding Before or after compression

message
In order to compress the data

Use few bits (short codewords) for frequent symbols
Many bits (long codewords) only for rare symbols / LSB / JPEG stego-
/
pixmap
embedding compression image
Usually, JPEG uses a simple Huffman code.
it can use other codes (saving space, but computionally costly) message
For instance, a single short codeword to say 
‘the rest of the block is zero’ JPEG LSB stego-
pixmap / / /
compression embedding image

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 24 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 26 / 47

Steganography in JPEG Into the compressed domain Steganography in JPEG Into the compressed domain

Fragility of LSB When fragility is a problem

It is a problem in robust watermarking


LSB embedding is criticised for being fragile JPEG compression is common-place
JPEG removes insignificant information most applications need robustness
... such as the LSB If the purpose is steganography,
and Alice and Bob are allowed to exchange pixmaps,
JPEG compression after embedding (probably) ruins the message
then it is not a problem.
When is this a problem? Obviously, if your steganogram is supposed to be JPEG
... Do not do LSB in the pixmap.

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 27 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 28 / 47
Steganography in JPEG Into the compressed domain Steganography in JPEG Into the compressed domain

Double compression Important lessons

Common bug in existing software


Read an arbitrary image file
1 Do not make unnecessary image conversions.
JPEG is decompressed on reading
... → pixmap 2 Many techniques apply to any format
Embedding works on JPEG LSB applies to JPEG signals
... but it is called Jsteg
image is compressed to produce JPEG signal
quality factor (QF) either default or supplied by user 3 Use a technique which fits the target (stego-) format
A JPEG steganogram has now been compressed twice i.e. the format you are allowed to use on the channel.
different QF produces an artifact
Is there any reason for de- and recompressing?

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 29 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 30 / 47

Steganography in JPEG Into the compressed domain Steganography in JPEG JSteg and OutGuess 0.1

Main development The JSteg algorithm


The past at a glance

Core Reading
Hide and Seek: An Introduction to Steganography by Niels Provos and
Peter Honeyman, in IEEE Security & Privacy 2003. JSteg denotes a software package.
Approach: simple LSB in the DCT domain.
1 JSteg was published No different from LSB in the spatial domain
2 JSteg was broken χ2 analysis applies
3 OutGuess was published
4 OutGuess was broken
5 F5 was published
6 F5 was broken

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 31 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 32 / 47
Steganography in JPEG JSteg and OutGuess 0.1 Steganography in JPEG JSteg and OutGuess 0.1

Pseudocode Bitflips in JSteg


The JSteg algorithm

~ Cover −5 −4.. −3 −2.. −1 0 +1 +2.. +3 +4.. +5


.  .  .  . 
Input: Image I, Message m
Output: Image J .. .. .. ..
  ...   ...   ...   ...
               
~
for each bit b of m Stego −5 −4 −3 −2 −1 0 +1 +2 +3 +4 +5
c := next DCT coefficient from I
while c = 0 or c = 1,
c := next DCT coefficient from I
end while
c := c − c mod 2 + b
replace coefficient in I by c
end for

May ignore high and/or low frequency coefficients Typical JPEG. Typical JSteg.

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 33 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 34 / 47

Steganography in JPEG JSteg and OutGuess 0.1 Steganography in JPEG JSteg and OutGuess 0.1

Pros and Cons Outguess 0.1

Why is JSteg important?


How can we improve JSteg?
First publicly available solution.
Simple solution How did we improve LSB in the Spatial Domain?
What are the disadvantages?
Similar to LSB in Spatial domain. Solution
Histogramme analysis applies Choose random coefficients from the entire image.
χ2 /pairs of values applies

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 35 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 36 / 47
Steganography in JPEG JSteg and OutGuess 0.1 Steganography in JPEG JSteg and OutGuess 0.1

Pseudocode Histogramme analysis


Outguess 0.1 Steganalysis

~ , Key k
Input: Image I, Message m
Output: Image J

Seed PRNG with k


~
for each bit b of m
1 Pairs of values
c := pseudo-random DCT coefficient from I Generalised χ2 works
while c = 0 or c = 1, 2 Symmetry
c := pseudo-random DCT coefficient from I Embedding exchange +2 ↔ +3 and −2 ↔ −1.
end while The DCT histogramme is expected to be symmetric
Outguess/JSteg destroy the symmetry.
c := c − c mod 2 + b
replace coefficient in I by c
end for

May ignore high and/or low frequency coefficients

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 37 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 38 / 47

Matlab The JPEG toolbox Matlab The JPEG toolbox

JPEG Toolbox JPEG Toolbox


Reading a JPEG image JPEG data

» im = jpeg_read ( ’Kerckhoffs.jpg’ )
» Xy = im.coef_arrays{im.comp_info(1).component_id} ;
» whos Xy
im =
Name Size Bytes Class Attributes
image_width: 180
Xy 248x184 365056 double
image_height: 247
image_components: 3
» Q = im.quant_tables{im.comp_info(1).quant_tbl_no}
image_color_space: 2
jpeg_components: 3
Q =
jpeg_color_space: 3
6 4 4 6 10 16 20 24
comments: {}
5 5 6 8 10 23 24 22
coef_arrays: {[248x184 double] [128x96 double] [128x96 double]}
6 5 6 10 16 23 28 22
quant_tables: {[8x8 double] [8x8 double]}
6 7 9 12 20 35 32 25
ac_huff_tables: [1x2 struct]
7 9 15 22 27 44 41 31
dc_huff_tables: [1x2 struct]
10 14 22 26 32 42 45 37
optimize_coding: 0
20 26 31 35 41 48 48 40
comp_info: [1x3 struct]
29 37 38 39 45 40 41 40
progressive_mode: 0
»
»
Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 40 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 41 / 47
Matlab The JPEG toolbox Matlab The JPEG toolbox

w/o the toolbox Other toolbox functions


Load/Save workspace

jpeg_read and jpeg_write are compiled functions,


Available on web page for Intel/Linux and Intel/Windows
Compilation required for other systems.
If you have trouble with the toolbox, it is possible to load/save files If you want to write your own (de)compressor, the following
as Matlab workspaces. functions are useful.
bdct, ibdct, quantize, dequantize
» load ’image.mat’
» whos
Name Size Bytes Class Attributes
im 1x1 575836 struct

There is one mat-file for each image on the web page

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 42 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 43 / 47

Matlab Randomness Matlab Randomness

Pseudo-random number generators Random locations

A pseudo-random number generator (PRNG)


Many ways to do it
finite state machine
starting state given by user input – the seed but some makes it hard to avoid using the same pixel twice
each transition outputs a number A simple approach
observing a sequence of number, 1 randomly permute the pixels
it is computationally infeasible to predict the next number 2 embed in the first pixels in the permuted sequence
looks random 3 reverse the permutation
It is deterministic If the sender and receiver use the same PRNG seed,
if sender and receiver share the seed (a key) they get the same pseudo-random permutation
they can generate the same sequence

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 44 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 45 / 47
Matlab Randomness Matlab Masking

Matlab functions Masking


Boolean matrix as index

Many functions using a PRNG Matlab allows Boolean (logical) matrices as indices
rand, randperm, randn Say A is an n × m matrix
And one dedicated for performing random permutations B = logical(ones(n,m))
new = randintrlv ( old, seed ) B(1,1) = 0
the seed is given directly when the permutation is used A(B) will be all elements of A except (1, 1)
reverse: old = randdeintrlv ( new, seed ) repmat(B,m,n) replicates B to form a larger matrix
new/old should be a 1D vector m times the heigh
serialise the image into a vector (im(:)) n times the width
before randintrlv How do you extract the AC coefficients in a JPEG image?
reshape ( vector, [ N, M ] ) to recover the 2D image Make an 8 × 8 mask of ones
after randdeintrlv Set the DC entry to 0, e.g. (1, 1)
Replicate the mask using repmat

Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 46 / 47 Dr Hans Georg Schaathun The DCT domain and JPEG Spring 2009 – Week 3 47 / 47

You might also like