Top Banner
Optimising JPEG image compression by identifying image characteristics Simon Wahlstrom Computer Science VU University Amsterdam and Mälardalens University A thesis submitted for the degree of Computer Science Track Software Engineering and Green IT 2015
65

Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

Jun 07, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

Optimising JPEG imagecompression by identifying image

characteristics

Simon Wahlstrom

Computer Science

VU University Amsterdam and Mälardalens University

A thesis submitted for the degree of

Computer ScienceTrack Software Engineering and Green IT

2015

Page 2: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

“The problem with quotes on the Internet is that you can’t always be sure of theirauthenticity.” - Gandhi

ii

Page 3: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

1. First Reader: Patricia Lago

2. Daily Supervisor: Thomas Larsson

3. Second Reader: Thomas Larsson

4. Industrial Supervisor: Jacob Middag

iii

Page 4: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

Abstract

The JPEG image format has been around for decades. During the years,JPEG compression has evolved tremendously to decrease image file size andat the same time keeping acceptable perceivable quality. JPEG compres-sion allows the user to make a trade-off between image file size and imagequality. However, it can be hard to find a good balance between file sizeand image quality. Imagine that we host a website containing millions ofimages. If we do not compress the images the website will most likely bevery slow. However, if we compress the images too much then the imageswill look bad. Therefore, the goal of this thesis is to find close to optimalcompression rate for any given image to solve this problem. The thesis willpresent an approach on how to balance this trade-off between size and qual-ity by identifying certain characteristics in an image (e.g., luminance, colors,frequencies) and then use them as a metric to estimate how to balance thecompression before the compression takes place. The thesis will give a stateof the art analysis of how JPEG works and how the things we see in imagesrelates to the Human Visual System. Finally, the method and experimentsused for creating the estimation formula on how to find the best possiblecompression will be presented.

Page 5: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

I dedicate this thesis to two of the most important women in my life,namely Johanna and Saga. Without you neither my stay in the

Netherlands or this thesis would have happened.

Page 6: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

Acknowledgements

I would like to thank all my colleagues at Voormedia for making my timeduring this internship so pleasant. I have learnt more about the Netherlandsand the Dutch customs during my time here than I have during my entirestay in the Netherlands. I would also like to give a special thank you toJacob, Rolf and Jippe for the excellent support during the research. Finally,I would like to thank my Coordinator Patricia for helping me get this projectand my daily supervisor Thomas for his support.

Page 7: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

Contents

List of Figures v

List of Tables vii

1 Introduction 1

1.1 Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.3 Solution / Master thesis assignment . . . . . . . . . . . . . . . . . . . . 3

1.4 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.5 Research questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.5.1 JPEG Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.5.2 Characteristics analysis and validation . . . . . . . . . . . . . . . 4

2 Background 7

2.1 Understanding JPEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.1.1 JPEG background . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.1.2 Lossy and Lossless Compression . . . . . . . . . . . . . . . . . . . 8

2.1.3 Color Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2.1.4 Subsampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.1.5 Discrete Cosine Transform . . . . . . . . . . . . . . . . . . . . . . 10

2.1.6 Variable Length Encoding . . . . . . . . . . . . . . . . . . . . . . 11

2.1.6.1 Huffman Encoding . . . . . . . . . . . . . . . . . . . . . 12

2.1.6.2 Arithmetic Encoding . . . . . . . . . . . . . . . . . . . . 12

2.2 Human Visual System . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3 Related Work 15

iii

Page 8: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

CONTENTS

4 Method 19

4.1 Research Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

4.2 Image Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

4.3 JCEE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4.4 Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

4.4.1 Experiment 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

4.4.2 Experiment 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

4.4.3 Experiment 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

5 Results 27

5.1 Characteristics Validation . . . . . . . . . . . . . . . . . . . . . . . . . . 29

5.2 Experiment results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

5.2.1 Experiment 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

5.2.2 Experiment 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

5.2.3 Experiment 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

5.2.4 Characteristics evaluation . . . . . . . . . . . . . . . . . . . . . . 39

5.2.5 Final algorithm results . . . . . . . . . . . . . . . . . . . . . . . . 42

6 Discussion, Conclusions and Future work 47

6.1 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

6.2 Conclusions and Future work . . . . . . . . . . . . . . . . . . . . . . . . 48

7 References 51

iv

Page 9: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

List of Figures

1.1 The simplified explanation of JPEG compression. . . . . . . . . . . . . 3

2.1 Color conversion from RGB to YCbCr [11] . . . . . . . . . . . . . . . . . 9

2.2 How subsampling affects an image. [25] . . . . . . . . . . . . . . . . . . 10

2.3 Image "A" in spatial-domain [27] . . . . . . . . . . . . . . . . . . . . . . 11

2.4 Image "A" represented as a DCT matrix in frequency-domain after ap-plying DCT [27] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.5 Huffman code tree [26] . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

4.1 Experiment view of JCEE . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5.1 Main window of JCEE . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

5.2 Main window of JCEE . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

5.3 All characteristics for 1.jpg (X = Compression rate, Y = characteristicvalue) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

5.4 Frequencies for 1.jpg (X = Compression rate, Y = characteristic value) 35

5.5 Percentage of high frequencies, Y = frequency percentage and X = com-pression rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

5.6 Percentage of middle frequencies, Y = frequency percentage and X =compression rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

5.7 Percentage of low frequencies, Y = frequency percentage and X = com-pression rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

5.8 The correlation between the percentage of high frequencies and the com-pression rate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

5.9 Correlation between the percentage of high frequencies and the compres-sion rate. The lines represent the acceptable compression rate area. . . 43

v

Page 10: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

LIST OF FIGURES

5.10 The percentage of high frequencies relation to the average compressionrate. Green = good estimation, yellow = decent estimation and red =bad estimation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

vi

Page 11: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

List of Tables

5.1 The results from all of the users in experiment 1 . . . . . . . . . . . . . 32

5.2 The results from experiment 3 of the first nine images with colors omitted. 36

5.3 Diagram for the 10 images that compressed the worst: . . . . . . . . . . 37

5.4 Diagram for the 10 images that compressed the best: . . . . . . . . . . . 37

5.5 Mean values for the 10 images that handle compression the worst . . . . 40

5.6 The mean values for the 10 images that handle compression the best . . 40

5.7 User satisfaction level of compressed images with low tolerance . . . . . 45

5.8 User satisfaction level of compressed images with high tolerance . . . . . 45

vii

Page 12: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

LIST OF TABLES

viii

Page 13: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

1

Introduction

1.1 Context

One thing that we humans always desire is for things to go faster and be more reliable.When we think about making online media faster we usually direct our thoughts towardsbeing able to view, interact and download files with higher speed. One way of achievingthis would be to optimise the way we compress images. If the file size of images that weinteract with gets smaller but keeps the quality then this would mean that they wouldload faster, giving the user a better experience.

Voormedia is a company based in the north of Amsterdam. They handle several projectsincluding TinyPNG and TinyJPG. Both TinyJPG and TinyPNG are image compressionservices. They are currently looking for a way to improve the way that JPEG imagesare being compressed. JPEG is a lossy[8] compression that splits the image up in 8x8pixel blocks and uses the Discrete Cosine Transformation to remove high frequencies inthe image. The successfulness of the compression of the image lies in the fact that thehuman eye is less sensitive to high frequencies which can be quantised away by reducingthe image quality without reducing the perceived quality.

There is no golden quality setting. Some images can be compressed enormously withJPEG while others give strange artefacts1 at even modest qualities. This is why Voor-media would like to research if it is possible to use certain characteristics within animage and use the characteristics to find the best input parameters for the compression.Voormedia is currently compressing an image several times and then using an errormetric to determine which image is the best with respect to quality and file size. Whatthey would like to do is to have a more precise way of knowing how much to compressan image before the compression takes place.

This master thesis will focus on trying to find a way to measure certain characteristicsof a JPEG image to be able to find the best possible compression rate. This work

1An artefact is a media distortion that did not exist before the compression

1

Page 14: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

1. INTRODUCTION

is structured as follows: First, the problems of compressing images will be explainedfollowed by how this thesis intends to solve these problems. After this, the scope,research questions and the research approach will be presented. Followed by this is therelated work section where the thesis presents other projects with similar goals followedby a state of the art analysis on JPEG itself as well as the Human Visual System. Afterthis the method section of the thesis will be presented. This section will go more intodepth of the characteristics that the thesis intends to research and how to use them.Finally, the results, the discussion, the conclusion and the future work section will bepresented.

1.2 Problem

JPEG images uses lossy compression. This means that when we compress the imagewe will throw away some of the information which usually leads to an overall lowerquality and size of the image. The problem is finding the right compression rate. Ifwe simplify the JPEG algorithm a little then we can say that JPEG uses 4 basic steps:Color conversion, Subsampling, Block-processing with Discrete Cosine Transformationand Variable length encoding. The first step changes the representation of colors in theimage. The second step exploits one of the human eye’s weaknesses, namely that it isless sensitive to the chrominance information in an image than it is to the luminance.Some of the chrominance information of the image can therefore be removed. Duringthe third step, all the pixels of the image are divided into blocks consisting of 8x8pixels. These blocks will then be transformed into the frequency-space by the DiscreteCosine Transformation. This will transform the block and separate the low and highfrequencies. Because of this, we can then apply quantisation, which will allow us toremove high frequencies which the human eye cannot see. This is where the most ofthe actual compression takes place. The last step will reorder the data that is left inthe blocks of the image for optimal storage. It is possible for the user to give input toboth the second and third step when using an existing JPEG encoder. Depending onthe input parameters, the image will be compressed to a certain amount. These stepscan be seen in figure 1.1.

The problem is that there is no good way of knowing how much we should compressan image to retain good perceived quality. Using the same compression settings on twodifferent images can yield different results. There might be no visual loss of quality inthe first image while the second image can look very poor for the human eye.

