Lossy Compression

27
Lossy Compression Trevor McCasland Arch Kelley

description

Lossy Compression. Trevor McCasland Arch Kelley. How Do I Lossy Compress?. Goal: reduce the size of stored files and data while retaining all necessary perceptual information Used to create an encoded copy of the original data with a (much) smaller size - PowerPoint PPT Presentation

Transcript of Lossy Compression

PowerPoint Presentation

Lossy CompressionTrevor McCaslandArch KelleyGoal: reduce the size of stored files and data while retaining all necessary perceptual informationUsed to create an encoded copy of the original data with a (much) smaller size

Compression Ratio = Uncompressed Size/Compressed SizeHow Do I Lossy Compress?Typical Compression RatiosGIF JPEG(low) JPEG(mid) JPEG(high) PNG4:1- 10:1- 30:1- 60:1- 10-30%10:1 20:1 50:1 100:1 smaller than GIF

The following JPEGs are compressed with different ratiosVisual Example

1:1(low) 1:10(low) 1:30(mid) 1:30 with 5XzoomLossy: Original data->Lossy Compressor ->Compressed DataReverse: Compressed Data->Decompressor ->Altered Data (not the same as original!)Lossless: Original data->Lossy Compressor ->Compressed DataReverse: Compressed Data->Decompressor ->Original Data (exactly the same!)Lossy is best used for data that we can afford to irreversibly alter (images, audio, video)Lossy Vs. Lossless- The DifferenceCommon techniques used in lossy compression methods include:Color spacing/chroma downsampling (images)QuantizationDiscrete cosine transform (DCT)Zigzag ordering and run-length encodingEntropy coding (Huffman coding)

Lossy Compression Tools

JPEG Process1) Image contents change slowly across the image, i.e., it is unusual for intensity values to vary widely several times in a small area, for example, within an 8x8 image block2) Humans are much less likely to notice the loss of very high spatial frequency components than the loss of lower frequency componentsHigh frequencies can be thrown out without noticeable change to the imageThe Human Eye- Observations3) Visual accuracy in distinguishing closely spaced lines is much greater for black and white than for colorTaken together, these three observations can be used to compress images in a way that reduces loss of visual quality while significantly downsizing the filesizeThe Human Eye- ObservationsA way of defining the boundaries in which an image can be represented using colorExamples: RGB, YCbCr, YPbPr, YUVRGB is most basic color space

Color Spacing

A pixels color is determined by its RGB (red blue green) valueEg. R=30, G=100, B=50Image formats using lossy compression often convert this data into a format that separates luminance (brightness) and chrominance (hue)Eg. Y = (R + G + B) / 3, Cb = B - Y Cr = R - Y

Color Spacing

Data of original image (top) isSeparated into luminance data(left) and chrominance data (right)*Operation takes O(1) time for each 8x8 block and is done on n blocks=> Running time O(n)Used to reduce the possible values that can be used to represent the chrominance of a pixelSpecific color spacing allows for chroma downsamplingThrow out portions of the chrominance (color) data in a group of pixels to reduce the total space usedUse the chroma from one part of the group to display the other part of the groupSource of data loss (lossy method)Chroma DownsamplingDifferent patterns exist for disposing of chrominance (UV values in figures) for portions or pixel groupsMost common is 4:2:24:4:4 is pointless because no data is being disposed (no downsampling occurs)Chroma Downsampling

4:2:2 sampling 4:1:1 sampling 4:2:1 sampling 4:4:4 samplingDCT main purpose is to remove redundancy of neighboring pixels to provide compressionThe transform maps the correlated data to transformed uncorrelated coefficientsDiscrete Cosine Transform

High compaction of informationDiscrete Cosine Transform

1D DCT-IIx[n] = original valueX[k]= transformed valueN= number of columnsk= transform coefficient1D-DCT-II1D-IDCT-IIDiscrete Cosine Transform2D DCTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1D-DCT

1D-DCT

Create an intermediateSequence by computing1D-DCT on rows

Compute 1D-DCTon the columns

Discrete Cosine Transform

The DCT coefficient matrix is UThe input coefficient matrix is AWhere

Discrete Cosine Transform

High information compaction at (0,0)

Inverse Discrete Cosine Transform

Each basis function is multipliedby its coefficient and then addedto the transformed image18complexityO(n ), running it2ntimes to build a 2D DCT with complexityO(n ).We can do better again by replacing theO(n )DCT algorithm with one factored similarly to a Fast Fourier Transform which would haveO(nlogn)complexity.

O(2n*nlogn) = O(n logn)Discrete Cosine Transform

Reduce the range of values used to represent image/audio dataSimilar to chroma downsampling, but applied to a full array of valuesAchieved by multiplying a constant quantization matrix with the DCT coefficient matrix Quantization matrix can be user-definedCan adjust quantization level (throw out more or less data) by altering matrixQuantizationQuantization Example

XQ=round(Xn,m/Qn,m)

X=Q=XQ=

Ex:Time complexity: O(n2) where n=#columns and rows (n2 O(1) operations)Main source of data loss in lossy compression algorithmsOnly works on data represented using frequenciesEncoder uses different quantization levels for different frequencies based on human vision preferencesUsually results in a much smaller filesize (typical JPEG compression ratio is 30:1)Quantization DetailsReorder quantized matrix to put non-zero elements in a sortable sequenceFinal Steps: Zig-Zag Ordering

-26-3 0-3 -3 -62 4 1 -41 1 5 1 2-1 1 -1 2 0 00 0 0 -1 -1 0 00 0 0 0 0 0 0 00 0 0 0 0 0 00 0 0 0 0 00 0 0 0 00 0 0 00 0 00 00[-26, -3 0, -3, , -1, 0, 0]

--Do not store zeroes afterfinal element in zigzag rowwith a non-zero elementSimple method of storing similar data using a single value and a run lengthEx:Final Steps: Run-Length EncodingWWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWbecomes12W1B12W3B24W1B14WTime complexity: O(n) where n=# of characters in string24RLE string is entropy coded to add an extra layer of compression/further reduce filesizeEntropy coding is a lossless methodCommon algorithm used is Huffman CodingMakes trees that look like:Final Steps: Entropy Coding

*Not important to understand lossy compressionJPEGLossy image filetype that follows the process exactlyMPEG-2Uses chroma downsampling and different quantization values to adjust level of compressionStreaming video lets users adjust qualityMP3Quantization removes frequencies that humans cant hear by rounding them to zeroMany, many moreApplicationsQuestions?-Where does the loss of data actually occur?-Why do highly compressed images look blocky?-What flaws appear in highly compressed audio?-How long does it take to learn all of this?O(nn) timeObligatory Question Slide