www hndit com Image Compression 1 www hndit

  • Slides: 28
Download presentation
www. hndit. com Image Compression 1

www. hndit. com Image Compression 1

www. hndit. com What is an Image File Format? � Image file formats are

www. hndit. com What is an Image File Format? � Image file formats are standard way of organizing and storing of image files. � Image files are composed of either pixels or vector (geometric) data. � The pixels that compose an image are ordered as a grid (columns and rows) � Each pixel consists of numbers representing levels of brightness and color. 2

www. hndit. com Image File Size � This is expressed as number of bytes

www. hndit. com Image File Size � This is expressed as number of bytes � This value depends on two factors ◦ Resolution (Number of pixels on the screen) ◦ Bit depth (Number of bits allocated for a pixel) � Large number of rows and columns increase the resolution and it leads to larger the file size. 3

www. hndit. com Image File Compression � Compression is a term used to describe

www. hndit. com Image File Compression � Compression is a term used to describe ways of cutting the size of the file. 4

www. hndit. com Why Need Image Compression? � Image files typically are larger than

www. hndit. com Why Need Image Compression? � Image files typically are larger than text files. � Web pages often contain many images that are transmitted across slow connections � A larger file type means more disk usage and slower downloads Therefore it is helpful to have a way to represent images in a compact format. 5

www. hndit. com Types of Image File Compression � There are two types of

www. hndit. com Types of Image File Compression � There are two types of Compression algorithms. Lossless Compression Lossy Compression 6

www. hndit. com Lossless Compression � Algorithms reduce file size without losing image quality

www. hndit. com Lossless Compression � Algorithms reduce file size without losing image quality � They are not compressed into as small a file as a lossy compression file. � When image quality is valued than file size, lossless algorithms are typically chosen. �because it lets you recreate the original file exactly. � All lossless compression is based on the idea of breaking a file into a "smaller" form for transmission or storage and then putting it back together on the other end so it can be used again. 7

www. hndit. com Lossy compression � This algorithms consider the limitations of the human

www. hndit. com Lossy compression � This algorithms consider the limitations of the human eye and discard invisible information. � Most lossy compression algorithms allow for variable quality levels (compression) � As these levels are increased File size is reduced. � At the highest compression levels, image weakening becomes noticeable � Lossy compression works very differently. 8

www. hndit. com Lossy compression… � These programs simply eliminate "unnecessary" bits of information,

www. hndit. com Lossy compression… � These programs simply eliminate "unnecessary" bits of information, so that it is smaller. � This type of compression is used a lot for reducing the file size of bitmap pictures, which tend to be fairly large. 9

www. hndit. com Lossy compression… Example: � If there is an image where whole

www. hndit. com Lossy compression… Example: � If there is an image where whole sky is blue, most of the individual pixels are a little bit different. � To make this picture smaller without compromising the resolution, you have to change the color value for certain pixels. � If the picture had a lot of blue sky, the program would pick one color of blue that could be used for every pixel. 10

www. hndit. com Lossy compression… � Then, the program rewrites the file so that

www. hndit. com Lossy compression… � Then, the program rewrites the file so that the value for every sky pixel refers back to this information. � If the compression scheme works well, you won't notice the change, but the file size will be significantly reduced. � with lossy compression, you can't get the original file back after it has been compressed. 11

www. hndit. com Compression Algorithms Algorithm Basic Concept Comp Ratio File Format Loss-Less Lossy

