image formats - fit.vutbr.czibarina/pub/image-formats-en.pdf · image formats davidbařina...
TRANSCRIPT
Image formats
David Bařina
March 22, 2013
David Bařina Image formats March 22, 2013 1 / 49
Contents
1 Notions
2 Uncompressed formats
3 Lossless formats
4 Lossy formats
David Bařina Image formats March 22, 2013 2 / 49
Introduction
the need for compression: FullHD image with resolution1920×1080×3 ≈ 6MBcompression: none, lossless, lossyformats: BMP, TIFF, GIF, PNG, JPEG-LS, JPEG, JPEG-2000, . . .
David Bařina Image formats March 22, 2013 3 / 49
Compression
data (BMP, TIFF)data → RLE (BMP, TGA, TIFF)data → prediction → context EC (JPEG-LS)data → prediction → RLE → ECdata → prediction → dictionary method (PNG)data → dictionary method (GIF)data → transform → RLE+EC (JPEG)data → transform → context EC (JPEG 2000)
David Bařina Image formats March 22, 2013 4 / 49
Color
colorprimary colors of CRTs: R, G, BluminanceITU-R BT.601
Y = 0.299R + 0.587G + 0.114B
David Bařina Image formats March 22, 2013 5 / 49
Color models and spaces
modelCIE xy chromaticity diagramspace, gamut
David Bařina Image formats March 22, 2013 6 / 49
YCbCrRGB transform
YCbCr
=
0128128
+
+0.299 +0.587 +0.114−0.16875 −0.33126 +0.5+0.5 −0.41869 −0.08131
·R
GB
David Bařina Image formats March 22, 2013 7 / 49
Chroma subsampling
Y vs. Cb, Cr
unobservable by humanblock, macropixelJ:a:b, 4:4:4, 4:2:2, 4:1:1, 4:2:0centroids
4:4:4 4:2:2
4:1:1 4:2:0
David Bařina Image formats March 22, 2013 8 / 49
Pixelformat
model + memory layoutRGB24 vs. BGR24planar: R0R1R2 . . .G0G1G2 . . .B0B1B2 . . .
packed: R0G0B0R1G1B1 . . .
...{pixel
} row
framebuffer:
image
byte
stride
width
David Bařina Image formats March 22, 2013 9 / 49
Multidimensional data
linearizationraster scan (everywhere), zig-zag (JPEG), z-curve (EZW, SPIHT),other (EBCOT)
David Bařina Image formats March 22, 2013 10 / 49
Predictorsprediction of symbol x , min. errorpredictor order, domainlinear and non-linear predictors
xa
bc d
a
cb
x
p = a + b − c
David Bařina Image formats March 22, 2013 11 / 49
Predictorstrivial: a, b, c, daverage, medianp (fit plane)MED (JPEG-LS)
x̂ =
min(a, b) : c ≥ max(a, b)max(a, b) : c ≤ min(a, b)p
Paeth (PNG)
x̂ = argminx∈a,b,c
|p − x |
David Bařina Image formats March 22, 2013 12 / 49
Transforms
sparse image reprezentationlossy methods (quantization)often DCT, DWTblocks, blocking artifacts
David Bařina Image formats March 22, 2013 13 / 49
DCT (discrete cosine transform)
gk,j [n,m] = λkλj2N cos
[kπN
(n +
12
)]cos
[ jπN
(m +
12
)]
c[k, j] =N−1∑n=0
N−1∑m=0
f [n,m] gk,j [n,m]
f [n,m] =N−1∑k=0
N−1∑j=0
c[k, j] gk,j [n,m]
0 ≤ k, j < N λk =
{1/√2 : k = 0
1
David Bařina Image formats March 22, 2013 14 / 49
DCT (discrete cosine transform)
David Bařina Image formats March 22, 2013 15 / 49
DWT (discrete wavelet transform)
aj+1 = (aj ∗ h) ↓ 2
dj+1 = (aj ∗ g) ↓ 2
1st level 2nd level
David Bařina Image formats March 22, 2013 16 / 49
2-D DWT
David Bařina Image formats March 22, 2013 17 / 49
BMP
BMP (DIB)uncompressed, RLE for palettestores: 1, 4, 8-bit indices intopallete; 16, 24, 32 RGB (BGRorder)bottom-top row order, 32-bitalignedWindows API, MSDNstructures BITMAPFILEHEADER(header, data offset),BITMAPINFOHEADER(dimensions, compression)
BMP file
BITMAPFILEHEADER
BITMAPINFO
image data
David Bařina Image formats March 22, 2013 18 / 49
TIFF
TIFF (Tagged Image FileFormat), 1986, 1992, Adobeseveral pages, fragmented data,transparency, colorometrycompression: RLE, LZW, JPEGstructure: analogy to FSheader, IFD, entry, tag,type+count, datatypes: byte (8-bit), ascii(characters), short (16), long(32), . . .
directory(IFD)
header entry
data
nextdirectory
.
.
.
.
.
.
tag
nextentry.
.
.
David Bařina Image formats March 22, 2013 19 / 49
TIFF
tags: Compression (none, PackBits, LZW, JPEG), ImageLength,ImageWidth, BitsPerSample, ColorMap, SamplesPerPixel
fragmentation: stripes, tilesstores: bi-level (2), gray-scale (16, 256), palette (16, 256), RGB(16M), CMYK (232), YCbCr (224)more tags: Artist (image creator), Copyright, DateTime,ImageDescription, Make (device manufacturer), Model (devicemodel), Orientation, Software, . . .PackBits: RLE variant, per bytes
I read nI 0 to 127: copy next n + 1 bytes to outputI −127 to −1: output next byte (−n + 1) times
David Bařina Image formats March 22, 2013 20 / 49
GIFGIF (Graphics Interchange Format), CompuServe, 1987 (GIF87a),1989 (GIF89a)LZW (patents, PNG)stores: frames (palette with indices up to 8-bits), animations, TrueColor (16M)transparent pixels (89a)logical screen, frames, background color
1
2
3
David Bařina Image formats March 22, 2013 21 / 49
GIF
global and local color palletesLZW: clear code, EOFcompression per rowsprogressive transfer: stripes of 8 rows, 4 passes
row sequentially pass of interleaving row by interleaving1 1 12 4 53 3 34 4 65 2 26 4 77 3 48 4 8
Google for: true color gif
David Bařina Image formats March 22, 2013 22 / 49
PNG
PNG (Portable Network Graphics), replacement for GIFDeflateextensible, interleaving, alpha channel
pixel type channels bit-depthspalette indices 1, 2, 4, 8grayscale Y 1, 2, 4, 8, 16grayscale w. transparency Y, A 8, 16true color R, G, B 8, 16true color w. transparency R, G, B, A 8, 16
compression: predictor (filter) + Deflate
David Bařina Image formats March 22, 2013 23 / 49
PNG
prediction: per rows, per bytes, 5 predictors
predictor predicted valuenone 0left btop aavg. b(a + b)/2cPaeth (above)
David Bařina Image formats March 22, 2013 24 / 49
PNGinterleaving: Adam7 (8× 8 pixels, 7 passes, each pass doubleresolution)
1 6 4 6 2 6 4 67 7 7 7 7 7 7 75 6 5 6 5 6 5 67 7 7 7 7 7 7 73 6 4 6 3 6 4 67 7 7 7 7 7 7 75 6 5 6 5 6 5 67 7 7 7 7 7 7 7
structure: blocks (type, size) – critical and ancillaryblock: size, name, data, CRCname: four characters (critical, registered, –, do not copy)critical: IHDR (header), PLTE (palette), IDAT (image data), IEND(footer)
David Bařina Image formats March 22, 2013 25 / 49
JPEG-LS
replacement for JPEG (lossless mode), not JPEG modificationbased on LOCO-I (LOw COmplexity LOssless COmpression forImages)predictor + context EC (Rice), also RLE variantcompression on rowsgeneric method, stores e.g. RGB, palette imagesfile format based on JIF (further)
inputimage
compressedimage
contextdetermination
predictionerrorcoding
runcoding
David Bařina Image formats March 22, 2013 26 / 49
JPEG-LSgradient D = (D1,D2,D3) (smoothness, edge)
D1 = Rd − RbD2 = Rb − RcD3 = Rc − Ra
chooses compression mode (zero gradient)quantize gradient: Di → Qi ∈ 〈−4, 4〉93 = 729, merge, 365 contexts
xa
bc d
David Bařina Image formats March 22, 2013 27 / 49
JPEG-LSMED predictorvalue on edge, or plane fitting
Px =
min(Ra,Rb) : Rc ≥ max(Ra,Rb)max(Ra,Rb) : Rc ≤ min(Ra,Rb)Ra + Rb − Rc
subsequent context dependent correction of predictionnear-lossless method: quantization of prediction error
xa
bc d
David Bařina Image formats March 22, 2013 28 / 49
JPEG-LS
codes error of predictionlimited Golomb-Rice code (max. length)parameter of Rice code dependent on contextnegative values mapping
EM =
{2 · |E | : E ≥ 02 · |E | − 1 : E < 0
David Bařina Image formats March 22, 2013 29 / 49
JPEG
JPEG committee (Joint Photographic Experts Group), 1992standard ISO/IEC 10918-1, recomendation CCITT/ITU-T T.81incorrectly file format (correctly JFIF or Exif)lossy and lossless compressionsequential and progressive transmissiondefines JIFbaseline process: mandatory, 8-bits, Huffman code with 2 AC + 2 DCtables, sequentialextended process: 8 + 12-bits, 4 AC + 4 DC
David Bařina Image formats March 22, 2013 30 / 49
JPEG
DCT quantization
quantizationtable
codetable
RLE Huffmancoder
inputimage
component
compressedbitstream
YCbCr inputchroma subsampling (4:2:2 a 4:2:0)blocks 8× 8, artifactsDCTcoefficients: 1 DC + 63 ACyet fully invertible
David Bařina Image formats March 22, 2013 31 / 49
JPEG
DC
(a) Edge direction (b) Frequency (c) Bases
quantization, quantization table (JPEG parametr)
Sqv ,u = round(Sv ,u/Qv ,u)
David Bařina Image formats March 22, 2013 32 / 49
JPEG16 11 10 16 124 140 151 16112 12 14 19 126 158 160 15514 13 16 24 140 157 169 15614 17 22 29 151 187 180 16218 22 37 56 168 109 103 17724 35 55 64 181 104 113 19249 64 78 87 103 121 120 10172 92 95 98 112 100 103 199
17 18 24 47 99 99 99 9918 21 26 66 99 99 99 9924 26 56 99 99 99 99 9947 66 99 99 99 99 99 9999 99 99 99 99 99 99 9999 99 99 99 99 99 99 9999 99 99 99 99 99 99 9999 99 99 99 99 99 99 99
David Bařina Image formats March 22, 2013 33 / 49
JPEGblocking artifacts
zig-zag linearization, more zeros at the end, EOBDC differentiallyAC using RLE of leading zerosfollowed by arithmetic or Huffman coding (5–10%)Huffman coding: tables for DC and AC coefficients
David Bařina Image formats March 22, 2013 34 / 49
JPEG15+ zeros using ZRLAC/DC code = Huffman code (tables) + extra bitsHuffman code cannot consist of only 1-bitscode tables indexing
I DC: categoryI AC: category + zero run length
category range0 01 −1, 12 −3,−2, 2, 33 −7 · · · − 4, 4 . . . 74 −15 · · · − 8, 8 . . . 155 −31 · · · − 16, 16 . . . 31
. . .10 −1023 · · · − 512, 512 . . . 102311 −2047 · · · − 1024, 1024 . . . 2047
David Bařina Image formats March 22, 2013 35 / 49
JPEG
JIF, JFIF, Exif, SPIFFbitstream, big endianconsists of segments, max. 65 535Bsegment preceded by marker 0xff + 0x01 až 0xfe
markers: APP0 (JFIF header), APP1 (Exif), SOF0 (image in baselineprocess), SOS (compressed data), RSTm (restart points), DHT(Huffman tables), DQT (quantization tables)JIF extended to JFIF and Exif (incompatible), JFIF+Exifthumbnails, metadata (device model)Exif: TIFF (thumbnail in JFIF)SPIFF not used
David Bařina Image formats March 22, 2013 36 / 49
JPEG 2000
successor of JPEGmany improvements, better quality at the same compression ratio,more computationally demandinglossy and lossless compressionofficially ISO/IEC 15444-1, ITU-T T.800based on DWT
preprocessing DWT quantization
ROI
EBCOT
David Bařina Image formats March 22, 2013 37 / 49
JPEG 2000color model transform using RCT, ICT
Yr =
⌊R + 2G + B4
⌋Cb = B − GCr = R − G
divison into tiles (blocking artifact)DWT (CDF 9/7, 5/3)
David Bařina Image formats March 22, 2013 38 / 49
JPEG 2000
tiles
image
DWT
LL HL
LH HH
LH HH
precinct
codeblock
EBCOT
layers packetsbitstream
decomposition level, resolution, subbands (LL, HL, LH, HH)quantization, ROI (Maxshift)precinct, code-block, EBCOTlayer (quality), packet, bitstream
David Bařina Image formats March 22, 2013 39 / 49
JPEG 2000
David Bařina Image formats March 22, 2013 40 / 49
JPEG 2000EBCOT
profile-0: code blocks of size of 32× 32 or 64× 64bit-planes from MSB to LSBbits per stripes (4 bits tall)
three passes: significance propagation, magnitude refinement, cleanupcontext AC, 8-bits context
D V D
H X H
D V D
David Bařina Image formats March 22, 2013 41 / 49
JPEG 2000
packets: component, tile, resolution, precinct, layer4 axes of progressive transmission: quality, color component,resolution, positionorder can be changedbitstream compatible to JIF, but other markersJP2 file formatmetadata in XML (e.g. XMP)
David Bařina Image formats March 22, 2013 42 / 49
JPEG 2000
Comparison with JPEG (108:1, ImageMagick)
Figure: original, JPEG 2000, JPEG
David Bařina Image formats March 22, 2013 43 / 49
JPEG 2000
Error resilience
Figure: JPEG, JPEG 2000
David Bařina Image formats March 22, 2013 44 / 49
JPEG 2000
Progressive transmission (resolution)
David Bařina Image formats March 22, 2013 45 / 49
JPEG 2000
Progressive transmission (quality)
David Bařina Image formats March 22, 2013 46 / 49
JPEG 2000
Progressive transmission (position)
David Bařina Image formats March 22, 2013 47 / 49
JPEG 2000
Progressive transmission (components)
David Bařina Image formats March 22, 2013 48 / 49
Summary
colors, predictorsBMP: uncompressed, RLE for palette imagesTIFF: directory structure, tags, LZW, RLE, JPEGGIF: LZW, 256 colors, 16M colorsPNG: Deflate, predictorsJPEG-LS: context, predictor, Golomb-Rice codesJPEG: YCbCr, DCT, RLE, Huffman code, JIF, segments, markers,JFIF, ExifJPEG 2000: DWT, EBCOT
David Bařina Image formats March 22, 2013 49 / 49