Numerical Analysis. Carmen Arévalo Lund University Arévalo FMN011

Similar documents
Compression. Reality Check 11 on page 527 explores implementation of the MDCT into a simple, working algorithm to compress audio.

Number Representation and Waveform Quantization

Multimedia & Computer Visualization. Exercise #5. JPEG compression

Image Compression. 1. Introduction. Greg Ames Dec 07, 2002

Singular Value Decompsition

Image Compression Using the Haar Wavelet Transform

Justify all your answers and write down all important steps. Unsupported answers will be disregarded.

Multimedia Networking ECE 599

8 The SVD Applied to Signal and Image Deblurring

MAT 343 Laboratory 6 The SVD decomposition and Image Compression

6 The SVD Applied to Signal and Image Deblurring

8 The SVD Applied to Signal and Image Deblurring

Compression. What. Why. Reduce the amount of information (bits) needed to represent image Video: 720 x 480 res, 30 fps, color

Wavelets and Multiresolution Processing

2. the basis functions have different symmetries. 1 k = 0. x( t) 1 t 0 x(t) 0 t 1

6.003: Signals and Systems. Sampling and Quantization

Mathematical Beer Goggles or The Mathematics of Image Processing

Problem Set 8 - Solution

BASICS OF COMPRESSION THEORY

BASIC COMPRESSION TECHNIQUES

Robot Image Credit: Viktoriya Sukhanova 123RF.com. Dimensionality Reduction

What is Image Deblurring?

Image Compression. Fundamentals: Coding redundancy. The gray level histogram of an image can reveal a great deal of information about the image

Image Compression. Qiaoyong Zhong. November 19, CAS-MPG Partner Institute for Computational Biology (PICB)

Source Coding for Compression

Compressing a 1D Discrete Signal

4x4 Transform and Quantization in H.264/AVC

Image Acquisition and Sampling Theory

Wavelets and Image Compression. Bradley J. Lucier

Learning goals: students learn to use the SVD to find good approximations to matrices and to compute the pseudoinverse.

18.085: Summer 2016 Due: 3 August 2016 (in class) Problem Set 8

RLE = [ ; ], with compression ratio (CR) = 4/8. RLE actually increases the size of the compressed image.

Department of Electrical Engineering, Polytechnic University, Brooklyn Fall 05 EL DIGITAL IMAGE PROCESSING (I) Final Exam 1/5/06, 1PM-4PM

Product Obsolete/Under Obsolescence. Quantization. Author: Latha Pillai

From Fourier Series to Analysis of Non-stationary Signals - II

Compressing a 1D Discrete Signal

on a per-coecient basis in large images is computationally expensive. Further, the algorithm in [CR95] needs to be rerun, every time a new rate of com

Overview. Analog capturing device (camera, microphone) PCM encoded or raw signal ( wav, bmp, ) A/D CONVERTER. Compressed bit stream (mp3, jpg, )

Improvement of DCT-based Compression Algorithms Using Poisson s Equation

Image Compression - JPEG

Lossless Image and Intra-frame Compression with Integer-to-Integer DST

encoding without prediction) (Server) Quantization: Initial Data 0, 1, 2, Quantized Data 0, 1, 2, 3, 4, 8, 16, 32, 64, 128, 256

4. Quantization and Data Compression. ECE 302 Spring 2012 Purdue University, School of ECE Prof. Ilya Pollak

Scientific Computing: An Introductory Survey

CHAPTER 3. Transformed Vector Quantization with Orthogonal Polynomials Introduction Vector quantization

Basic Principles of Video Coding

A study of image compression techniques, with specific focus on weighted finite automata

Proyecto final de carrera

L. Yaroslavsky. Fundamentals of Digital Image Processing. Course

Numerical Analysis FMN011

Analysis of Fractals, Image Compression and Entropy Encoding

CSE 408 Multimedia Information System Yezhou Yang

HOSVD Based Image Processing Techniques