In conclusion, the JPEG compression algorithm can be very efficient for certain imagesbut it all depends on the information in the image. There is no "shortcut" to findthe best compression setting and obtaining the best possible quality after the compres-sion. This is something that Voormedia would like to research. By looking at differentcharacteristics of an image it might be possible to determine the best possible imagecompression, i.e., having the smallest file size but still maintaining an acceptable image

2

Page 15: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

1.3 Solution / Master thesis assignment

Figure 1.1: The simplified explanation of JPEG compression.

quality. This thesis focuses on trying to identifying these characteristics and then usethem to find a close to optimal way of compressing images using JPEG compression.

1.3 Solution / Master thesis assignment

The hypothesis to the previous mentioned problem could be to research different char-acteristics that appear in different JPEG images. This information might then be usedfor finding the best possible compression rate. These characteristics can be the resolu-tion, aspect ratio, image contents, lighting, pixel density, amount of edges and more.By identifying and analysing these characteristics it may be possible to write an algo-rithm to calculate how to optimise the JPEG image compression for the best qualityand smallest size. Therefore, promising characteristics will be selected and then testedtogether with different compression rates to see how they affect the overall compressionof an image. We can also select a large quantity of images and manually measure theselected characteristics on each image to see if there is any obvious relation betweencharacteristics and perceivable quality after compression.

1.4 Scope

The scope of the project focuses on identifying characteristics of images such as lu-minance, color range, number of edges, file size, frequencies etc. By identifying thesecharacteristics, this project intends to find the best possible compression rate for animage while keeping as high as possible visual quality. This process is going to be donebefore the actual compression is invoked.

If time allows it, the possibility of compressing different parts of an image with differentcompression rates will also be researched. This is something that could improve boththe file size and the visual quality of an image since different parts of images can handle

3

Page 16: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

1. INTRODUCTION

compression differently depending on the specific characteristics in that part of theimage.

1.5 Research questions

1. Is it possible to find a close to optimal compression rate for JPEG images bymeasuring different characteristics?

1.1 Which characteristics can we benefit from measuring in a JPEG image (Filesize, amount of edges, amount of colours used, monochromatic areas, regularpatterns etc.) for finding the best possible compression rate?

1.2 How can we identify the distinct characteristics from JPEG images and usethem as a metric? E.g., would it be possible to determine if the current blockcontains an "edge" or if it contains a certain color in an image and use thatinformation when compressing the image?

1.3 How can we use the metric identified in the characteristics of an image todecide to which degree images should be subsampled and compressed?

2. How can we validate the algorithms that generate the selected metric to ensurethat the results are correct? How can we validate the success rate of the estimatedcompression rate from the final algorithm?

In order to find answers to the above-mentioned research questions, the following ap-proaches will be taken.

1.5.1 JPEG Analysis

Researching how JPEG works and getting a deeper understanding for the actual com-pression will help answering the main research question. By studying how the compres-sion rate affects a JPEG image and measuring the different characteristics it becomespossible to gain insight on how and which characteristics might affect the compressedimage. Research question 5 will be answered by looking at different validation methodsto ensure the algorithms correctness.

1.5.2 Characteristics analysis and validation

Research questions 1.1, 1.2 and 1.3 can be answered by studying the characteristics ofimages. When a characteristic is deemed important it can be turned into a metric whichcan be used for finding the close to optimal compression rate for a given image. Theresult needs to be validated to be sure that the metrics holds for all different kinds ofJPEG images.

4

Page 17: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

1.5 Research questions

The second main research question can be answered by taking the aspects of algorithmengineering into account. This includes the process of analysing, designing, implement-ing, debugging and experimental evaluating of the algorithms [22]. It is important thatour algorithms that extracts the selected characteristics and turns them into a metricbehaves correctly. It is also important that we can verify the success rate of the finalalgorithm. This can be done by benchmarking the results against Voormedia’s ownresults as well as other sources.

5

Page 18: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

1. INTRODUCTION

6

Page 19: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

2

Background

This section will cover two important parts. First, the JPEG image compression stan-dard will be explained. It is important that we understand how JPEG works to beable to analyse which characteristics might be interesting to look at when trying to findthe almost optimal compression rate for an image. This section will also look into theHuman Visual System (HVS). The HVS is directly related to how we humans view animage. This is highly important when working with compression of images that is goingto be viewed and interpreted by humans.

2.1 Understanding JPEG

2.1.1 JPEG background

The Joint Photographic Experts Group (JPEG) is a committee founded in 1986 [10].Their goal was to create a standard for image compression. At the time, most computersdid not have as much storage as we have today and therefore could not handle largefiles in an efficient way. To solve this, a universal standard was needed for storing imagefiles in a compressed format. Almost 30 years later, the JPEG image file format is stillone of the most common image types on the web.

So what makes the JPEG image file format so successful? The reason is simple. It isnot unusual for a JPEG image to be compressed to one eighth of its original size andstill maintain good visible quality [6]. JPEG uses a compression technique that allowslarge image files to be compressed to a much smaller size without loosing visible qualityof the image. This makes JPEG images an excellent file format for storing images.

The JPEG compression has a simple goal. We want it to take a large file and compressit to a smaller file without loosing too much visible quality to make it easier to transportand/or store. When displaying webpages, text files are much smaller than images andwe therefore need to compress the images to achieve acceptable loading times.

7

Page 20: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

2. BACKGROUND

2.1.2 Lossy and Lossless Compression

There has been several image compression techniques developed during the years withintwo main categories: “Lossy” and “Lossless” compression. When using “lossy” imagecompression, we “throw away” information during the compression to make the imagesmaller. “Lossless” on the other hand does the exact opposite. “Lossless” compresses theimage without loosing any information. JPEG is a “lossy” format. This means that thedecompressed image is not really the same image as the one you started with. JPEGcompression takes advantage of the limitations of the human eyes, namely, the factthat small color changes are perceived less accurately than small changes in brightness.However, if we analyse images automatically with a machine instead of human eyes,then the small errors that JPEG produces will be a problem, even if the human eyescannot se them.

With “Lossless” compression, the algorithm tries to make the information as compact aspossible without loosing any information. So why would we want to use “lossy” compres-sion? The reason for this lies in the allure of the JPEG compression. The informationthat we throw away is usually something that the human eyes cannot see. Therefore,the image will still have a high quality but the size will be reduced significantly.

Something that makes JPEG’s lossy compression even more useful is the possibilityto adjust the compression parameters. By doing so, we can make a trade-off betweenimage quality and size. If we can accept low quality then we can make the images verysmall. If it is more important to have an accurate image that is going to be processedby a machine and the size is not a problem, then we simply increase the quality byreducing the compression rate.

When compressing a JPEG image, the user is usually given the ability to decide aquality setting that controls the degree of how much the image is going to be compressed.However, there seems to be some confusion regarding these quality settings. The qualityrange is between 1 and 100. Choosing a quality setting of 50 does not mean that youwill keep 50% of the information. The quality scale is actually quite arbitrary.

Another extraordinary ability that JPEG compression provides is that the decodersi.e., the program showing the image to the user, can make a trade-off decoding speedagainst image quality. It is possible to use fast but inaccurate approximations to therequired calculations. By doing this, we can obtain remarkable speedups when decodingthe image[9].

2.1.3 Color Conversion

With the JPEG algorithm, it becomes possible to encode images that use any typeof color space. This is possible since JPEG encodes all components in a color modelseparately, completely independent of any color space model. Some typical color spacemodels[11] include HSI, RGB and CMY. Using the YUV or YCbCr[17] color spaceyields the best result for JPEG image compression. The reason for this lies in the

8

Page 21: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

2.1 Understanding JPEG

fact that human eyes are much more sensitive to the visual information contained inthe high-frequency grey-scale component Y. The other components, Cb Cr are chromi-nance components, which contain high-frequency color information that our eyes areless sensitive to. Therefore, by using YCbCr, and dividing them into three differentmatrices (see figure 2.1), we can separate information from the CbCr components with-out affecting the visual outcome. The color conversion itself does not lead to any datareduction.

Figure 2.1: Color conversion from RGB to YCbCr [11]

2.1.4 Subsampling

As mentioned in previous section, the human eyes are much less sensitive to differencesin the chrominance. One way to quickly reduce an image’s size is to subsample thechrominance components. This can be achieved by simply using fewer pixels in thechrominance channels. The chrominance components are usually reduced 2:1 both ver-tically and horizontally. This is known as 4:2:2 subsampling (4:4:4 is no subsampling).As an example, we imagine an image with the resolution of 1000x1000 pixels. We thentransform the image to only use 500x500 pixels for the chrominance component butkeep the 1000x1000 pixels for the luminance component. Thus, each chrominance pixelwill now cover the same area as a 2x2 luminance block. This can be seen in figure 2.2.What is truly interesting is that this 50% reduction of the chrominance components hasvery little to no effect on the perceived quality when viewed by the human eyes.

9

Page 22: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

2. BACKGROUND

Figure 2.2: How subsampling affects an image. [25]

2.1.5 Discrete Cosine Transform

One important part of the JPEG compression is the Discrete Cosine Transform orDCT. There are several versions that can be used of the DCT function but the mostcommon one is DCT-II[12]. When we use DCT, values with the lowest frequency will beclustered around the upper-left corner of the DCT matrix. When performing the DCTtransformation, we divide the image into blocks. The standard size of the blocks are8x8 pixels. This number might look arbitrary, which it actually is. There are however afew reasons for using this block size. First, if the blocks were smaller, the compressionwould be more troublesome to perform. It would also take longer for the compressionto finish. Secondly, if we were to make the blocks bigger then there is a high probabilitythat the image would have larger color gradients between the blocks. Finally, powers of2 is known to have computational advantages.