www. hndit. com Compression Algorithms Algorithm Basic Concept Comp Ratio File Format Loss-Less Lossy RLE (Run-Length Encoding) Compress repetitive data ~1. 2 BMP LZW (Lempel-Ziv-Welch) Build treed dictionary ~2. 0 TIFF, GIF DCT (Discrete Cosine Transformation Transform to series of Cosine functions ~100 JPEG, MPEG 1/2 Colour Space Compression Cut non-sensitive color information ~2 JPEG, (TV) Wavelet Transform to series of Wavelet functions ~100 JPEG 2000, MPEG 4 12

www. hndit. com Some General Concepts • Bit Rate and Compression Ratio – Bit

www. hndit. com Some General Concepts • Bit Rate and Compression Ratio – Bit rate: bits/pixel, sometimes written as bpp – Compression ratio (CR): CR = number of bits to represent the original image number of bits in compressed bit stream 13

Run Length Encoding (RLE) www. hndit. com � Many files, particularly image files, contains

Run Length Encoding (RLE) www. hndit. com � Many files, particularly image files, contains sequences of identical symbols. ◦ Eg. In an image, a section of many adjacent pixels may all be the same color. ◦ Be encoded with the same bit pattern. � RLE replaces sequence of identical bit patterns with ◦ one instance of the pattern, and ◦ a number specifying how many times the pattern is to be repeated. � Uses with BMP 14

www. hndit. com • Run Length Encoding – The length of consecutively identical symbols

www. hndit. com • Run Length Encoding – The length of consecutively identical symbols • Run length encoding Example • When Does it Work? – Images containing many runs of 1’s and 0’s • When Does it Not Work? 15

www. hndit. com Run Length Encoding • Decoding Example A binary image is encoded

www. hndit. com Run Length Encoding • Decoding Example A binary image is encoded using run length code row by row, with “ 0” represents white, and “ 1” represents black. The code is given by Row Row Row Row 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: “ 0”, 16 “ 0”, 7, 2, 7 “ 0”, 4, 8, 4 “ 0”, 3, 2, 6, 3, 2 “ 0”, 2, 2, 8, 2, 2 “ 0”, 2, 1, 10, 1, 2 “ 1”, 3, 10, 3 “ 0”, 2, 1, 10, 1, 2 “ 0”, 2, 2, 8, 2, 2 “ 0”, 3, 2, 6, 3, 2 “ 0”, 4, 8, 4 “ 0”, 7, 2, 7 “ 0”, 16 decode Decode the image 16

www. hndit. com Run Length Encoding • Decoding Example A binary image is encoded

www. hndit. com Run Length Encoding • Decoding Example A binary image is encoded using run length code row by row, with “ 0” represents white, and “ 1” represents black. The code is given by Row Row Row Row 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: “ 0”, 16 “ 0”, 7, 2, 7 “ 0”, 4, 8, 4 “ 0”, 3, 2, 6, 3, 2 “ 0”, 2, 2, 8, 2, 2 “ 0”, 2, 1, 10, 1, 2 “ 1”, 3, 10, 3 “ 0”, 2, 1, 10, 1, 2 “ 0”, 2, 2, 8, 2, 2 “ 0”, 3, 2, 6, 3, 2 “ 0”, 4, 8, 4 “ 0”, 7, 2, 7 “ 0”, 16 decode 17

www. hndit. com Chain Coding Assume the image contains only single-pixel-wide contours, like this,

www. hndit. com Chain Coding Assume the image contains only single-pixel-wide contours, like this, not this contour image After the initial point position, code direction only region image n 2 3 1 0 4 Code Stream: 7 (3, 2), 1, 0, 1, 1, 3, 3, 3, 4, 4, 5, 4 initial point position chain code 5 m 6 18

www. hndit. com Chain Coding • Decoding Example The chain code for a 8

www. hndit. com Chain Coding • Decoding Example The chain code for a 8 x 8 binary image is given by: 2 3 (1, 3), 7, 7, 0, 1, 1, 3, 3, 3, 1, 1, 0, 7, 7 decode 1 4 0 5 6 7 Decode the image 19

www. hndit. com Chain Coding • Decoding Example The chain code for a 8

www. hndit. com Chain Coding • Decoding Example The chain code for a 8 x 8 binary image is given by: 2 3 (1, 3), 7, 7, 0, 1, 1, 3, 3, 3, 1, 1, 0, 7, 7 decode 1 4 0 5 6 7 20

Variable Word Length Coding www. hndit. com Assign short words to gray levels that

Variable Word Length Coding www. hndit. com Assign short words to gray levels that occur frequently Assign long words to gray levels that occur infrequently Example: A 4 x 4 4 bits/pixel original image is given by Default Code Book 0: 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Bit rate = 4 bits/pixel Total # of bits used to represent the image: encode 4 x 16 = 64 bits 21

www. hndit. com Variable Word Length Coding: Example • Encode the original image with

www. hndit. com Variable Word Length Coding: Example • Encode the original image with a CODE BOOK given left Huffman Code Book 0: 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 00000001 0000010 0000011 0000100 01 0000101 10 00100 11 0000110 0000111 001010 0011 001011 Total # of bits used to represent the image: encode 4+2+2+2+2+2+5+2+2+4 = 39 bits Bit rate = 39/16 = 2. 4375 bits/pixel CR = 64/39 = 1. 6410 22

www. hndit. com Lempel-Ziv-Welch (LZW) � Dictionary based coding algorithm � Another Loss-Less compression

www. hndit. com Lempel-Ziv-Welch (LZW) � Dictionary based coding algorithm � Another Loss-Less compression algorithm. � It was not designed specifically for graphics � Data Dictionary is used to represent linear sequences of data in a uncompressed input stream. Then uses an algorithm similar to RLE. � It does not work well with black and white or true colour images. � Uses with GIF 23

www. hndit. com Color Space Compression � Uses human eye characteristics ◦ Less sensitive

www. hndit. com Color Space Compression � Uses human eye characteristics ◦ Less sensitive to color than lightness ◦ Less sensitive to Red than Green � YUV color space ◦ Originally developed for color TV signal ◦ Convert color to Luminance(Y) and � Chrominance (U, V) values Y=0. 299 R + 0. 587 G + 0. 114 B … Most sensitive color for human eyes U=(B-Y) V=(R-Y) 24

www. hndit. com Color Space Compression cont… � Reduce color information § Y: U:

www. hndit. com Color Space Compression cont… � Reduce color information § Y: U: V = 4: 2: 2 (TV) § Y: U: V = 4: 1: 1 (JPEG) § Y: U: V = 4: 1: 0 (JPEG) JPEG (1: 50) Y U V 25

www. hndit. com Mathematical Transformation � Convert images to mathematical functions ◦ Discrete Cosine

www. hndit. com Mathematical Transformation � Convert images to mathematical functions ◦ Discrete Cosine Transformation (DCT) �Use series of cosine functions to approximate image. �Use with JPEG, MPEG 1/2 ◦ Wavelet Transformation �Use wavelet function to approximate image. �Use with JPEG 2000, MPEG 4 Both are Lossy Compression Algorithms 26

www. hndit. com DCT vs Wavelet Algorithm Comparison Original Image (154 KB) Compress to

www. hndit. com DCT vs Wavelet Algorithm Comparison Original Image (154 KB) Compress to 3 KB (1: 50) DCT Wavelet 27

www. hndit. com Image Compression: Coding and Decoding original image 262144 Bytes image encoder

www. hndit. com Image Compression: Coding and Decoding original image 262144 Bytes image encoder compressed bitstream 00111000001001101… (2428 Bytes) image decoder compression ratio (CR) = 108: 1 28