8/13/16. Data analysis and modeling: the tools of the trade. Ø Set of numbers. Ø Binary representation of numbers. Ø Floating points.

IMAGE COMPRESSION-II. Week IX. 03/6/2003 Image Compression-II 1

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

repetition, part ii Ole-Johan Skrede INF Digital Image Processing

Introduction to Machine Learning

SYDE 575: Introduction to Image Processing. Image Compression Part 2: Variable-rate compression

( nonlinear constraints)

Image compression. Institute of Engineering & Technology, Ahmedabad University. October 20, 2015

Matrix decompositions

Singular Value Decomposition and Digital Image Compression

Linear Algebra Linear Algebra : Matrix decompositions Monday, February 11th Math 365 Week #4

Image Compression Using Singular Value Decomposition

CHAPTER 4 PRINCIPAL COMPONENT ANALYSIS-BASED FUSION

COSC460 Honours Report. A Fast Discrete Tchebichef Transform Algorithm for Image Compression

Numerical Methods I Orthogonal Polynomials

A Variation on SVD Based Image Compression

Applied Linear Algebra in Geoscience Using MATLAB

Principal Component Analysis

EE16B - Spring 17 - Lecture 12A Notes 1

Module 4. Multi-Resolution Analysis. Version 2 ECE IIT, Kharagpur

Lec 04 Variable Length Coding (VLC) in JPEG

3.2 Gaussian Elimination (and triangular matrices)

Derivation of the Kalman Filter

JPEG Standard Uniform Quantization Error Modeling with Applications to Sequential and Progressive Operation Modes

Module 2 LOSSLESS IMAGE COMPRESSION SYSTEMS. Version 2 ECE IIT, Kharagpur

Two-Dimensional Signal Processing and Image De-noising

ECE472/572 - Lecture 11. Roadmap. Roadmap. Image Compression Fundamentals and Lossless Compression Techniques 11/03/11.

Lecture 6. Numerical methods. Approximation of functions

Matrix decompositions

! Where are we on course map? ! What we did in lab last week. " How it relates to this week. ! Compression. " What is it, examples, classifications

EM Algorithm & High Dimensional Data

Reduced-Error Constant Correction Truncated Multiplier

Laplacian Filters. Sobel Filters. Laplacian Filters. Laplacian Filters. Laplacian Filters. Laplacian Filters

2.3. Clustering or vector quantization 57

Digital Image Processing Lectures 25 & 26

IMAGE COMPRESSION IMAGE COMPRESSION-II. Coding Redundancy (contd.) Data Redundancy. Predictive coding. General Model

The Laplace Expansion Theorem: Computing the Determinants and Inverses of Matrices

The Basis. [5] The Basis

Image Data Compression

THE newest video coding standard is known as H.264/AVC

Citation Ieee Signal Processing Letters, 2001, v. 8 n. 6, p

Data Mining and Matrices

Wavelets. Lecture 28

The discrete and fast Fourier transforms

The Haar Wavelet Transform: Compression and. Reconstruction

Lecture 12 (Tue, Mar 5) Gaussian elimination and LU factorization (II)

Can the sample being transmitted be used to refine its own PDF estimate?

Transcription:

Numerical Analysis Carmen Arévalo Lund University carmen@maths.lth.se

Discrete cosine transform C = 2 n 1 2 1 2 1 2 cos π 2n cos 3π 2n cos (2n 1)π 2n cos 6π 2n cos 2(2n 1)π 2n cos 2π 2n... cos (n 1)π 2n cos (n 1)3π 2n cos (n 1)(2n 1)π 2n The DCT of x is the vector y = Cx C is a real orthogonal matrix. The DCT involves only real computations and consists only of cosines. 1

Trigonometric interpolation with satisfies P (t) = 1 n y 0 + 2 n n 1 k=1 y = Cx y k cos P (j) = x j, j = 0,..., n 1. k(2t + 1)π 2n Like the DFT, the DCT transforms n data points into n interpolation coefficients. 2