DCT converts the pixels of the image from the spatial-dimension (figure 2.3) into thefrequency-dimension (figure 2.4) which makes it possible to separate the low and highfrequencies. The reason for separating high and low frequencies lies in the fact thathuman eyes are unable to see high frequencies. Therefore, removing them have little tono impact of the quality of the image. DCT enables us to separate the high frequenciesallowing us to choose which values we want to save. By applying a quantisation matrixon the DCT matrix, we can zero out elements that represent high frequencies, freeing upmemory. As mentioned before, the pixels of an image is represented by numbers. If wecan remove some of these numbers, i.e., the numbers representing high frequencies, wecan free up memory without diminishing the visual quality for us humans. Dependingon the amount of quantisation we can decide approximately how much we want tocompress the image. This is the only step except the subsampling step where the useractually has a chance to influence the end result, i.e., how much the image is going tobe compressed.

10

Page 23: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

2.1 Understanding JPEG

Figure 2.3: Image "A" in spatial-domain [27]

Figure 2.4: Image "A" represented as a DCT matrix in frequency-domain after applyingDCT [27]

2.1.6 Variable Length Encoding

Our coefficients will be reduced more and more to zero depending on the quantisationin the previous step. It is much more likely that the zero valued coefficients appearin higher frequencies than lower frequencies. The values are sorted with the lowerfrequencies before the higher frequencies. This will lead to a high probability of havingsome values at the beginning and then several values with the value of zero. The reasonfor this is that it is cheaper to store {10x0} rather than {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}.This way we will reduce the amount of data significantly.

There are two common encoding techniques used for encoding JPEG images, “Huffman”and “Arithmetic encoding”. Both are variable length encoding techniques that are usedto map source symbols to a variable number of bits. This is used for compressingand decompressing information, in this case, JPEG images. The following section willexplain the main principles behind both Huffman and Arithmetic encoding.

11

Page 24: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

2. BACKGROUND

2.1.6.1 Huffman Encoding

The Huffman encoding is a statistical data compression technique that represents thesymbols of an alphabet by reducing the average code length. The Huffman code isconsidered optimal if all the symbols have probability of integral powers of 1/2. Amuch simplified example of the Huffman encoding would be if we imagine our image asthe string "HHHHHUFFFFFF". Instead of writing the entire string as it is we couldinstead write "Hx5UFx6". The Huffman encoding achieves this by building a Huffmancode tree (figure 2.5). It is possible to create many different Huffman codes for a givenfrequency. However, the total compressed length will always be the same for that givenfrequency. For a more detailed version of the Huffman encoding, I suggest the readerto take a look at the Internet FAQ Archives[9].

Figure 2.5: Huffman code tree [26]

2.1.6.2 Arithmetic Encoding

Huffman encoding has been and still is the standard encoding process of JPEG images.However, there is actually one encoding technique that can be considered more effectiveand that is Arithmetic encoding. As seen previously, Huffman encoding is considered

12

Page 25: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

2.2 Human Visual System

optimal when all the symbols probability are integral powers of 1/2. This restriction isnot affecting the Arithmetic encoding.

What makes Arithmetic encoding different is that it represents a number by an intervalof real numbers between one and zero. This means that the interval to represent themessage (in this case the representation of the image) becomes smaller and smaller thelonger the message gets. If the message contains successive symbols then the intervalwill be reduced in accordance with the probability of that symbol, i.e., the more likely asymbol is, the lower the range will get. This leads to adding fewer bits to the message.It has been measured that the Arithmetic encoding can give between 5 - 10% betterencoding than the Huffman encoding [13].

This leads to asking, why are we not using Arithmetic encoding instead of Huffman en-coding? First of all, Arithmetic encoding is not supported by modern internet browsers.Secondly, Arithmetic encoding used to consume very large quantities of computing re-sources, both in terms of memory and CPU. Finally, Arithmetic encoding has also beenpatented for a long time. It was not until recent years that the patents started to getlifted and it became possible to use Arithmetic encoding without having to pay largeamounts of money.

2.2 Human Visual System

This section will explore information related to the Human Visual System (HVS). Thisis important since the compressed images are going to be viewed by human eyes andnot machines. Therefore, by taking the Human Visual System into account, it becomeseasier to figure out which characteristics of an image are important to perceive theimage quality as “good”.

Maintz tells us that there is a big difference between the image that we see on a screenand the image that we actually perceive [14]. The luminance of a pixel is a good example.It does not necessarily mean that we will perceive the brightness as doubled of we doublethe screen brightness. The reason for this is that the brightness also depends on otherfactors. The contrast around a pixel plays a big part on how we perceive the brightnessaround it. Therefore, we can say that the ability to detect a spot of light is more relatedto the difference in contrast, i.e., luminance of the spot and background rather than theluminance of the spot itself.

Maintz also tells us that the ability to detect the spots is related to a certain luminancethreshold that must be met. This threshold is known as just noticeable differencewhich Weber’s law defines as the difference δL that is proportional to the backgroundluminance L. This means that the constant needs to be high if the background luminanceis high to be able to detect a difference. This is also mentioned in [15] where theauthors tell us that image distortions that have arisen from small changes of the ambientillumination intensity are usually far more tolerable to the human eyes than those whodisorder the spatial structure of intensities and colors.

13

Page 26: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

2. BACKGROUND

According to [16], something they define as “killer dots” is the element that is the hardestfor JPEG to compress. “Killer dots” is when a ring of dark dots at minimum intensitysurrounds a bright dot. The reason for this is that the dots’ offset only contributevery little to the background and therefore is quantised away. To be able to determinethe best quantisation matrix for any given image, for example the "killer dot” image,we need to take several factors into account. These factors include mean luminance,contrast masking and orientation masking.

Now that we understand how JPEG work and how we actually interpret images itbecomes easier to understand which characteristics and aspects are important to takeinto consideration. This knowledge will be used when answering the main researchquestion and its sub-questions.

14

Page 27: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

3

Related Work

This section will present the related work. This includes both ongoing projects related toJPEG compression as well as academic research. Projects related to measuring differentaspects/characteristics is prioritised. For the interested reader, I suggest taking a lookat the following references [29][32][33][34][35][36][37][38]. These references also have asimilar goal to this thesis but are not similar enough to be presented in the followingsection. The difference between these papers and this thesis is mainly that we try tofind a close to optimal compression rate before actually compressing the image. Thesepapers focus more on improving the compression or improving compressed images usingdifferent methods.

Imgmin: Ryan Flynn tells us that the easiest way to find the best compression ratewould be to generate several versions of an image of different qualities [1]. We wouldthen let a human decide which image has the lowest acceptable quality. However, this isnot applicable when compressing several hundred images. Ryan noticed that the visualquality of images started to diminish seemingly when the mean pixel error rate becamehigher than 1.0. The pixel error rate measures the average of how much a pixel in acompressed image has changed from the original image. Therefore, he came up with away of automating this process. This is done by generating several compressed imagesand then taking the image that has a mean pixel error rate as close as possible to 1.0without exceeding it. This process turned out to work very well except for low colorimages with low-contrast patterns and gradients used in the background.

Mozilla JPEG Encoder Project and libjpeg-turbo: Mozilla have created twoprojects that they call the "Mozilla JPEG encoder project" (mozjpeg project) andlibjpeg-turbo [2]. The mozjpeg encoder was produced to create better compressionfor images used on the web by the price of degraded performance while libjpeg-turbois suited for a more "balanced" compression. The mozjpeg encoder determines theprogressive encoding configuration to conclude the best compression quality. It alsouses a more intelligent algorithm called "Trellis quantisation", which decides what datato remove during lossy compression.

15

Page 28: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

3. RELATED WORK

Enhancement of JPEG-Compressed Images by Re-application of JPEG: Inthis paper, Aria presents a technique for reduction of compression artefacts in JPEG-images [3]. The goal of the algorithm is to apply shifted versions of the JPEG com-pression operator to the JPEG-compressed image. This approach seems like a verypromising technique for “smoothing” out the compressed images. However, since thisthesis is focusing on measuring characteristics before the compression is done to givethe best compression rate this method is not directly applicable. If I were to continuemy research with a broader scope then this method could be very promising for refiningthe already compressed images.

JPEG Compression Metric as a Quality Aware Image Transcoding: Suren-dar and Carla presents a technique for quantifying the size-versus-quality tradeoff fortranscoding JPEG-images [4]. They noticed that the perceived information quality ofan image mostly depends on several factors such as the image background, the imagesize, viewing distance, the display characteristics and ambient light. They also tell usthat it is possible to objectively measure compressed images using distortion metrics,fidelity metrics and quality metrics. Distortion metrics tries to find differences betweentwo images (sharpness, noise, and color) while fidelity metrics try to find the visibledifferences between two images. Quality metrics is basically numbers that are derivedfrom physical measurements that directly relate to the perception of the image quality.

A Color-based Technique for Measuring Visible Loss for use in Image DataCommunication: This paper focuses on measuring the amount of colors in an imageto determine how much an image can be compressed [5]. They explain that the “lossi-ness" that an image can tolerate when being compressed depends on three factors: Theorganisation of colors in the image, the total amount of colors and the total numberof distinct colors in an image. Since color is one of the criteria used by human eyesto identify objects around them, Annamalai and Bhargava developed a technique thatwould evaluate the quality of an image based on the color histogram. The algorithmtakes the loss-induced version and the original image and calculates the color differencebetween them. By identifying certain quality levels and then associate a thresh value tothe quality level it becomes possible to determine if the compression rate is acceptable.

An Approach for Color Image Compression of JPEG and PNG Images us-ing DCT And DWT: This paper presents a different method for compressing jpegand png images. Instead of using DCT they use DWT which is the Discrete WaveletTransformation. They tell us that DWT decreases the complexity of images into itselementary forms [28]. They also claim that the discrete wavelet transformation per-forms better than the “normal” discrete cosine transformation in terms of Signal toNoise Ratio, Mean Square Error and overall compression. Their compression method isbased on DWT and is allegedly producing good compression ratios without degradingthe perceivable quality of the image. Based on their findings it becomes clear that thisis of interest for this master thesis. However, their results are based on 10 images whichis not enough to verify if this method actually is better than the more common DCTmethod.

16

Page 29: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

Compression Color Space Estimation of JPEG Images Using Lattice BasisReduction: Images can be be encoded in several different color spaces. Each colorspace requires three independent values to describe colors. For example, the RGB colorspace expresses each color in terms of red, green and blue components. The problem isthat it may not always be possible to determine the color space of a compressed image[31]. The paper "Compression Color Space Estimation of JPEG Images Using LatticeBasis Reduction” therefore presents an estimation formula for estimating the unknowncompression color space. Their problem analysis shows that DCT coefficients of theimage conform to an approximate lattice. This lattice can then be used to determinethe used color space. They use an algorithm that fuses statical noise reduction with thenovel and powerful lattice reduction algorithm from number theory.

High rate compression based on luminance & chrominance of the imageusing binary plane technique: Ismail et al. proposes an approach for processingthe chrominance data separately from the luminance [17]. This will in turn help withexploiting the fact that human eyes have a limited perception of color in as related to theperception of the light intensity. This is done by processing the chrominance componentsusing a lossy binary plane technique. This is done by first converting the image intothe YCbCr color space and then compressing the luminance (Y) using lossless binderyplane technique. The chrominance components (Cb and Cr) are then compressed usinglossy binary plane technique. After this is completed, all the components are mergedtogether to create the compressed image.

Image compression and quality factor: This paper proposes a relation betweenthe compression rate and the quality of the image [30]. The paper also presents threereasons why JPEG is better than many other compression formats. The first reason isthat JPEG uses a lossy compression method which means that we can remove uselessdata. This also means that JPEG usually have a superior compression ratio comparedto most lossless schemes. The second reason is that JPEG works best with compleximages and photographs. The third reason is that JPEG stores images using a pixeldepth between 6 and 24 bits with both efficiency and speed. The authors also claimthat the most used objective image distortion/quality metrics are Mean Squared Error(MSE) and Peak Signal-to-Nose Ratio (PSNR). The problem is that these metrics arecriticised for not correlating well with the perceived quality measurement. Instead ofusing these metrics, the paper matches the original image to the compressed image andmeasure differences in color discrimination, brightness, geometry, contrast and evennessof illumination. The only downside with this paper is that the implementation is neverpresented, only the results.

In conclusion, even if there are many interesting papers on the same subject which havesimilar goals none of them had the exact same approach as this thesis. They do howeverprovide several good aspects on how to further improve the coming results and how tobenchmark the results of this thesis.

17

Page 30: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

3. RELATED WORK

18

Page 31: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

4

Method

4.1 Research Design

To be able to understand how different characteristics affect the JPEG compression it isimportant to first understand how the JPEG compression works in general. Therefore,an extensive research on JPEG compression was conducted in the background section.This was done by doing a broad literature study on the subject.

Another aspect that is important to take into account is how humans interpret animage. There is a big difference in how machines and humans view an image. Therefore,a literature study on the Human Visual System was also included in the backgroundsection.

Finally, we need to decide which characteristics should be measured to analyse images.Once this is completed we can try to develop an algorithm that uses the informationfrom the selected characteristics and generates an estimation of what compression rateshould be used for the compression. It is important that we can validate the correctnessof this algorithm. It is also necessary to verify and validate the selected algorithmsfor measuring the characteristics. This will be done by using information from the“Algorithm Engineering” methodology [22][23][24].

4.2 Image Characteristics

Since there might be an infinite amount of different characteristics that could be mea-sured in an image, some characteristics have to be discarded to leave room for the mostimportant ones. The characteristics that can be deducted from the previously men-tioned information together with other scientific sources will therefore be the focus ofthis report. The criteria for choosing a characteristic were the following:

19

Page 32: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

4. METHOD

• The characteristic must be able to be measured and turned into a metric.

• The characteristic must be mentioned in other scientific papers if they are notobviously related to the compression and perceivable image quality. However, ifa new characteristic is discovered that clearly affects the compression then thatcharacteristic can be added as well.

• The characteristic should be measurable on the original image.

• The characteristic must be related to how the image compresses.

This lead to the following characteristics which serves as a proposed answer to researchquestion 1.1:

Color: As mentioned in [5], colors are one of the criteria used by human eyes to identifyobjects around them. It is not uncommon when compressing an image that containsthe color red that the red color looks worse compare to other colors with the samecircumstances. JPEG compresses all colors equally so this should not really happen intheory. In reality, there are several reasons why we perceive the color red as compressedworse than other colors. One reason is that our eyes “see” more red than other colors.Around 64% of all the cones in our eyes are more sensitive to red than green and blue.Another reason is that humans usually associate the color red with “danger” or “stop”making us extra vigilant for the color red.

Therefore, the characteristic “color” needs to be measured when doing an analysis ofan image. This can be done by measuring the organisation of colors in the image,measuring the total amount of colors and measuring the total number of distinct colorsin an image.

Grey-scale Components: Grey-scale images are challenging when using JPEG com-pression. The human eye is a lot more sensitive to brightness variations than to huevariations [18]. This makes it harder to compress brightness data without giving visualdegradation when using the human eye. This means that when an image has a lot ofgrey-scale elements, we have to be careful with the compression. However, measuringif a component is in grayscale is easy since we just need to look at the colors in thespatial domain. If the red, green and blue channels all have the same value, then wehave encountered a shade between black (RGB = 0) or white (RGB = 255). If themeasurements show that an image contains high amounts of grey, then we will knowthat we cannot compress the image heavily without getting consequences like artefactsor distorted images.

Luminance: As mentioned previously, human eyes are very sensitive to luminance[16]. Therefore, taking the luminance as a metric is something that is going to beimportant. Many papers discuss the luminance and argue that it is highly importantfor the compression since the human eyes are sensitive to it. What separates luminancefrom grey-scale components is that luminance can be measure in both color and grey-scale images. Luminance is the perceived brightness.

20

Page 33: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

4.2 Image Characteristics

Chrominance: Since the human eyes are far less sensitive to chrominance than theluminance it becomes important to take the chrominance components into considerationas well. By measuring the chrominance it would in theory become possible to know ifthe compression should use subsampling or not. This would be very beneficial to knowbefore compressing the image since subsampling an image can save a lot of data andmake the rest of the calculations faster. The downside is that it can also generatedistortions in some cases. The main difference between "Color" and "Chrominance" isthat we can determine the bandwidth of each chrominance component by separatingthem from the RGB signal.

Edges: One important characteristic to look at when analysing an image is the amountof edges [9]. JPEG will have a hard time with sharp edges due to the fact that 8 x8 pixel blocks are used. An example could be an image with white background and ablack triangle in the middle. Sharp edges usually become blurred unless we use verylittle compression. However, sharp edges are quite uncommon in regular photos which iswhy regular photos can be compressed more than photos of computer generated media,e.g., a website logo or a cartoonish image.

By applying functions like “Canny edge detection” we can easily convert the image intoblack and white. All edges will be white while the rest of the image will be black.This image can then be divided into smaller blocks. If a block contains white, thenwe will know that we have encountered an edge. This information can then be turnedinto a metric which can be used for giving an estimation of how much an image can becompressed without gaining intolerable artefacts or distortions.

Frequencies: The human eyes are a lot more sensitive to medium frequencies than lowand high frequencies [15]. This is something that we can exploit when compressing ourimages. By identifying areas in an image as low, middle or high frequency areas we cancreate a metric for making an estimation of how much an image should be compressed.If an image mostly contains high frequencies (can be a natural scene photo) then weknow that the image can be more compressed than an image containing parts consistingof mostly middle to low frequencies.

Luminance and Contrast masking: In the paper “An improved JPEG CompressionScheme Using Human Visual System Model” [19] the authors tell us that the way weperceive an image is affected by the masking phenomenon whereby a visual signal mightbe hidden or diminished in the presence of other visual signals. There are two importantvariables that are directly related to this: spatial frequency and luminance. If we have aregion of an image that is brighter than the other regions, then the brighter region cantolerate a higher value loss since the human eyes are less sensitive to the local variations.This is known as luminance masking. The authors also tell us that we are less sensitiveto an image component in the presence of other components with similar orientationand frequencies as well. This is known as contrast masking which is also referred to asthe reduction of visibility in one image component by the presence of another. This issomething that could be made into a metric and then be used before compressing theimage to help achieving the best possible compression.

21

Page 34: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

4. METHOD

Miscellaneous Characteristics: One characteristic that could also be taken intoconsideration is the file size. However, this characteristic can only be measured in ameaningful way after the compression, which is not exactly what we want. However, itcould still be used for tweaking the compression rate. If we keep lowering the qualityof the image but the file size stops decreasing at an acceptable rate then we know forsure that we have reached the best compression rate since further compression will justdecrease the image quality.

4.3 JCEE

To be able to quickly see how the compression affects an image a graphical user interfacewill be developed. The programming language that will be used is C# together withVisual Studio. The program should be able to take an image and then let the usereasily change the compression-rate to see the result in real time. The program shouldalso have some functionality for measuring the user selected characteristics, e.g., meanluminance, frequencies, colors, etc. These algorithms need to be validated in order toensure that the results are correct. This will be done both visually (by drawing them onthe image) and mathematically (by validating their result against other trusted resultsor by experiments). These functions should also be implemented in a way that enablesparallel execution. At this stage speed is not critical, but it might be in the future.Therefore, designing for parallel computing is important for future improvements [23].Furthermore, even if it is important that the algorithms are efficient it is also importantto aim for simplicity, reusability and implementability [24].

JCEE will also have support for selecting multiple images and then run the user selectedcharacteristics. The generated information will then automatically be exported to anExcel file so the user can get a quick overview and generate diagrams if needed. Thismakes it very easy to analyse multiple images without having to do everything by handfrom the command line or using online tools. For compressing images, a library calledImageMagick will be used. This will save a lot of time since creating my own encoderwould require a bigger time frame than what this thesis is intended for. ImageMagickhas support for specifying the compression rate and how much subsampling should beused, which is exactly what we need.