Least squares with DCT Like for the DFT, the choice of m < n coefficients y 0,..., y m 1 in 1 n y 0 + 2 n m 1 k=1 y k cos k(2t + 1)π 2n gives the best approximation in the 2-norm. 3

2D discrete cosine transform Applying the DCT to a matrix of data (e.g. a pixel file), first in a vertical direction and then in a horizontal direction, we can use the DCT in image processing. The human eye does not distinguish the higher visual frequencies, so here we will also be interested in compressing by doing a least squares that eliminates the higher frequencies. Convention: Each point is represented by a pair (s, t), where s is the vertical coordinate and t the horizontal component. We start the numeration at 0. 4

Each point (s i, t j ) has a corresponding value x ij. 5

Matrix form of the 2D DCT and its inverse The 2D DCT constructs an interpolating function F (s, t) that interpolates the n 2 points (s i, t j, x ij ). Let the matrix X contain the values x ij. 1. Apply the DCT in the horizontal t direction. Each column of CX T corresponds to a fixed s i. 2. Apply the DCT in the vertical s direction, Y = C(CX T ) T = CXC T. Y = CXC T X = C T Y C 6

2D-DCT interpolation and least squares The inverse of the transform performs an interpolation, just like for the DFT. The 2-dimensional trigonometric polynomial that satisfies P (i, j) = x ij for i, j = 0,..., n 1 is P (s, t) = 2 n n 1 k=0 n 1 l=0 y kl a k a l cos k(2s + 1)π 2n cos l(2t + 1)π 2n where a 0 = 1/ 2 and a k = 1 for k > 0. Least squares is done in the same way as for the 1D-DCT. 7

The DCT in Matlab >> y = dct(x) When x is a matrix it does the DCT of each column of x. Matlab does not use the DCT matrix to compute the DCT transform, it maximizes efficiency by using the FFT. We can get the DCT matrix from >> C = dct(eye(n)) To do the 2D-DCT transform, >> Y = dct2(x) 8

Image compression Images consist of pixels, represented by numbers (or vectors for color images). DCT least squares reduces the information (bits) required while maintaining the quality of the picture to the human eye. A grayscale picture represents the grayness of each pixel by an integer between 0 and 255. A picture containing n m pixels will have n m integers of information. To import a picture in Matlab and get its matrix >> ximage = imread( picture_name.jpg ); >> x = double(ximage); 9

Example in Matlab Grayscale picture with pixels in a 306 224 grid. 10

To get the image matrix: >> xin = imread( hippo1.jpg ); To render the grayscale image in Matlab: >> imagesc(xin) >> colormap(gray) >> axis image When working with the image matrix it is a good practice to subtract 128 (256/2) in order to center the values around 0. This contributes to better numerical stability. To convert back to JPG: >> x = double(xin); >> x=uint8(x); 11

>> imwrite(x, hippo2.jpg, jpg ) 12

Crude compression: replace each 4 3 pixel block by its average value xc=x1-128; for i=1:56 for j=1:102 A=xc(4*(i-1)+1:4*i,3*(j-1)+1:3*j); mv=mean(mean(a)); xc(4*(i-1)+1:4*i,3*(j-1)+1:3*j)=mv; end end xc=xc+128; Goes from 68,544 bytes of information to 5,712. 13

Grayscale picture with pixels in a 102 56 grid. Compressed by averaging. 14

DCT compression x1 = imread( hippo1.jpg ); x1=double(x1); xc=x1-128; for i=1:56 for j=1:102 A=xc(4*(i-1)+1:4*i,3*(j-1)+1:3*j); Y=dct2(A); Y(1,3)=0; Y(2,2:3)=0; Y(3:4,:)=0; Y=round(Y); xc(4*(i-1)+1:4*i,3*(j-1)+1:3*j)=idct2(y); end end xc=xc+128; xc=uint8(xc); imwrite(xc, hippo3.jpg, jpg ) 15