All functions for measuring characteristics in JCEE will divide the image into the userspecified amount of squares. These squares are then treated as a single image bitmap.This makes it possible to run the different algorithms on each square to get a mean valuewithout taking up to much computational power. An image is divided into 8 x 8 pixelblocks by default. This number comes from a series of test runs that included differentsizes of the blocks. The test runs showed that if we increase the number then we loseprecision and if we decrease it the process to calculate characteristics takes longer. SinceJPEG is already using 8 x 8 blocks it also felt natural to use the same size. Anotherreason for dividing the image into blocks is to enable the use of parallelism. Differentthreads can work on different blocks speeding up the process.

22

Page 35: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

4.4 Experiments

4.4 Experiments

When the characteristics have been decided and implemented into JCEE some exper-iments will be conducted. The goal of the experiments will be to find out how thedifferent characteristics affect the different images.

When conducting the experiments, I will choose to use both a set of images that Voor-media has provided that they know will give a great variation of perceived quality atdifferent compression rates. I will also choose to use a set of test images from [21]. Thesecond set of images are high-resolution high-precision images that has been specificallyselected to aid in image compression research and algorithm evaluation. Finally, I willchoose some other images to be sure that all the categories mentioned in 4.4.1 will becovered. The reason for using multiple sets of images, not only the ones provided byVoormedia, was to avoid finding results that would only be valid for their set of images.To gain insight on how the compression rate affected the different characteristics, thefollowing experiments will be conducted.

4.4.1 Experiment 1

The goal of the first experiment is to find out how much actual users will compress animage. Therefore, several different categories of images will be selected:

• Photos (nature, city, sky, space, crowds, portraits, etc)

• Art, clip art, modern art

• Large images

• Screenshots

• Diagrams

• Images with text

• Drawings

• Blocking checkerboard 8x8 aligned

• Images with gradients, middle frequencies

• Images with lines, rotating lines

• Images with limited set of colors/a lot of colors

• Small images

23

Page 36: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

4. METHOD

This will result in approximately 60 images to cover these categories. This will ensurethat as many as possible different types of images would be included in the test. Theexperiment have to be somewhat compact to ensure that the test subject does not gettired. A screen with the resolution of 2560x1600 pixels will be used to conduct theexperiment. Images that are bigger than 2560/2 pixels in width and 1600/2 pixels inheight will be cropped but keeping the parts of the image that affects the compressionthe most.

To conduct this experiment a small new application will be developed (see figure 4.1).This application will contain two picture boxes containing the original image in one boxand the compressed image in the other. The application will also have two buttons thatallows the user to switch between the original images. Finally, beneath the compressedpicture box is a slider that will allow the user to select the compression level in steps offive ranging between 0 - 100.

Six test subjects will be used to conduct the experiment. Having more subjects willnot be necessary since we are looking for a range and not any exact numbers. All thesubjects that will be used should know what JPEG compression is and some of thesubjects should often compress their images using JPEG. All subjects will be told tocompress every image as much as possible without having the image looking bad.

4.4.2 Experiment 2

The second experiment will be created to see how the different characteristics changeswhen compressing an image between the image’s initial quality level all the way downto 1. For every image in the series, the current estimated quality level will be extractedand set to x. As long as x is bigger than 0, compress the current image using x asthe compression rate and then measure all the characteristics for every x. All theinformation generated will then be automatically added to an excel file which can thenbe used to make a diagram displaying the compression rate on the X-axis the values forthe characteristics on the Y-axis.

4.4.3 Experiment 3

The third experiment will be created to measure the initial characteristics of everyimage in the previous mentioned sets. The experiment will be very similar to thesecond experiment but instead of going through 60 excel files by hand the process wasautomated. All the selected characteristics will be measured at the image withoutcompressing the image first. The results will then be added to an Excel file for easyviewing. This makes it possible to quickly look up the initial characteristics for anyimage in the set. This can then be used together with the other experiment to crossreference the characteristics. It is also possible to use the experiment for measuring acertain characteristic if needed.

24

Page 37: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

4.4 Experiments

Figure 4.1: Experiment view of JCEE

25

Page 38: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

4. METHOD

26

Page 39: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5

Results

After the initial characteristics had been decided, a graphical user interface namedJCEE (JPEG Compression Experimental Environment) was developed. The applicationis intended to allow the user to select an image to be analysed. Once the user hasselected an image, the image will be displayed in the application. The user then hasthe possibility to either run different functions for measuring the previously mentionedcharacteristics. The user can also choose to compress the image by turning a slider thatranges from 1 – 100. When the slider values change, the original image gets compressed.This way, the user can see in real time how an image is affected by the compression-rate.

JCEE or JPEG Compression Experimental Environment is an application developedduring the thesis to quickly be able to compress images and try different algorithms formeasuring different characteristics. The application was developed with Visual Studiousing C# 4.5. The main view of the application consists of three image boxes (seefigure 5.2). The first image box shows the original image that the user has selected.The second box show the compressed image after the user has specified the compressionlevel. The third box shows how Voormedia currently would compress the image. If theuser would click any of the boxes, a modal window would appear that would allow theuser to pan and zoom the image. This makes it easier for the user to detect artefacts.

The user compresses the image by changing the value on a slider. The range is between0 - 100 where 0 is the maximum compression and 100 is the lowest. This makes itpossible to see the compression in real time. There are also several buttons and eachbutton will run the different measurement algorithms mentioned in 4.2.

If the user selects “Analyse images”, another view will be shown (see figure 5.2). Theuser can now add either a single image or a folder containing images. The view containstwo list boxes where the left box contains the file paths to the user selected images andthe right box contains the processed image. The user can choose which characteristicsthat should be included into the analysis. The user can also choose to just run theanalysis on the current quality level or to measure the selected characteristics for everyquality level down to 0. Once the analysis is done, the results will be written to an

27

Page 40: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5. RESULTS

Figure 5.1: Main window of JCEE

excel file for easy viewing. Finally, in the original JCEE view, the user can choose“Experiment”. This part is covered in 4.4.1.

Figure 5.2: Main window of JCEE

28

Page 41: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5.1 Characteristics Validation

5.1 Characteristics Validation

Edge detection: This function is intended to be used when we want to find edges in animage. Since there already exist several algorithms for finding edges I decided to use the“Canny edge” algorithm. "Canny edge" is one of the most used and simplest algorithmsfor finding edges. The function takes an image and highlights the edges with white andmakes the rest of the image black. The simplest way to see if we have encountered anedge would then be to check if one of our squares contains the color white. We can thendivide the number of squares containing the color white with the squares without whiteto get a metric that possibly could be used. However, later it was discovered that thefunction for measuring frequencies was also able to find the same edges as this functionand therefore the edge detection function was deprecated due to the fact that it wasslower.

The validation of this function is rather straight forward. It can easily be done byrunning the “Canny edge function” (highlighting edges with white and making the restof the image black) and then visually analysing the image by checking if the shownsquares contains an edge. To make the visual confirmation easy, all squares containingan edge got an outline painted on them. The function was run on 10 different imagesand all edges were found and marked correctly.

Error detection: Many of todays algorithms for finding the best compression rateusually compress the image several times and then use a metric for deciding whichimage is the best. This function is only used when analysing how the compression affectsthe image between compression level 100 and 1. The function uses the original imageand the compressed image to calculate the mean error per pixel and the normalisedmaximum error. However, our goal is to find the best compression rate without actuallycompressing the image so this function could only be used when analysing how thecompression rate is affecting the image.

To validate this function other programs with similar functions were used. One examplewas using ImageMagick directly from the command line both under Windows and MacOSX. The results were identical.

Measure color: This function extracts the amount of colors in percentage of the image.The algorithm also uses the previously mentioned blocks for the calculation. For everyblock, we calculate the mean value for all the pixels in the block. This is done by goingthrough each pixel in the current block and save the mean color value for that block.The values are then divided by the amount of pixels in the square to get the mean value.We then divide the amount of specific blocks with the total amount of blocks. This waywe can get a metric and see the amount of red, green and blue. We can also see if ablock contains the color white (all RGB values higher than 240), the color black (allRGB values lower than 55), and if the color is grey (all RGB values are the same andbetween 55 and 240). These ranges can be changed to give a more precise "color". Thiscan be especially interesting since we know from our previous analysis of the HumanVisual System that red can for example look worse compressed compared to blue.

29

Page 42: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5. RESULTS

To validate this function, a very simple experiment was constructed. By creating imagescontaining very few pixels it becomes possible to easily verify if the algorithm is workingas intended.

Measure luminance: This function is very similar to the “measure color” function.It uses the same technique to calculate the luminance. The difference here is that wealways use all the RGB values and apply a function to the values. The formula forcalculating the luminance can be found in [20], 0.299R + 0.587G + 0.114B where R isthe red value, G is the green value and B is the blue value. The luminance for everyblock is then summarised and divided with the total amount of blocks to get the meanluminance in the image. This can then be used as a metric for the overall analysis.Furthermore, the maximum and minimum luminance for each image was also saved tobe able to clearly see the luminance range.

This function was validated by using another application, namely Adobe PhotoshopCS4. Photoshop is a well known application and is famous for its abilities for handlingimages. With the help of Photoshop it is possible to determine the mean, the maximumand the minimum luminance of an image. JCEE’s measure luminance function givesalmost identical values to the values that Photoshop display. The reason for not havinga 100% match is due to the fact that JCEE is using a three decimal number (to simplifythe calculations) and Photoshop is probably using a more precise value. However, thevalue that JCEE is providing is close enough to be accepted.

Detect frequencies: This function is still under development. The main problemis that we have been unable to find a perfect threshold for when determining if afrequency is low, medium or high. A high frequency is when the pixels change rapidly,e.g., when we have an edge or when we have an image containing for example colourfulballoons or a forest. Low frequency is when the pixels change slowly, e.g., when wehave a gradient image. Medium frequency is everything in between the high and lowfrequencies. This means that we can turn the low, medium and high frequencies into ametric by calculating all the blocks containing a specific frequency and dividing themby the total amount of squares. As mentioned before, human eyes are more prone todetect changes in the middle and high frequency which means that if those metrics arehigh then we should have to proceed with caution when compressing the image. Thecurrent threshold for a high frequency is if the mean pixel value changes more than fiveper block. If all the pixels are the same in the block then we have a low frequency andeverything between high and low frequencies are considered as a medium frequency.

Validation for this function was done in a similar matter as to the edge detection func-tion. The amount of high frequencies were almost identical to the amount of detectededges. The squares were painted with different colors as well to easily distinguish if thealgorithm catches the different frequencies correct. The algorithm is not 100% correctand this is due to the problem of finding thresholds that will work with all images. Al-gorithms are usually analysed at either the worst or the average case [22], and by testingthis algorithm we found out that the worst case, i.e., when the algorithm sometimesmistook middle frequencies for low frequencies was still good enough.

30

Page 43: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5.2 Experiment results

File size: This metric is only usable when analysing how the compression is affectingan image in the range between 100 and 1 as well. If the file size does not shrink at areasonable level between each compression step then we know that we are most likelystarting to reach the maximum compression that we should be using. There is no reasonfor compressing an image more if we are not saving space.

To validate the file size function, the only thing needed is to check that the said file sizeis the same as the reported file size by the operating system.

Chrominance: This function did not get implemented in JCEE. I was unable to find agood way of measuring the pure chrominance components and the function was thereforedisregarded to give room to the other functions. As far as my research goes a successfulway of measuring when to use subsampling or not does not exist. The best way so farin regards of judging when to use subsampling or not is to compress the image withand without subsampling and use error measures to determine if it is worth using.

Luminance and Contrast masking: This function was excluded due to time con-straints. However, the algorithm for implementing the luminance masking is quitestraight forward. Since we are dividing the image into blocks, it becomes possible tocheck if a block is surrounded by darker blocks in terms of luminance. Then we wouldknow that this particular block could handle heavier compression than the blocks aroundit. Another reason for not implementing this function is that we would need a work-ing block-wise compression algorithm for utilising the gained information and this issomething that we do not have yet.

Measuring contrast masking could be done in a similar matter but instead of measuringthe luminance in the surrounding squares we would measure the frequencies and orien-tation to see if they are similar. The reasons for not implementing a way to measurecontrast masking is the same as for the function for measuring luminance masking.

5.2 Experiment results

As mentioned in the Method section, three different experiments were conducted to seehow different characteristics affect different images. The experiments would also tell ushow much users would like to compress different images. This information could thenbe used to create an algorithm for finding the close to optimal compression rate for anygiven image.

5.2.1 Experiment 1

The results of the first experiment were more spread than expected. All test subjectsused the same monitor, the same lightning, sat at the same height and had the sameinstructions. Even so, the range of acceptable compression could sometimes vary be-tween 40 and 80 which is quite much when compressing using JPEG. The reason forthis is most likely due to the fact that they all focused on different elements in the

31

Page 44: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5. RESULTS

image. However, this was still very beneficial to learn since it is now was possible toknow which “range” to aim for when trying to create an algorithm for finding the almostoptimal compression rate. Another important element gathered from the experiment isthat it is now possible to sort images based on how much they can be compressed. Thismakes it possible to cross reference the characteristics to see which characteristics arepresent in different images.

In the table (5.1) we can see which compression rate all the users chose for every imagebetween 1 and 30:

Table 5.1: The results from all of the users in experiment 1File: Subject 1 Subject 2 Subject 3 Subject 4 Subject 5 Subject 61.jpg 80 75 45 65 65 802.jpg 75 60 65 45 80 603.png 85 85 80 80 90 704.jpg 60 30 50 45 60 455.jpg 50 25 35 45 35 456.jpg 55 40 35 55 50 257.jpg 35 20 15 30 35 258.jpg 65 35 40 50 40 309.jpg 55 54 70 40 70 3010.jpg 55 29 80 50 65 3511.jpg 75 49 70 50 50 6512.jpg 55 19 40 35 27 2513.jpg 40 15 40 25 30 3014.jpg 45 25 50 50 25 3015.jpg 70 40 50 25 75 3516.jpg 70 45 55 70 85 5017.jpg 70 50 75 65 70 5518.jpg 65 55 70 45 70 6519.jpg 80 70 75 80 85 8520.jpg 85 80 85 80 85 9021.jpg 76 95 85 75 85 9022.png 91 75 65 75 85 8523.jpg 40 15 15 25 20 1024.jpg 50 40 70 50 70 3525.jpg 80 60 65 70 65 5526.jpg 75 75 65 75 85 7027.jpg 45 25 35 50 35 4028.jpg 90 90 75 85 85 6529.jpg 65 60 50 60 45 3530.jpg 50 35 50 65 55 65

32

Page 45: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5.2 Experiment results

5.2.2 Experiment 2

The second experiment was created to see how the compression rate would affect thecharacteristics in the image. This information was then added to an excel file were adiagram could be created. The results from experiment two showed that for images thatwere known to compress very well even at a very low compression rate the characteristicvalues were quite constant. For images that would quickly get artefacts and distortionsthe characteristic values varied instead. One interesting discovery was that even thoughthe luminance was supposed to be practically constant during the entire compressionit sometimes dropped a little and quickly went back to normal. When compressing animage using the x value when the luminance dropped one could sometimes see somethingunexpected. Some images contained “lines” that were not supposed to be there. Thelines could usually be seen where there were areas containing solid colors. Even moreinteresting was that these lines could only be seen using Windows. The reason forthis is that Windows and for example Mac OS X uses different decoders to display theimage. This means that the Windows decoder might sometimes display a compressedimage incorrectly. It can also be due to the fact that there is a bug in the encoder ofImageMagick that were used during the compression.

In figure 5.3 we can see the results for image 1.jpg with all the measured characteristics.In figure 5.4 we can see the different frequencies for the same image. The highlightedarea of 5.4 is the compression range from the first experiment. The lines show how thedifferent characteristics differ on each compression rate between 100 and 0.

33

Page 46: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5. RESULTS

Figure 5.3: All characteristics for 1.jpg (X = Compression rate, Y = characteristic value)

34

Page 47: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5.2 Experiment results

Figure 5.4: Frequencies for 1.jpg (X = Compression rate, Y = characteristic value)

35

Page 48: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5. RESULTS

5.2.3 Experiment 3

The third experiment was created to measure the initial characteristics of every imagein the previous mentioned sets. An example of this experiment (with colors omitted)can be seen in table 5.2. This experiment is very similar to the second experiment butinstead of going trough 60 excel files manually the process was automated. All theselected characteristics would be measured at the image without compressing the imagefirst. The results were then added to an Excel file for easy viewing. This makes itpossible to quickly look up the initial characteristics for any image in the set. This canthen be used together with the other experiments to cross reference the characteristics,e.g., seeing the current values of any characteristic at any given compression rate. It isalso possible to use the experiment for measuring a certain characteristic if needed. Anexample of how the excel file was structured can be seen in table 5.2.

Table 5.2: The results from experiment 3 of the first nine images with colors omitted.Name %HF %MF %LF MinLum MeanLum MaxLum1.jpg 55 34,22 10,77 88,46 197 2552x.jpg 23,18 21,74 55,07 33,29 177,81 254,883x.png 35,97 19,27 44,75 45,33 137,22 250,744.jpg 21,98 4,21 73,8 80 240,98 2555.jpg 23,54 25,8 50,61 0 27,08 2556.jpg 92,65 7,2 0,14 1,25 65,07 232,677.jpg 54,95 12,18 32,85 29,63 221,45 2558.jpg 52,9 19,49 27,6 12,72 192,51 2559.jpg 89,07 9,3 1,61 0 127,14 254,88

When evaluating the characteristics, I took the top 10 images that handled compres-sion the worst and the top 10 images that handled compression the best to see howthe different characteristics behaved in "good/bad" compressions. The results can beseen in table 5.3 and table 5.4. From the third experiment it is quickly possible todistinguish a connection between the amount of high frequencies and the compressionrate. Something that could also be important is to take the resolution of the imageinto account. If an image have a very low resolution then the test subject will not seewhen the artefacts manifest and will therefore compress the image a lot more. To seethe correlation between the percentage of frequencies and the average compression ratevisually 2D scatter-plots between the percentage of the different frequencies togetherwith the average compression rate were created. (see figure 5.5, 5.6 and 5.7).

36

Page 49: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5.2 Experiment results

Table 5.3: Diagram for the 10 images that compressed the worst:File: Compression %HF %MF %LF %Red %Green42.jpg 86 35,42 64,21 0,37 92,32 2,5128.jpg 85 40,59 57,82 1,59 10,63 0,4249.png 85 30,8 11,12 58,07 33,67 0,013.png 82 35,97 19,28 44,75 8,38 46,4920.jpg 82 0 100 0 36,8 24,821.jpg 82 4,39 14,79 80,81 42,54 25,6852.jpg 78 11,04 47,32 41,64 3,83 1,3319.jpg 76 2,85 59,21 37,93 26,13 26,0122.png 76 21,08 60,15 18,78 0,41 96,24

Table 5.4: Diagram for the 10 images that compressed the best:File: Compression %HF %MF %LF %Red %Green5.jpg 38 23,54 25,84 50,62 31,75 0,4227.jpg 38 28,75 5,14 66,11 0 0,3638.jpg 38 79,18 20,77 0,05 33,48 54,7312.jpg 37 94,26 5,74 0 47,31 29,8841.jpg 36 92,51 7,4 0,09 19,69 74,8450.png 33 81,64 18,36 0 97,66 060.jpg 32 99,27 0,73 0 98,43 1,427.jpg 25 54,95 12,19 32,86 0,28 3,323.jpg 23 43,23 28,12 28,65 2,77 1,66

37

Page 50: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5. RESULTS

Figure 5.5: Percentage of high frequencies, Y = frequency percentage and X = compres-sion rate