Grayscale picture with pixels in a 102 56 grid. Compressed by 2D-DCT. 16

Quantization Instead of zeroing the lower right hand side of the transform matrix we assign fewer bits to store the information there. We want to compress a range of values to a single value. To do this we do the following: z = round(y/q) (rounding to the nearest integer) y q = qz For instance, if we quantize the numbers between 30 and 33 modulo 4, 4 round([30 31 32 33]/4) = 4 round[7.5 7.75 8 8.25] = 32 The size of the maximum error is q/2 = 2. In the example above, the maximum error occurs when y = 30 and it is equal to -2. 17

Quantization matrix The matrix Q formed by the numbers q kl that regulate how many bits are assigned to each entry of the transform matrix Y is the quantization matrix. Matrix Y is replaced by the compressed matrix Y Q = round ( ykl The rounding is where the loss occurs and makes this method a lossy compression. To decompress, the elements of Y Q are multiplied by the corresponding elements of Q. The larger q kl, the more the loss and the greater the compression. q kl ) 18

Linear quantization We will now work with quantization matrices of dimension 8 8. Linear quantization is defined by for the loss parameter p. q kl = 8p(k + l + 1) for 0 k, l 7 A small loss parameter gives a better reconstruction (less compression). The Hilbert matrix has entries h kl = 1/(k + l + 1) and can be used directly for linear quantization in Matlab: >> Yq = round(y.*hilb(8)/(8*p)); To reconstruct, we need to divide pointwise by the Hilbert matrix: >> Xq = 8*p*Yp./hilb(8); 19

Hilbert matrix The Hilbert matrix acts as a low pass filter, reducing the value of the coefficients of the higher frequencies. These are located in the lower right corner of the transform matrix. 1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9 1/3 1/4 1/5 1/6 1/7 1/8 1/9 1/10 1/4 1/5 1/6 1/7 1/8 1/9 1/10 1/11 1/5 1/6 1/7 1/8 1/9 1/10 1/11 1/12 1/6 1/7 1/8 1/9 1/10 1/11 1/12 1/13 1/7 1/8 1/9 1/10 1/11 1/12 1/13 1/14 1/8 1/9 1/10 1/11 1/12 1/13 1/14 1/15 20

For instance, if one of the 8 8 submatrices is A = 40 40 40 37 39 36 41 38 193 195 159 34 25 29 43 35 229 224 194 34 33 29 29 27 225 224 211 24 44 36 19 32 19 29 42 238 226 136 29 13 16 32 62 223 228 143 29 24 18 26 60 234 238 150 24 20 14 16 50 227 228 143 16 15 21

after undergoing linear quantization with p=2 becomes 3 1 1 1 0 0 0 0 6 4 2 0 0 0 0 0 5 4 2 0 0 0 0 0 4 3 2 0 0 0 0 0 0 0 0 2 2 1 0 0 0 0 0 2 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 0 0 22

Best quantization matrix The matrix that experimentally gives the best results for the human eye is Q Y = p 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 It gives almost perfect reconstruction for p = 1. 23

Compression due to quantization p bits/pixel 0 8 1 3.89 2 2.98 4 2.30 24

Color images Each pixel is assigned 3 numbers, for red, green and blue intensity. The matrix of a color image is a tensor of dimension n m 3. One way to treat color compression is to work independently with the matrix for each color (R, G and B) and then reassemble the tensor. There are more sophisticated ways of dealing with this problem, in particular by defining three matrices Y = 0.299R + 0.587G + 0.114B U = B Y V = R Y, applying a certain quantization matrix to each and then reassembling. 25

Lossless compression Lossy compression occurs because of quantization of the transform matrix. There is a tradeoff between the amount of compression and the amount of accuracy. The smaller the resulting file, the bigger the loss of accuracy. After quantization, we can further compress without losing any more accuracy. This is done by efficient coding of the transformed image. 26