Figure 5.6: Percentage of middle frequencies, Y = frequency percentage and X = com-pression rate

38

Page 51: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5.2 Experiment results

Figure 5.7: Percentage of low frequencies, Y = frequency percentage and X = compressionrate

5.2.4 Characteristics evaluation

From the first experiment we gain insight on how much the given images can be com-pressed. If we summarise the results of how much users would compress the image forevery image and divide it by six (the amount of test subjects) then we get the meancompression rate. This makes it possible to sort images after how well they handlecompression. We can now take the top 10 images that compresses the worst and thetop 10 images that handles compression the best. We can now extract all the initialmeasured characteristics from experiment 3 for the 20 selected images. With this in-formation we can see how the characteristics differ from images that compress well andimages that compress badly. We can also create graphs with the information gatheredin experiment 2 to see how the characteristics change during the compression. Basedon this information, I discovered the following about these images.

Images that compress badly usually have a high frequency percentage below 40%. Theyalso have middle frequencies between 11 – 100% and low frequencies that range between0 - 81%. The middle and low frequency combined ranges between 60 – 100%. Thelargest deviation between high and low frequencies can be as high as up to 100%. Theirminimum luminance range between 0 – 105, medium luminance ranges between 56 –236 and their maximum luminance ranges between 214 – 255. The mean value of the10 images that handled compression the worst can be seen in table 5.5.

39

Page 52: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5. RESULTS

Table 5.5: Mean values for the 10 images that handle compression the worst%HF %MF %LF MinLum MeanLum MaxLum21.9 49.4 28.5 42.4 130.6 244.7

From experiment 3 we can also see that images that handle compression well have ahigh frequency percentage between 23 – 99, but for the most part the high frequencypercentage is dominant. The middle and low frequencies ranges between 1 – 28 and1 – 75. The middle and low frequencies combined ranges between 8 – 57%. Thehighest deviation between high and low frequencies never differed more than 27%. Theirminimum luminance range between 0 – 93, medium luminance ranges between 27 – 221and their maximum luminance ranges between 206 – 255. The mean value of the 10images that handled compression the best can be seen in table 5.6.

Table 5.6: The mean values for the 10 images that handle compression the best%HF %MF %LF MinLum MeanLum MaxLum67 15.1 17.8 22.4 104.2 244.7

The color values for both the images that handled compression badly and the imagesthat handled compression well were very similar. Therefore, no direct connection be-tween how the colors affect the image compression could be made.

We know for example that images containing mostly middle frequencies are hard tocompress so it is not so surprising that images that compress badly have a higherpercentage of middle frequencies than images that handle compression well. We can alsosee that images containing high frequencies are more prone to handle more compressionwithout looking bad. Luminance also seems to play an important part due to thefact that the images that compress badly have an overall higher value for their meanluminance. Based on this information, two hypotheses were created:

Hypothesis 1: Images will not handle compression well if the percentage of highfrequency are around 40 or lower and the middle frequency is dominant. This hypothesisholds true for 9/10 of the 10 images that handled compression the worst. The exceptionwas a screenshot of a webpage containing a white background with black text. Thisimage had a very high amount of luminance which is something that we saw from table1 is common in images that compress badly.

Hypothesis 2: Images will handle compression well if the percentage of high frequen-cies are dominant or if the percentage of low frequencies dominates the percentage ofmiddle frequencies. This hypothesis held true for 10/10 of the images that handledcompression the best.

40

Page 53: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5.2 Experiment results

To further verify that the hypotheses were true, correlation testing and regression anal-yses were done. The correlation testing showed that the two characteristics that hadthe most correlation in regards to each other and the average compression rate was thepercentage of high and middle frequencies. High frequencies had a correlation of 0.54and middle frequencies had a correlation of 0.47. A regression analysis was then doneto see if these correlations were statistical significant. Both characteristics held a highstatistical significance and did therefore become the main elements for calculating thebest possible compression rate for a given image. These hypotheses served as guidelinesfor creating an algorithm that would try to find the almost optimal compression for agiven image.

41

Page 54: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5. RESULTS

5.2.5 Final algorithm results

Now that we have seen that there seems to be a decent correlation between the percent-age of high frequencies and the compression rate it is time to try to create an algorithmfor estimating the close to optimal compression. Out of the 60 images used through theexperiments 40 images were randomly selected for validation and the rest of the 20 im-ages were used for verification. By taking the first 40 images and creating a 2D-scatterplot where the percentage of high frequencies are on the X-axis and the compressionrate is on the Y-axis. This can be seen in figure 5.8.

Figure 5.8: The correlation between the percentage of high frequencies and the compres-sion rate.

After visually analysing the 2D-scatterplot in 5.10 I tried to create a model for estimat-ing the desired compression rate by aiming for the average compression rate. However,using the average as a goal for the compression estimation is not necessarily good. Theaverage does not tell us so much about how well the compression is going to be. There-fore, instead of using an average, a wider range had to be used. Therefore, I tried to seta linear range that would be considered as the "acceptable compression range". This

42

Page 55: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5.2 Experiment results

can be seen in figure 5.9

Figure 5.9: Correlation between the percentage of high frequencies and the compressionrate. The lines represent the acceptable compression rate area.

As mentioned earlier, the high frequencies percentage had a decent correlation to theaverage compression rate and is statistically significant as well. Therefore, by acceptinga wider range (see the top and bottom line in 5.9) and then using the average of thatrange as a base-formula to lower the compression rate it becomes possible to createan estimation of what the compression rate should be that is slightly higher than theaverage.

43

Page 56: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5. RESULTS

By using the middle line in 5.9 as a base, the formula then became (HF = percentageof high frequencies):

y = −2

5∗HF + 80 (5.1)

(the middle line in 5.7 created from Y = kx+m).

This formula were then used to estimate the close to optimal compression rate forthe remaining 20 images. The results were then compared against Voormedia’s owncompression estimation algorithm to measure how satisfied the users were. The usersatisfaction level were set to the following two ranges:

Strict user satisfaction ranges

• User will be happy if the estimated compression rate is estimated between 0 or +5from the selected compression. Example: User selects 80, estimation is between80 and 85

• User will almost be happy if the estimated compression rate is estimated between+6 or +10 from the selected compression. Example: User selects 80, estimationis between 86 and 90

• User will be sad if the estimated compression rate is estimated higher than 10 orhave a lower estimation from the selected compression. Example: User selects 80,estimation is 91 or lower than 80

Less strict user satisfaction ranges

• User will be happy if the estimated compression rate is estimated between 0 or +10from the selected compression. Example: User selects 80, estimation is between80 and 90

• User will almost be happy if the estimated compression rate is estimated between+11 or +20 from the selected compression. Example: User selects 60, estimationis between 71 and 80

• User will be sad if the estimated compression rate is estimated higher than 20 orhave a lower estimation from the selected compression. Example: User selects 50,estimation is 71 or lower than 50

The results of the strict user satisfaction ranges can be seen in table 5.7 and the resultsof the less strict user satisfaction ranges in table 5.8.

44

Page 57: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5.2 Experiment results

Table 5.7: User satisfaction level of compressed images with low toleranceSatisfaction Very satisfied Almost satisfied Not satisfiedRange between 0 and +5 +6 and +10 +10 or below estimationEstimation formula: 16 12 92TinyJPG: 15 9 96

Table 5.8: User satisfaction level of compressed images with high toleranceSatisfaction Very satisfied Almost satisfied Not satisfiedRange between 0 and +10 +11 and +20 +20 or below estimationEstimation formula: 44 15 61TinyJPG: 24 15 81

As we can see, the estimation formula seems to have a better estimation of what thecompression should be, compared to what Voormedia uses today. If we take all of the60 images and construct them in the same way as before we will get the overall resultin figure 5.10.

45

Page 58: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

5. RESULTS

Figure 5.10: The percentage of high frequencies relation to the average compression rate.Green = good estimation, yellow = decent estimation and red = bad estimation.

In figure 5.10, the red dots represent the images that will have a bad estimation. Theyellow dots represents the images that will have a decent estimation and the green dotsrepresent the images that will have a good estimation using the previously presentedformula. Out of 60 images, 13 images had a bad estimation, 13 images had a mediumestimation and 34 images had a good estimation. However, having a bad or mediumestimation does not necessarily mean that they are in fact “bad”. 22 out of the 26 imagesthat had a bad or medium estimation were estimated to have a lower compressionrate than the average compression rate. This means that those images would be lesscompressed than the average and the image would in fact look good to the majority.

In overall, 43 out of 60 images had an estimation higher than the average. This meansthat these images would still look good after compressing them using the estimationformula. This is good since we do not want the images to be below the average com-pression rate. 17 out of 60 images had a lower estimation, and this is not somethingthat can be accepted. If we go lower than the average compression rate then we canassume that these image will not be considered as “good” by the majority of users.

46

Page 59: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

6

Discussion, Conclusions and Futurework

6.1 Discussion

The experiments have shown that it is in fact possible to make a connection between thecompression rate and the percentage of frequencies in the image. However, creating analgorithm for finding the close to optimal compression rate was harder than expectedbut a formula for estimating the desired compression rate was created. Out of 60images, 43 if those images received an estimation that would be classified as acceptablein regards to the quality to the majority of the test subjects of the experiments. It wasalso indicated that the estimation formula had a higher acceptance amongst the testsubjects than Voormedia had.

It was surprising to see that the rest of the characteristics did not have an obviouseffect on the compression rate. Some of the images in the experiments were in grey-scale. As mentioned earlier, these images were thought to be challenging. However,they did not compress as badly as previously thought. The grey-scale images actuallyhandled compression really well. One of the grey-scale images were amongst the toptwo of the images that handled compression the best. The reason for having a grey-scale image compressing so well is probably due to the fact the image contained mostlyhigh frequencies and had a large portion of pure black in the background. It was alsosurprising to see that that there was no clear connection between the amount of colorsand how well an image handled compression. This might have been different if thecolors were measured in actual colors (red, green, blue, yellow, magenta, etc.) insteadof just using red, green, blue, grey, white and black. However, even if actual colors wereused there is no guarantee that the results would have been different.

One thing that could further improve the way we compress JPEG images would be if wecould use “block-wise” compression. This means that we would use different compressionrates for different blocks in the image. By using block-wise compression together with

47

Page 60: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

6. DISCUSSION, CONCLUSIONS AND FUTURE WORK

the information gathered from the characteristics in the image we could most likelystart to reach the best imaginable compression for lossy compression. The problem isthat when we divide an image into blocks, each block is represented as an image onits own rather than just part of the original image. If we divide the image into blockswith today’s technologies and then compress them differently then we may still end upwith a much bigger image than we started with. The reason for this is that each squarecontains all the information that is needed to encode and decode the image (e.g., headersand DCT tables). However, if we could somehow optimise the way that we store theDCT tables in the original image then it might be possible to store each blocks DCTtable in an efficient way. This could in turn lead to a much better compression of JPEGimages.

6.2 Conclusions and Future work

Based on the experiments and the results we can say that it is possible to measuredifferent characteristics of an image to get an estimation of how much an image can becompressed. This answers the first main research question. This means that it wouldin theory be possible to create an algorithm for finding the best possible compressionrate. The characteristics play a big part of how well an image can be compressed. Thiswas indicated by the experiments conducted within this research. However, there wasonly one of the chosen characteristics that had any real significance and that was thepercentage of high frequencies. Therefore, the percentage of high frequencies is theanswer to research question 1.1. Research question 1.2 and 1.3 was answered in section5.1.

To answer the second main research question, a comparison against Voormedia’s owncompression method was used. Voormedia is a very respected company for compres-sion of JPEG images and if the proposed method satisfies more users then it may beconsidered successful.

The main problem of the estimation formula was that there was no clear connection towhy some images could not be properly estimated. If we want to create an algorithmfor finding the absolute best possible compression rate in the future then we would mostlikely have to conduct more experiments including other characteristics. I do howeverbelieve that this research could have laid the groundwork for a new way of finding thebest possible compression rate. The most common technique today is to compress animage several times and then measure the different images against the original image tofind the best compression. By using the technique presented in this research not onlywould the process be faster but also more accurate since we are compressing each imagebased on their own characteristics.

Something that is left as future work is to further validate the results by compressinganother set of test images using the estimation formula and compare them to the sameset compressed by Voormedia. It is however already known that some of the images

48

Page 61: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

6.2 Conclusions and Future work

compress better with the estimation formula than they would do with Voormedia’scompression. The estimation formula is still immature and it is very possible that itcan be tweaked together with other characteristics to become the best way of estimatinghow much to compress an image using JPEG.

49

Page 62: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

6. DISCUSSION, CONCLUSIONS AND FUTURE WORK

50

Page 63: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

7

References

[1] Flynn, R. imgmin. [Online] Available at: https://github.com/rflynn/imgmin. Ac-cessed 1 Mar. 2015.

[2] Mozilla JPEG Encoder Project and libjpeg-turbo. [Online] Available at: http://www.libjpeg-turbo.org/About/Mozjpeg. Accessed 1 Mar. 2015.

[3] Nosratinia, A. Enhancement of JPEG-Compressed Images by Re-application ofJPEG. Department of Electrical Engineering. University of Texas at Dallas, Richard-son, TX 75083, USA. 1999

[4] Chandra, S. Schlatter, C. JPEG Compression Metic as a Quality Aware ImageTranscoding. Boulder, Colorado, USA. 1999

[5] Annamalai, m. Sundaram, A. Bhargava, B. A Color-based Technique for MeasuringVisible Loss for use in Image Data Communication. Department of Computer Sciences.Purdue University, USA. 1996

[6] Austin, D. Image Compression: Seeing What’s Not There. American Mathe- maticalSociety. Grand Valley State University. 2009. Accessed 3 Mar. 2015. [Online] Availableat:http://www.ams.org/samplings/feature-column/fcarc-image-compression.

[7] "Types of Bitmaps." MSDN. Microsoft Corporation. 2009. [Online] Available at:https://msdn.microsoft.com/en-us/library/at62haz6(v=vs.110).aspx Accessed 3 Mar.2015.

[8] Wiseman, Y. The still image lossy compression standard – JPEG. Computer ScienceDepartment. Bar-Ilan University. Israel

[9] Internet FAQ Archives. [Online] Available at: http://www.faqs.org/faqs/ Accessed27 Mar.2015

[10] I, Snyder. JPEG Image Compression. Unpublished paper. December 14, 2009

[11] "Color model". Wikipedia. [Online] Available at: https://en.wikipedia.org/wiki/Color_model. Accessed 27 Mar. 2015

51

Page 64: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

7. REFERENCES

[12] M, Marcus. JPEG Image Compression. Math 56. Unpublished paper. June 1,2014

[13] G, K, Wallace. The JPEG Still Picture Compression Standard. December 1991

[14] T, Maintz. Digital and Medical Image Processing, Part I, Chapters 1–6. Nov 2005

[15] U, Rajashekar. Z, Wang. E, Simoncelli. Perceptual Quality Assessment of ColorImages Using Adaptive Siganl Representation. Proc. SPIE, Conf. on Human Visionand Electronic Imaging XV, vol.7527 San Jose, CA, USA. Jan 2010

[16] S, Klein. A, Silverstein. T, Carney. Relevance of human vision to JPEG-DCTcompression. SPIE Vol. 1666 Human Vision, Visual Processing, and Digital DisplayIII, page 200 - 2015. School of Optometry, University of California. 1992

[17] M, Ismail. M, Shaik. E, Reddy. High-Rate Compression Based in Luminance andChrominance of the Image Using Binary Plain Technique. Journal of Theoretical andApplied Information Technology. Vol 42 No 2. Pages 191 - 195. 31 Aug 2012

[18] J, Cheng. X, Lv. A Predicted Compensation Model of Human Vision System forLow-light Image. International Congress on Image and Signal Processing. Pages 605 -609. 2010

[19] G, Sreelekha. P,S, Sathidevi. An Improved JPEG Compression Scheme Using Hu-man Visual System Model. Department of Electronics Engineering. National Instituteof Technology, Calicut, Kerala, India. Pages 98 - 101. 2007

[20] W3C. Techniques For Accessibility Evaluation And Repair Tools. 26 April 2000.[Online] Available at: http://www.w3.org/TR/2000/WD-AERT-20000426, Accessed on20 April 2015

[21] Rawzor. The New Test Images. [Online] Available at: http://imagecompression.info/test_images/, Accessed on 1 May 2015

[22] C, Demetrescu. I, Finocchi. G, Italiano. Algorithm Engineering. Italian Ministryof University and Scientific Research. 2003

[23] N, Fang. Engineering Parallel Algorithms. Department of Computer Science.University Basel. Switzerland. 1996

[24] P, Sanders. Algorithm Engineering, An Attempt at a Definition. Universität,Germany. Pages 321-340. 2009

[25] "Chroma Subsampling". Wikipedia. [Online] Available at: https://en.wikipedia.org/wiki/Chroma_subsampling. Accessed 22 Jun. 2015

[26] "Huffman coding tree". [Online] Available at: http://mathworld.wolfram.com/images/eps-gif/HuffmanCoding_701.gif. Accessed 22 Jun. 2015

[27] "JPEG". [Online] Available at: https://en.wikipedia.org/wiki/JPEG. Accessed 25Jun. 2015

[28] J, Iqbal Barbhuiya1. T, Laskar. K, Hemachandran. An Approach for Color Im-age Compression of JPEG and PNG Images using DCT And DWT. Department ofComputer Science. Assam University. India. 2014

52

Page 65: Optimising JPEG image compression by identifying image characteristics › blog › 2016 › 12 › optimising-jpeg-image... · compression by identifying image characteristics Simon

[29] M.Lucassen, J.V.D.Weijer, R. Baldrich. Saliency of color image derivatives: acomparison between computational models and human perception. Computer VisionCenter, Universitat Autonoma de Barcelona. Vol. 27, No. 3. Pages 613 - 621. 2009

[30] R, Pandit. N, Khosla. G, Singh. H, Sharma. Image compression and qualityfactor. International Journal of Advanced Research in Computer and CommunicationEngineering Vol. 2, Issue 7. Pages 2578 - 2581. 2013

[31] R, Neelamani. R, Baraniuk. R, Queiroz. Compression Color Space Estimation ofJPEG Images Using Lattice Basis Reduction. Department of Electrical and ComputerEngineering. Rice University. 2001

[32] U, Rajashekar. Z, Wang. P, Simoncelli. Perceptiual Quality assessment of colorimages using adaptive signal representation. Proc SPIE, Conf. on Human Vision andElectronic Imaging, XV, vol.7527. Jan 2010

[33] Z, Wang. Image Quality Assessment: From Error Visability to Structural Similarity.Image Processing, IEEE Transactions, Volume:13, Issue:4. Pages 600 - 612. April 2004

[34] L, W C. C, Y, Wang. S, M, Lee. Designing jpeg quantization tables based inhuman visual system. Department of Computer Science National Tsing Hua UniversityHsinchu 300, Taiwan. Pages 376 - 380. 1999

[35] M, Cadik. P, Slavik. Evaluation of Two Principal Approaches to Objective ImageQuality Assessment. IEEE. Pages 513 - 518. 2004

[36] J, Mukherjee. Enhancement of Color Images by Scaling the DCT Coefficients.IEEE. Pages 1783 - 1794. 2008

[37] X, Wang. JPEG Image Compression Algorithm Analysis and Local Optimization.Advanced Management Science (ICAMS). IEEE International Conference on volume:1.Pages 5 - 7. 2010

[38] J, Ehel. F, Mendivil. E, Lutton. Overcompressing JPEG images with EvolutionAlgorithms. Springer Berlin Heidelberg. Pages 383 - 390. 2007

53