<<

COMPRESSION OF MEDICAL IMAGES USING LOCAL NEIGHBOR DIFFERENCE

Thesis

Submitted to

The School of Engineering of the

UNIVERSITY OF DAYTON

In Partial Fulfillment of the Requirements for

The Degree of

Master of Science in Electrical Engineering

By

Erin Leigh Patterson

UNIVERSITY OF DAYTON

Dayton, Ohio

August, 2017 COMPRESSION OF MEDICAL IMAGES USING LOCAL NEIGHBOR DIFFERENCE

Name: Patterson, Erin Leigh

APPROVED BY:

Eric J. Balster, Ph.D. John S Loomis, Ph.D. Advisor Committee Chairman Committee Member Associate Professor, Electrical and Professor, Electrical and Computer Computer Engineering Engineering

Yakov Diskin, Ph.D. Committee Member Professor, Electrical and Computer Engineering

Robert J. Wilkens, Ph.D., P.E. Eddy M. Rojas, Ph.D., M.A., P. E. Associate Dean for Research & Dean, School of Engineering Innovation, Professor School of Engineering

ii c Copyright by

Erin Leigh Patterson

All rights reserved

2017 ABSTRACT

COMPRESSION OF MEDICAL IMAGES USING LOCAL NEIGHBOR DIFFERENCE

Name: Patterson, Erin Leigh University of Dayton

Advisor: Dr. Eric J. Balster

Medical images are an essential part to any health professional’s career when helping patients and diagnosing health concerns. Due to the need for large storage capacity and fast transferring speed, research in has grown. Image compression uses the property of redun- dant information in the image to reduce the amount of data in the image to solve both problems of storage and transmission. For medical images, algorithms are of interest to make sure that the reconstructed image provides the same details as the original image. This thesis presents a proposed algorithm called the Local Neighbor Difference (LND) which is a pre- processing technique to allow the redundancy in the medical image to be reduced before being sent into a commercial-off-the-shelf compressor (COTS), XZ. LND, when used in conjunction with XZ losslessly, compresses images, on average, by 6% more than XZ alone. The LND process, along with some future work, is proposed in this paper and results in a viable option for a pre-process to a compressor.

iii I want to dedicate my thesis to my parents, Randy and LeAnn. Thank you for always encouraging

and supporting me in accomplishing my goals.

iv ACKNOWLEDGMENTS

I would like to thank those who have supported and encouraged me as a graduate student at the University of Dayton. Without the support of the following people, my Master’s thesis would not have been possible. It is with guidance and mentorship provided to me in this experience that allowed me to grow, not only as a person, but also as an engineer.

• Dr. Eric J. Balster: For being my advisor and providing me with great insight in the area of

image compression.

• The Design Knowledge Company (TDKC): For providing me with a thesis platform and

experience.

• Dr. John Loomis and Dr. Yakov Diskin: For being willing to be on my thesis defense and

providing any help when necessary.

• Friends & Family: For always supporting me in my decisions and surrounding me with ad-

vice, love, and friendship.

v TABLE OF CONTENTS

ABSTRACT ...... iii

DEDICATION ...... iv

ACKNOWLEDGMENTS ...... v

LIST OF FIGURES ...... viii

LIST OF TABLES ...... xi

I. INTRODUCTION ...... 1

1.1 Medical Images ...... 1 1.2 Image Compression ...... 3 1.3 Lossy versus Lossless ...... 6 1.4 Importance of Lossless ...... 7 1.5 Properties of Images ...... 7 1.6 Current Compressors ...... 8 1.6.1 ...... 8 1.6.2 ...... 9 1.6.3 XZ ...... 10 1.6.4 JPEG ...... 10 1.6.5 JPEG2000 ...... 11 1.7 Compression Ratio ...... 11 1.8 Proposed LND ...... 12

II. LND PROCESS ...... 14

2.1 Subtraction of Surrounding Pixels ...... 15 2.2 Importance of Pixel Location ...... 17 2.3 Residual Compression ...... 18 2.4 Location Compression ...... 19 2.5 Final LND Process ...... 20

vi III. TESTING & RESULTS ...... 22

3.1 Sample Size & Image Criteria ...... 22 3.2 Optimum Block Size ...... 23 3.3 Variations of LND ...... 26 3.3.1 Basic LND ...... 27 3.3.2 Close Mirror LND ...... 28 3.3.3 Close Mirror Diagonal LND ...... 29 3.3.4 Close Mirror Diagonal Mix LND ...... 30 3.3.5 Block Mean LND ...... 31 3.3.6 Col/Row Mean LND ...... 31 3.3.7 Edge Mean LND ...... 32 3.3.8 Middle Mean LND ...... 32 3.3.9 Row Mean Edge/Col Mean Edge LND ...... 33 3.3.10 Nearest Neighbor LND ...... 34 3.3.11 Clockwise Spiral ...... 34 3.3.12 Counter-Clockwise Spiral ...... 35 3.4 Variation Optimization ...... 35 3.4.1 Optimization Based on Chest Xray256a ...... 37 3.4.2 Optimization Based on Four Testing Images ...... 43 3.5 LND with Two Variations ...... 50 3.6 LND with Eight Variations ...... 52 3.7 Optimum Block Size Revisited ...... 54 3.8 Pre-processing Comparison ...... 54 3.9 Variation Prediction ...... 58 3.10 Large Image Testing ...... 62

IV. REVERSE PROCESS ...... 67

4.1 Importance ...... 67 4.2 Process ...... 67

V. CONCLUSION & FUTURE WORK ...... 69

BIBLIOGRAPHY ...... 71

vii LIST OF FIGURES

1.1 Image Compression Process ...... 4

1.2 Forward Compression Processing Chain ...... 4

2.1 Local Neighbor Difference (LND) Process ...... 14

2.2 Pixel Neighbors ...... 15

2.3 Final Pixel Neighbors ...... 16

2.4 Pixel Neighbor Options ...... 17

2.5 Combination of Location Elements ...... 20

2.6 Final LND Process ...... 21

3.1 Left: Chest X-ray (1760x1760), Center: Hands X-ray (2577x2048), Right: Skull X-ray (2048x2577) ...... 22

3.2 Top Left to Right: Chest Xray256a, Chest Xray256, xr chest1, xr chest2 Bottom Left to Right: xr chest3, xr hands1, xr skull1, xr skull2 ...... 23

3.3 Chest Xray256a ...... 24

3.4 Left: 2x2 Block Grouping, Center: 3x3 Block Grouping, Right: 4x4 Block Grouping 25

3.5 Block Positions ...... 26

3.6 Inner Block Pixel Positions ...... 27

3.7 Basic LND Result for Block X ...... 28

viii 3.8 Close Mirror Diagonal LND Result for Block X ...... 29

3.9 Close Mirror Diagonal Mix LND Result for Block X ...... 30

3.10 Clockwise Spiral LND Result for Block X ...... 35

3.11 Counter-Clockwise Spiral LND Result for Block X ...... 35

3.12 Variation Optimization Process ...... 36

3.13 Variations Used: Top: Stage 1, Bottom: Stage 2 ...... 39

3.14 Variations Used: Top: Stage 3, Bottom: Stage 4 ...... 40

3.15 Variations Used: Top: Stage 5, Bottom: Stage 6 ...... 41

3.16 Variations Used: Stage 7 ...... 42

3.17 Residual Size Dependent on Variations ...... 43

3.18 Top Left: Chest Xray256a, Top Right: xr chest1 Bottom Left: xr chest3, Bottom Right: xr skull1 ...... 44

3.19 Variations Used: Top: Stage 1, Bottom: Stage 2 ...... 46

3.20 Variations Used: Top: Stage 3, Bottom: Stage 4 ...... 47

3.21 Variations Used: Top: Stage 5, Bottom: Stage 6 ...... 48

3.22 Variations Used: Stage 7 ...... 49

3.23 Location of Edge and Middle Blocks ...... 50

3.24 Combination of 2 Variations into 8bit Value ...... 53

3.25 Process of Image Compression ...... 55

3.26 Pre-Process Comparison of 8 Images ...... 56

3.27 Pre-Process Comparison Average of 8 Images ...... 57

3.28 Prediction Comparison of 8 Images ...... 59

ix 3.29 Prediction Comparison Average ...... 60

3.30 Versions of LND ...... 61

3.31 Left to Right: Imdent-0100 (512x512), Chest X-ray (1760x1760), Hands X-ray (2577x2048), Skull X-ray (2048x2577) ...... 62

3.32 Prediction Comparison of Large Images ...... 64

3.33 Prediction Comparison Average of Large Images ...... 65

4.1 Final LND Process ...... 68

x LIST OF TABLES

3.1 File Size of Different Block Sizes ...... 25

3.2 Variation Reduction Based on Chest Xray256a ...... 38

3.3 Variation Reduction Based on Four Training Images ...... 45

3.4 Top 2 Variations per Block Location ...... 51

3.5 File Sizes with 2 Variations ...... 51

3.6 File Sizes with 8 Variations ...... 53

3.7 Pre-Process Comparison of 8 Images ...... 56

3.8 Prediction Comparison of 8 Images ...... 58

3.9 Prediction Comparison of Large Images ...... 63

xi CHAPTER I

INTRODUCTION

1.1 Medical Images

Medical imaging technology has allowed the medical field to grow and technologically improve on a massive scale. Medical images allow medical professionals to analyze anatomical and physio- logical structures of their patients. To accurately do this, very high resolution images are captured by current technology with spatial sampling pitches of a few micrometers for optical coherence tomography and of a fraction of a millimeter for current x-ray computed tomography (CT) and magnetic resonance imaging (MRI) [1]. The high spatial sampling resolutions translate into large image resolutions of at least 1024x1024 pixels per image and up to hundreds of slices of images in a video sequence. The pixel intensity is also finely quantized and require 12 or 16 bits-per-pixel (bpp) to represent the image. Due to the image resolution, the number of slices of images, and the pixel bit-depth, the image data set is rather voluminous. Other factors that effect the large amount of im- ages that need to be archived for long periods of time are the widespread use of medical images, the longer life expectancy of patients, and legal imperatives [1]. These factors lead to high storage costs and creates issues with storing and transferring of the images to other necessary medical facilities.

There are two different types of medical images including 2-D and 3-D. Examples of a 2-D med- ical image includes X-rays and ultrasounds. An X-ray is a type of radiation called electromagnetic 1 waves that penetrate the body to create a 2-D image of the inside of the body. Due to the different types of tissues in the body, they absorb different amounts of radiation resulting in the images being different shades of black and white. For example, the calcium in bones absorb the radiation the most so they appear white while fat or other soft tissues absorb less so they appear gray. Ultrasounds are frequently used by healthcare professionals since it is noninvasive in nature, low cost, and allows the forming of real time imaging. Instead of radiation, ultrasounds use high-frequency sound waves that bounce off of the tissues inside the body to create the images.

Another type of medical image are 3-D. In this case, each examination produces multiple slices which is a graphical representation of a cross section of the human body. The collection of all of these slices creates a 3-D image. Just like the correlation between neighboring pixels in a 2-D im- age, the 3-D images show a strong correlation among consecutive slices which is inter-slice and a relationship in the spatial context called intra-slice [2]. Examples of 3-D medical images include computed tomography (CT), magnetic resonance imaging (MRI), and positron emission tomogra- phy (PET). A CT scan uses X-rays to produce images of all types of body structure including organs, bones, and blood vessels. CT are used by health professionals to help diagnose and manage many health conditions. MRI is a radiology test that uses magnetic fields and radio waves to produce 3-D images. These images can show details of the brain and spinal cord, bones and joints, the heart and blood vessels, breast tissue and other organs. PET is a nuclear imaging technique that allows professionals to see how the organs and tissues are functioning. Usually, a radiopharmaceutical or tracer is injected into a patient’s vein to aid in making the detailed, computerized pictures of the body [3].

2 1.2 Image Compression

Due to the reasons expressed above, medical images not only require a large amount of stor- age capacity but also require a high speed network to transfer the images. The lack of a high speed network creates a bottleneck in places that have either bad connections or limited bandwidth. There- fore, the compression of medical images is an efficient solution for both problems of storage and transmission via a limited bandwidth [4][5].

Image and video compression are areas of research and development that started around the late 1980s and early 1990s when digital imaging, video, and Internet connectivity started to be- come mainstream. The original JPEG standard was finalized in 1992, and ever since, image and video compression have been active areas of research. Digital still and video cameras have com- pletely replaced old film cameras and VHS video recorders. Compression technology has become commonplace in everyday life wherein most ways, the user is unaware that it is taking place auto- matically.

Image compression is a procedure of decreasing, diminishing, and minimizing the quantity of bits needed to represent, store, and transmit data as fast as possible [6]. This can be performed by taking advantage of two different factors that are relevant in an image, whether the image is a medical image or not. These different factors are redundancies and irrelevancies in the image data allowing the storage size of the image to be truncated or scaled down [6]. Reduction of irrelevancy is the removal of data that will not be identified by the receiver. When working with medical im- ages, irrelevancy is not of importance since the healthcare professionals want to make sure that all of the details are available in the image whether they can be seen or not. Reduction of redundancy is the removal of duplicate content from the data. Since neighboring pixels are likely to be corre- lated, redundant information may be present. This is one of the three types of redundancies known

3 as interpixel redundancy [4]. The other two types of redundancy are coding and psycho visual redundancy [4][6].

Image compression includes a forward process referred to as encoding and a reverse process referred to as decoding. Consider the encoder and decoder system as shown in Figure 1.1.

Figure 1.1: Image Compression Process

When the encoder receives the original image, the image is converted into a series of binary data called a bit-stream. The decoder then takes the encoded bit-stream and decodes it to create the decoded image.

In general, the forward process of image and video compression can be broken down into three distinct processing blocks as shown in Figure 1.2. The three distinct processing blocks are: predic- tion and transformation, quantization, and encoding. Each processing block is needed and performs a distinct function in the compression process as discussed below.

Figure 1.2: Forward Compression Processing Chain

4 Prediction and transformation is a processing step to reduce the entropy of the original data set.

By using mathematical transformations, a sparse representation of the data can be obtained which is referred to as a coefficient set as opposed to pixels or data. Different portions of the data may be used to represent the current set of data or to predict the current data set. This predicted data is then subtracted from the original data set resulting in data that is referred to as residual data. Prediction techniques have traditionally evolved from video compression so prediction and transformation of data is typically seen in video compressors, whereas image compression techniques tend to rely merely on mathematical transforms for entropy reduction.

In general, the transformation and prediction processes are reversible. This means that there is no data loss incurred when applying the inverse of the processes to the coefficient or residual data.

However, some techniques use floating point processing techniques which are ultimately rounded prior to encoding. This rounding of fractional data make come transformation and prediction tech- niques irreversible. However, for most types of images, any data loss due to transformation and prediction is typically deemed negligible.

Quantization is a process which limits the dynamic range of the coefficient and residual data that comes out of the transformation and prediction processing block. The more limited the dynamic range of the data (i.e. high quantization) the higher the compression gain and the greater the loss in image/video quality. Quantization is designated to be solely responsible for quality loss in the compression engine.

Encoding is the process where actual data reduction takes place. In both the transformation and quantization techniques, typically there is no reduction in the data. They are processing steps to attempt to make the data more uniform and ready for compression. The true happens in the encoder.

5 The decoding process is the reverse of the encoding process steps. If the total data quantity of the bit-stream is less than the total data quantity of the original image, then image compression has been performed [7]. This process can be performed on a vast array of types of images but the focus of this paper is on two-dimensional medical images like X-rays, ultrasounds, etc. To save both memory space and speed for transferring large amounts of data across the globe through compressed format, image compression plays a vital role [6].

1.3 Lossy versus Lossless

There are two classes of image compression, lossy and lossless, and are each used for different purposes depending on the image being compressed. In a system, the recon- structed image from the condensed data is not the same as the reference or input image. The data can never be recovered precisely as it was before it was compressed [4]. Though the information recovered isn’t a perfect replica of the original image, it is enough in many applications including images and sounds for human eyes and ears [8]. Since some of the information in an image can be lost during a lossy compression algorithm, it allows for a larger compression on the data and can reduce the image down to a very small size. In a lossless compression system, the reconstructed image from the condensed data is exactly the same as the reference or input image. Since they need to work perfectly, the compression ratios are only a modest 2:1 to 4:1, depending upon the redun- dancy of the information in the image [8]. Though lossless compression is not as extreme as a lossy compression system, this method is preferred for confidential documents, executable files, data base records, and biomedical images and signals where a single bad bit in the reconstructed image could lead to major problems [4, 6, 8].

6 1.4 Importance of Lossless

Despite the fact that lossy compression results in higher compression ratios, the therapeutic community and medical group are hesitant to receive and use lossy options due to legitimate risks and ineffectively, unpredictability and poorly reconstructed images [6]. This lossless criteria is im- portant in the medical field, especially to doctors and other people who examine images including

X-rays, CT scans, ultrasounds, etc. When medical images are being saved and transferred to other hospitals, it is required that no information in the image is lost. A medical image without details is of no use to the doctors and hospital staff and could result in serious issues for the patients. Data compression is essential and a lossless compression algorithm is required and indispensable since the acquired data are precious and, in many cases, obtained by unrepeatable medical exams [2].

Without the details from a lossy compression, doctors may have a harder time providing the pa- tient with a correct diagnosis and, therefore, correct treatment for the issues they are experiencing.

Therefore, the best way to ensure the best treatment for the patient and the fastest and easiest diag- nosis by medical personnel is to compress the images in a lossless manner. Since all of the details of the image must be saved and accounted for, a lossless compression process provides a sense of certainty that all of the information in the image is conserved through transferring between hospitals and this is more important than a larger compression ratio.

1.5 Properties of Images

Each pixel in an image has two vertical and two horizontal neighbors along with four other neighbors on the diagonals of the pixel. These eight points are together known as the eight neighbors of a particular pixel. If the pixel is on the border of an image, then some of the eight neighbors may fall outside of the image. Each image, except for images with a high level of noise, have certain properties between its pixels which can be used as an advantage when compressing an image.

7 Adjacency is when two pixels are connected if they are neighbors and their pixel values satisfy some specified criterion of similarity. This can happen with any of the eight neighbors surrounding a particular pixel. In images, pixels tend to have very similar values of its neighbors since there is not typically sudden changes in an image. Besides noise, two neighboring pixels will not have pixel values of the extremes in the image. For example, pixel A has a pixel value of 103 and pixel B, which is a horizontal neighbor to the right of pixel A, has a pixel value of 105. This small difference of 2 between pixel A and pixel B supports the idea that these two pixels are adjacently related and contain a certain level of redundant information.

Because each pixel has eight neighbors, many mathematical and logical processes can be per- formed on the pixel. Some mathematical and logical operations include addition, subtraction, multi- plication, division, Logic AND, OR, and compliment. Other tasks can be done due to neighborhood processing including smoothing and averaging, noise cancellation and filtering, edge detection, and contrast enhancement. All of these processes rely on the adjacency and correlation between neigh- boring pixels to help define an image. A main benefit of having high pixel correlation in neighboring pixels in an image is the possibility of using prediction and/or transform-based methods to reduce the redundancy and, therefore, reduce the number of bits needed to encode the image [4][1][8]. This allows for compression.

1.6 Current Compressors

The following is a brief description of popular compression tools. Some are older compressors while others are currently performing the best and are being improved.

1.6.1 ZIP

ZIP is a compression format that supports lossless data compression and allows the user to group one or more files called directories into one .zip file. This was initially released in 1989 and

8 is currently supported by many software utilities including Microsoft Windows and MAC operat- ing systems. Since each file inside the .zip file is stored separately, this allows for different files to be compressed using different methods depending on the nature of the file. A few of the differ- ent compression methods include: Store (no compression), Shrink, Deflate, bzip2, WavPack, and

LZMA.

There are limits on the minimum and maximum size of a .zip file. The minimum size is 22 bytes.

This is an empty ZIP file but still contains an End of Central Directory (EOCD) Record resulting in a little amount of information. Two enhancements of ZIP is the extra field facility within the file headers which allows for extra data to be stored and ZIP includes strong encryption specifications which was involved in a controversy in 2003.

1.6.2 BZIP2

BZIP2 is a free and open-source file compressor that was released in 1996 but, unlike ZIP, it is not an archiver and can only compress one file at a time. It uses the Burrows-Wheeler algorithm to compress data in blocks of size between 100 and 900 kB. The Burrows-Wheeler algorithm con- verts frequently-recurring character sequences into strings of identical letters then applies Huffman coding.

BZIP2 compresses most files more effectively than the ZIP compressor but compresses at a slower speed. A pro of BZIP2 is that it decompresses the file relatively faster than ZIP. BZIP2 compression is slower since it follows a nine step compression stack which occur in the following order: run-length encoding, Burrows-Wheeler transform, move-to-front transform, Huffman cod- ing, selection of Huffman Tables, Unary base 1 encoding, Delta encoding, and finally, sparse bit array showing which symbols are used.

9 1.6.3 XZ

XZ is a lossless data compressor that uses the LZMA/LZMA2 compression algorithms [9]. It was released in 2009 as an open format for users to download and use. Just like BZIP2, XZ is a

file compressor that does not archive files and can only compress a single file at a time. The XZ file format provides a couple of advanced features but has been kept simple for it to be used in many embedded systems. Some of the advanced features include: stream-able, random-access reading, allows multiple filters, performs integrity checks, and allows concatenation of files.

1.6.4 JPEG

The Joint Pictures Experts Group (JPEG) committee developed a compression standard for digi- tal images in the late 1980s which was finalized in 1992. JPEG compression has long since been the most widely accepted standard in image compression, embedded in most modern digital imaging products.

The JPEG image encoder operates on 8x8 blocks of image data so images being compressed by

JPEG are segmented into independent processing blocks. JPEG compresses each block separately by first transforming the block by Discrete Cosine Transformation (DCT), quantizing the resultant coefficient values, run-length encoding, and finally coding with a variable length entropy coder

[10]. The block-based encoder facilitates simplicity, computational speed, and a modest memory requirement. Typically, JPEG can compress images at 10:1 to 20:1 compression ratio and retain high quality reconstruction. 30:1 to 50:1 compression ratios can be obtained with only minor defects to the reconstructed image [11].

10 1.6.5 JPEG2000

It has been shown throughout the research community for several years that the wavelet trans- form is superior to DCT methods in image compression. Thus, in March of 2000, JPEG published the JPEG2000 standard based on wavelet technology [12]. The compression method of JPEG2000 is similar to that of JEPG but uses the wavelet transform instead of the block-based DCT. This al- lows for the user to specify the size of the processing block, called tiles. The optimum tile size is determined by the user since small tile sizes reduce the memory requirement while large tile sizes improve compression gain and reconstructed image quality. After transformation, coefficients are quantized and encoded.

In addition to higher compression gain as compared to JPEG, JPEG2000 offers a suite of fea- tures not found in the JPEG standard. These features include user-defined tile sizes, resolution scalability, SNR scalability, region of interest coding, quality-layer based encoding, and support for multi-spectral imagery.

1.7 Compression Ratio

There are many different parameters that can be used to describe the performance of a com- pression technique or tool. A main parameter used is compression ratio. Compression ratio (CR) is a parameter that compares the size of the input image (Fs) to the size of the bit-stream once the original image is encoded (CFs) based on the following equation.

CR = F s/CF s

When comparing compression ratios, the higher compression ratio, the more effective the com- pression algorithm is performing on the image [8]. In this thesis, the results are described by stating

11 the percentage of the original image that is needed to reverse the compression process. For example, if the original image is of size 600 and the compressed image is of size 330, then the compression

file is 55% of the original file size based on the equation below where CP is the compression per- centage. When comparing these percentages, a lower percentage suggests that less of the original image is needed and is a more effective compression algorithm being performed.

CP = CF s/F s

1.8 Proposed LND

In this thesis, a new lossless compression algorithm is being proposed as a way to compress

2-D medical images. The Local Neighbor Difference (LND) uses the property that neighboring pixels are correlated and finds the smallest difference from a pixel’s eight neighbors and sends the residuals into the commercial-of-the-shelf, XZ compressor. It is important to use commercial-of- the-shelf compressors because they are usually not internally paired, or coupled, with a pre-process already. By using an unpaired compressor, as new and more efficient compressors are developed, they can be replaced allowing the system to always be up-to-date with the most efficient compressor.

Through many tests, the basic model of the LND grew to not only use the neighbors of the pixel but also variations on how the pixels in one block relates to the pixels in the surrounding blocks.

In Chapter 2, the initial and basic LND process is explained along with the few steps of processing done before the bit-stream is sent into the XZ compressor. Chapter 3 goes into detail of the many tests that are performed to enhance the LND process including scanning across an image in blocks instead of a pixel by pixel basis, different variations tested, and the possibility of prediction in the future. Chapter 4 describes the importance of medical images being reversed and the process to

12 accurately reverse the LND. And finally, Chapter 5 includes the final results and suggestions for future work.

13 CHAPTER II

LND PROCESS

Because of the correlation between pixels and the way image compressors work, some pre- processing can be performed on an image before being sent into a compressor to reduce the amount of redundancy in the image. For example, JPEG and JPEG2000 use a wavelet transform as a pre- processing tool. There are many ways pre-processing on an image can be performed where some are simple and others are more complex. A basic pre-process example is performed by taking the difference of two pixels, A and B, where pixel B is directly to the right of pixel A. A pre-process that is a little more complex will be described in this thesis and is called the Local Neighboring

Difference (LND). The initial LND process, whose steps are shown in Figure 2.1, is performed and then sent into a commercial off-the-shelf compressor, XZ.

Figure 2.1: Local Neighbor Difference (LND) Process

14 Since the LND process is performed on a pixel by pixel basis, it is important to discuss the various steps by focusing on a single pixel from the image. The pixel that will be described has the pixel coordinates of (i,j). Throughout this paper, this specific pixel, pixel(i,j), will be referred to as pixel Q.

2.1 Subtraction of Surrounding Pixels

The first step in the LND process is the subtraction of the surrounding pixel values from the specific pixel, pixel Q. Besides special cases of corner and edge pixels, each pixel is surrounded by eight neighboring pixels as shown in Figure 2.2.

Figure 2.2: Pixel Neighbors

The difference between pixel Q and it’s surrounding pixels is calculated and stored into a 1x8 element array. Then, from those differences, the minimum difference is determined and is called the residual value. Due to the correlation in neighboring pixels in an image, the desired residual value is zero between pixels which allows the information of pixel Q to be stored with better compression of zero bits. The value of pixel Q is replaced by the minimum difference. The element number in the array of where the minimum difference was located is saved into another file called the location

file. This same process can also be expressed by the following equations where D(m,n) is the differences between pixel i,j in image I and it’s neighboring pixels. (x,y) is the argument value in

15 the difference array, D, that is the absolute minimum difference. Pixel Q is then replaced with the absolute minimum difference.

D(m, n) = I(i, j) − I(i + m, j + n)|m,n=−1,0,1

(x, y) = argmin{|D(m, n)|}

Q(i, j) = I(i, j) − I(i + x, j + y)

Since the pixel values are replaced as the process raster scans through each pixel in the image, only certain neighbors are predicted to provide the minimum residual value. For example, in Figure

2.2, neighboring pixels 1, 2, 3, and 8 have already been replaced by the minimum residual value due to the movement of a raster scan. Therefore, for pixel Q, the only neighboring pixels that can possibly result in the minimum residual value are pixels 4, 5, 6, and 7. These four neighboring options can then be stored by only using two bits and are referred to as locations 0, 1, 2, and 3 as shown in Figure 2.3. It is important to note that the neighbor to the right of pixel Q is referred to as location ’0’ since it is the location that most often provides the minimum residual value.

Figure 2.3: Final Pixel Neighbors

After the subtraction of the surrounding pixels is performed for each pixel, two files are created that contains the needed information about the image. The residual file contains the difference 16 between pixels and the location file contains information about which neighboring pixel provided the minimum residual value. Both of these files have the same number of pixels as in the original image at this point in the LND process.

2.2 Importance of Pixel Location

Depending on pixel location, only certain neighboring options are available for calculating the difference between pixels. Figure 2.4 shows the neighboring options for each specific location of the pixels in an image. In the figure, TL represents the top left corner, TE is the top edge, etc.

Figure 2.4: Pixel Neighbor Options

By looking at the above diagram, it can be seen that if the desired pixel is in the top left corner of the image, there are only three pixels that are surrounding neighbors that can be used to deter- mine the minimum difference between the pixel values. For the top right corner, there is only two surrounding pixels; and for the bottom left corner, there is only one surrounding pixel. For all of the pixels on the top edge excluding the top left and top right corners, there are four surrounding pixels

17 that can be used to determine the minimum difference. For the pixels on the left edge excluding the two corners, there are only three surrounding pixels; for the pixels on the right edge, there are only two surrounding pixels; and for the pixels on the bottom edge, there is only one surrounding pixel.

The pixels in the middle of the image, have the same neighboring options as the top edge pixels which is a total of four surrounding pixels. It is important to note that the bottom right pixel is a special case. This pixel is called the reference pixel and is the only pixel in the entire image that has the value of the original image. This is needed and used in the reverse process, which is explained in further detail in Chapter IV, to fulfill a lossless process.

2.3 Residual Compression

Once the residual array is created from the subtraction of the surrounding pixels, one more step is performed on that array before it is sent into the XZ compressor. At this stage in the LND process, there is a variable that contains the residual values for each pixel in the image. This is an array that has the same number of elements as pixels in the original image but the values now range from

[-255,255]. Negative numbers have more bits that are the value of ’1’ than positive numbers which results in needing more bits to describe the number. For each of the negative values in the residual variable, sign magnitude is performed. This provides two advantages: 1. Doing sign magnitude reduces the need to have a sign bit to describe the negative numbers. For the range of [-255,255], a total of nine bits would be needed to account for the negative values. 2. Since positive binary numbers have more zeros than negative binary numbers, the compressors can condense the size of the residual value smaller. For example, if the residual value is -36, the binary 8bit negative number is [11011100]. With sign magnitude, the most significant bit is declared as the sign bit and the rest of the value is the binary 8bit positive number. For -36, after sign magnitude, the binary 8bit number stored is [10100100]. Therefore, there are more zeros present but it doesn’t lose the negative information needed which is now stored in the most significant bit. It is important to note that this 18 step of sign magnitude relies on the image property of pixel correlation. Since neighboring pixels tend to have the same or close to the same pixel value, the difference between the two is going to be zero or small. Since the difference is smaller than the largest negative 8bit value of -255, the most significant bit can be used as the sign bit without losing any important information about the residual value. Once all of the negative residual values are changed with sign magnitude, the array is sent into the XZ compressor. This results in a created residual file that is the compressed information to describe the image pixels compared to their surrounding neighbors.

2.4 Location Compression

Once the location array is created from the subtraction of the surrounding pixels, one more step is performed on the array before it is sent into the XZ compressor. At this stage in the LND process, there is a variable that contains the location values for each pixel in the image. This is an array that has the same number of elements as pixels in the original image but the values range from

[0,3]. Since this range is only four different values, each location can be described by only 2bits.

Location ’0’ would be described by ’00’, location ’1’ by ’01’, location ’2’ by ’10’, and location ’3’ by ’11’. Since the location array is being compressed by using 8bits, four location elements can be combined into one 8bit value. This is done by combining the four elements in blocks as shown in

Figure 2.5. Combining the four elements allows the location array to be reduced to a quarter of the size of the original array and, with less elements that need to be compressed, the location file can be reduced in size when compressed with the XZ compressor. This results in a created location file that is the locations of which neighboring pixels provide the minimum residual value for each pixel in the image.

19 Figure 2.5: Combination of Location Elements

2.5 Final LND Process

Based on the many tests that are conducted and explained along with their results in Chapter

III, the final LND process is slightly different than the initial process described in Sections 2.1- 2.4.

The main stages of subraction of surrounding pixels and the processes on the two files are the same and are not changed throughout testing, but there are other changes that are important to note. First, instead of raster scanning through the image pixel by pixel for the subtraction stage, the Optimum

Block Size test results show that using 3x3 blocks allows there to be less location values to be saved to reverse the process losslessly. Another change for the final LND process is the location file.

Instead of comparing the differences between a block and its surrounding blocks, four variations, or subtracting methods, are tested to determine the one that produces the minimum difference. The process of determining the top four variations that are offered to each block are determined by the

Variation Optimization Test (VOT). This now turns the need of having a location file into the need to have a variation file. Since four variations are offered, it only takes two bits to record the best variation and those values can be combined just as the location values were combined. The final

LND process is shown in Figure 2.6.

20 Figure 2.6: Final LND Process

21 CHAPTER III

TESTING & RESULTS

3.1 Sample Size & Image Criteria

The following tests are performed on a certain set of images due to the desire to compress medical images specifically. These medical images consist of x-rays, ultrasound images, etc. The provided medical images are shown in Figure 3.1.

Figure 3.1: Left: Chest X-ray (1760x1760), Center: Hands X-ray (2577x2048), Right: Skull X-ray (2048x2577)

22 The provided images are initially of large size (for example, 1760x1760) so to reduce the pro- cessing time, smaller images were made from the original images. The images that are created and used were of the size 256x256 which is an original file size of 66 KB. The images also had a bit depth of 8 bits and are shown in Figure 3.2. Most of the following tests are performed on one specific image, Chest Xray256a.bpm, which is shown in the top left image of Figure 3.2. These smaller images created the sample set used in the tests to determine the average outcome and results of the LND process. Various amounts of pixels containing detail and blank space was chosen to provide the tests with diverse images.

Figure 3.2: Top Left to Right: Chest Xray256a, Chest Xray256, xr chest1, xr chest2 Bottom Left to Right: xr chest3, xr hands1, xr skull1, xr skull2

3.2 Optimum Block Size

The initial LND process was performed on a pixel by pixel basis for the given image. To reduce the number of elements in the location file, the LND process could be performed on a block by block basis instead. The subtraction step in the LND process is performed the same but are now

23 done with groups of pixels. This test was conducted using only the Chest Xray256a image which is shown below for reference in Figure 3.3.

Figure 3.3: Chest Xray256a

The grouping of the pixels that are tested consisted of 2x2 blocks which is two pixels wide by two pixels tall for a group of 4 pixels, 3x3 blocks which is three pixels wide by three pixels tall for a group of 9 pixels, and 4x4 blocks which is four pixels wide by four pixels tall for a group of 16 pixels. The pixels were grouped into the blocks by combining the closest neighboring pixels due to the high correlation between adjacent pixel values. Then, the neighbors used to compute the minimum difference as in the LND process, are also blocks of the same size. This allows for only one location to be needed to describe each block of pixels which significantly reduces the number of elements in the location file that need to be compressed by XZ. Figure 3.4 shows the grouping of the 2x2 blocks, the 3x3 blocks, and the 4x4 blocks where the blue represents the current block and the green represents the neighboring blocks used for subtraction.

24 Figure 3.4: Left: 2x2 Block Grouping, Center: 3x3 Block Grouping, Right: 4x4 Block Grouping

The test image, Chest Xray256a is compressed after being pre-processed by the LND process.

First, the image was sent through LND on a pixel by pixel basis, or a 1x1 block. This resulted in a total file size of 33,236 bytes which consists of the residual file and the location file. The location variable first contained 256x256 elements and was then combined in the LND process into an 8bit number resulting in the location variable having 128x128 elements. The same image was then sent into the LND process but with the various block sizes. Table 3.1 shows the resulting total file size for each block size and the number of elements for the location file.

Table 3.1: File Size of Different Block Sizes

Block Size Total File Size Initial Size of Location Variable Final Size of Location Variable 1x1 33236 256x256 128x128 2x2 30472 128x128 64x64 3x3 30080 85x85 43x43 4x4 30560 64x64 32x32

Based on the above data, the LND process on 3x3 blocks allows the image to be compressed more than the other block sizes. The value of the residual file is larger for the 3x3 block versus the

2x2 block since there is a larger minimum difference between neighboring blocks due to the greater

25 distance. The value of the location file is smaller for the 3x3 block than the 2x2 block since it has less amounts of elements that need to be compressed. Therefore, the optimum block size that results in the smallest file size for this image is the 3x3 block size in the LND process.

3.3 Variations of LND

After the optimum block size is determined to be a 3x3 block, there are many ways that the difference can be calculated with the neighboring blocks. Many ways are created and tested to determine which variation provided the minimum file size of the images. Here, the many variations are explained in detail resulting in a total of twelve variations. There are many more variations that could be created but these were the main ones in the testing process. The four block positions available for subtraction are labeled A, B, C, and D. Figure 3.5 shows where each of those block positions correspond to the block that is being focused on, Block X. Some positions had more variations than others due to the frequency of use of that position and the adjacency of the position block to Block X.

Figure 3.5: Block Positions

Figure 3.6 shows the 3x3 blocks and their corresponding inner pixels that are referred to in the following subsections to explain the variations.

26 Figure 3.6: Inner Block Pixel Positions

3.3.1 Basic LND

The Basic LND variation is taking the difference between the two neighboring blocks in a straight forward manner. This is performed by the following equation for each pixel in Block X with respect to Block A where R represents the residual value.

Ri = Xi − Ai, i = {1, 2, ..., 9}

This equation results in Block X as shown in Figure 3.7. This same equation and process is performed with Blocks B, C, and D.

27 Figure 3.7: Basic LND Result for Block X

3.3.2 Close Mirror LND

The Close Mirror variation is performed by taking the difference of each pixel with respect to the pixels in the neighboring blocks that are the closest to the shared edge. This is described by the following equations for each pixel in Block X with respect to Block A.

Ri = Xi − A1, i = {1, 2, 3}

Ri = Xi − A4, i = {4, 5, 6}

Ri = Xi − A7, i = {7, 8, 9}

These same equations are performed with Blocks B, C, and D but with Blocks B and D being diagonal from Block X, the subtraction is only with the diagonal pixel. For example, with respect to Block B, the equation would be as follows:

Ri = Xi − , i = {1, 2, ..., 9}

28 3.3.3 Close Mirror Diagonal LND

The Close Mirror Diagonal LND is very similar to the Close Mirror variation but the equation changes for Blocks B and D since they are diagonal to Block X. The following equations results in

Block X with respect to Block B.

Ri = Xi − A4, i = {3}

Ri = Xi − A7, i = {2, 6}

Ri = Xi − B1, i = {1, 5, 9}

Ri = Xi − C3, i = {4, 8}

Ri = Xi − C2, i = {7}

These equations result in Block X as shown in Figure 3.8. This same process is performed with

Block D with the diagonal in the opposite direction.

Figure 3.8: Close Mirror Diagonal LND Result for Block X

29 3.3.4 Close Mirror Diagonal Mix LND

The Close Mirror Diagonal Mix variation is a combination of Close Mirror and Close Mirror

Diagonal where Block X is determined by the following equations with respect to Block B. This variation only refers to Blocks B and D since they are diagonal to Block X.

Ri = Xi − A1, i = {1, 2, 3}

Ri = Xi − C1, i = {4}

Ri = Xi − B1, i = {5}

Ri = Xi − A4, i = {6}

Ri = Xi − D3, i = {7}

Ri = Xi − C2, i = {8}

Ri = Xi − B1, i = {9}

These equations result in Block X as shown in Figure 3.9. This same process is performed with

Block D with the Block X pixel 5 subtracted from D1 instead of B1.

Figure 3.9: Close Mirror Diagonal Mix LND Result for Block X

30 3.3.5 Block Mean LND

The Block Mean LND variation first takes the mean of all nine pixels in the neighboring block and then subtracts that value from each pixel in Block X. Since the mean of the neighboring block can be a decimal, the value is rounded for the sake of keeping all values integers. This process is shown in the following equations which are with respect to Block A and is the same for Block C.

9 1 X µ = A A 9 i i=1

Ri = Xi − µA, i = {1, 2, ..., 9}

For the two diagonal blocks of Block B and D, the subtraction is just based on the corner pixels of the block changing the equation for Block X with respect to Block B to Ri = Xi − B1 for i = {1, 2, ..., 9}.

3.3.6 Col/Row Mean LND

The Col/Row Mean variation takes the mean of each column or row of the neighboring block

depending on the position the neighboring block is according to Block X. For Block A, it is the

mean of the rows that is calculated and subtracted but for Block C, it is the mean of the columns

since Block C is directly under Block X. The two diagonal blocks of Block B and D are performed

as in the Block Mean variation and are just the subtraction of the corner pixels. The following

equations are an example of how Block X is determined with respect to Block A.

31 3 1 X row = A 1 3 i i=1 6 1 X row = A 2 3 i i=4 9 1 X row = A 3 3 i i=7

Ri = Xi − row1, i = {1, 2, 3}

Ri = Xi − row2, i = {4, 5, 6}

Ri = Xi − row3, i = {7, 8, 9}

3.3.7 Edge Mean LND

The Edge Mean variation determines the mean of the closest edge to Block X of the neighboring block. For Block A, the closest edge is a column and for Block C, the closest edge is a row. The following equations are an example of how Block X is determined with respect to Block A.

1 µ = (A + A + A ) edge 3 1 4 7

Ri = Xi − µedge, i = {1, 2, ..., 9}

3.3.8 Middle Mean LND

The Middle Mean variation is one that has to be performed in a set of steps. First, the top row and bottom row of pixels in Block X are subtracted from the middle row of pixels in Block X. Then, the mean of the closest edge of the neighboring block is calculated as in the Edge Mean variation.

Finally, to reduce the values of the middle row of Block X, the mean of the closest edge is subtracted from each pixel in the middle row of Block X. This same process is performed on a column basis 32 for when the neighboring Block C is used. The following equations are an example of how Block

X is determined with respect to Block A.

1 µ = (A + A + A ) edge 3 1 4 7

Ri = Xi − Xi+3, i = {1, 2, 3}

Ri = Xi − µedge, i = {4, 5, 6}

Ri = Xi − Xi-3, i = {7, 8, 9}

3.3.9 Row Mean Edge/Col Mean Edge LND

The Row Mean Edge or Col Mean Edge variation is named two different names depending on which neighboring block is being used. For Block A, the Col Mean Edge is used and for Block C, the Row Mean Edge is used. Since the process is the same, the Col Mean Edge will be described here with respect to Block A. The first step in the process is to subtract the second column of Block

X from the first column of Block X for the values of the first column. Then, the same is done for the second column of Block X. Then, the mean of the closest edge of the neighboring block is calculated as in the Edge Mean variation. Finally, the edge mean is subtracted from the third column of Block X for the values of the third column. This same process is performed on a row basis for when the neighboring Block C is used. The following equations are an example of how Block X is determined with respect to Block A.

1 µ = (A + A + A ) edge 3 1 4 7

33 Ri = Xi − Xi+1, i = {1, 2, 4, 5, 7, 8}

Ri = Xi − µedge, i = {3, 6, 9}

3.3.10 Nearest Neighbor LND

The Nearest Neighbor variation is partially based on the idea of the previous variation where each pixel in Block X is subtracted from the neighboring pixel. For Block A, this is to the right of the pixel and for Block C, this is under the pixel. The following equation is an example of how

Block X is determined with respect to Block A.

Ri = Xi − Xi+1, i = {1, 2, 4, 5, 7, 8}

Ri = Xi − A1, i = 3

Ri = Xi − A4, i = 6

Ri = Xi − A7, else

3.3.11 Clockwise Spiral

The Clockwise Spiral variation does not follow any equation for all of the pixels in Block X but is created in a way that each pixel is related to the pixel neighboring it. For example, Figure 3.10 shows the subtraction step for each pixel in Block X in respect to Block A.

34 Figure 3.10: Clockwise Spiral LND Result for Block X

3.3.12 Counter-Clockwise Spiral

The Counter-Clockwise Spiral variation is just like the Clockwise Spiral variation but rotates around the pixels in Block X in the opposite direction. For example, Figure 3.11 shows the sub- traction step for each pixel in Block X in respect to Block A.

Figure 3.11: Counter-Clockwise Spiral LND Result for Block X

3.4 Variation Optimization

Due to the many variations of the subtraction step in LND, some variations were the minimum difference for some blocks while other variations were the minimum for other blocks. It was also noted that some location options were not used as frequently as other options. Because of this, a variation optimization process was performed to reduce the many variations of the subtraction step

35 down to the top four frequently used variations. Reducing the options down to the top four would allow for blocks to use the variation that provides them with the minimal difference or residual value, but also would provide a simple way of tracking which variation was used for a particular block. Just as the location for each block was saved using only two bits, the variation used for each block can be saved using only two bits. This removes the need for having a location file and replaces that with the need of a variation file. The variation file contains the same number of elements as the location file but now describes which of the top four variations is the one that provides the minimum difference between blocks. To perform the variation optimization, code was created that contained a top level code and then many functions that were called from the top level. For each block, only certain variations were tested since the block may only have neighboring blocks on a few sides depending on if that particular block is on the edges or corners of the image. The overall optimization process is shown in Figure 3.12 where the top level code calls the functions for each block location available for that particular block and then those options call the functions created for each variation. A, B, C, and D are referred to as location functions and 1,2,3,...,etc are referred to as variation functions.

Figure 3.12: Variation Optimization Process

36 For each level in the optimization process, certain data was sent and returned to all of the func- tions that were called. From the top level code, the block’s pixel location was sent to the location functions, which then passed the pixel location onto the variation functions. Once the variation func- tions calculated the difference between the pixels, then it returned which of the variations provided the minimum difference and also the values of that difference on a pixel by pixel basis to the loca- tion functions. Then, in the location functions, it determined which of the four locations provided the minimum difference returning which location was the minimum, the variation of that location that provided the minimum, and the pixel values of the minimum to allow the block to be updated with the residual values. Performing the optimization in this fashion allows 35 different variations to be reduced down to the top four variations, one for each of the four locations surrounding the block. Then, the overall minimum difference is based from the top four variations that represent each of the four locations. The optimization process is performed two different times. First, the variations are optimized based on one image, Chest Xray256a as explained in Section 3.4.1. Then, four images are chosen from the eight that were created to be the training images and the variations were optimized based on those four training images as discussed in Section 3.4.2.

3.4.1 Optimization Based on Chest Xray256a

First, the variation optimization process was performed based on the image Chest Xray256a as shown above in Figure 3.3. The process of optimizing the variations is a slow process that needs to be completed in many steps. In each round of reduction, as some variations were removed, the blocks that are using the removed variations had to adjust and use other variations that are still being offered. This is why the process is done in stages to determine which variations were used the most frequently based on the variations that were being offered. Table 3.2 shows the reduction process of the variations for this image.

37 Table 3.2: Variation Reduction Based on Chest Xray256a

Stage Variations Variations Size of Comments Used Tested Residual 1 27 35 25156 35 variations created; not all used in min difference 2 24 30 25232 removed position D for all blocks 3 13 19 25616 removed variations used for <200 blocks 4 12 16 25696 reduced position C to 1 variation 5 6 8 26200 removed variations used for <500 blocks 6 5 7 26376 removed variations used for <800 blocks 7 4 6 26664 removed variations used for <1000 blocks

It is important to note, though there were a total of 35 variations tested, not all of them are used for any of the blocks. Some variations never provided a minimum difference and are not efficient enough for any of the blocks. This is why the number of variations used is less than the number of variations tested. Figure 3.13 through Figure 3.16 shows the graph of each of the variations used and by how many blocks. By looking at the graphs, it was determined which of the variations were to be removed until the final four were used for all of the blocks in the image.

38 Figure 3.13: Variations Used: Top: Stage 1, Bottom: Stage 2

39 Figure 3.14: Variations Used: Top: Stage 3, Bottom: Stage 4

40 Figure 3.15: Variations Used: Top: Stage 5, Bottom: Stage 6

41 Figure 3.16: Variations Used: Stage 7

Based on the last graph in the above image which represents the last stage of the optimization process, the top four variations based on Chest Xray256a are Close Mirror A, Block Mean A,

Nearest Neighbor A, and Nearest Neighbor C. By only using these four variations, the residual file size is 26,664 bytes. The variation file that is needed to record which variation each block used is compressed into a file size of 1,648 bytes. For this image, the total compressed file size is 28,312 bytes. It is important to note that as more variations are offered, the size of the residual is smaller as shown in Figure 3.17. But with more variations to create a smaller residual file, the more bits are needed to record which of the variations is used for each block in the variations file. This is where the balance of how many variations to offer and the size of the files becomes important and key on creating the smallest file size possible.

42 mgsa riigiae o h ytm h ortann mgsaesonblwi Figure in below shown are images training four The 3.18. system. the for images training as images Images Testing Four on Based Optimization 3.4.2 eod h aito piiainpoeswspromdbsdo oro h ih created eight the of four on based performed was process optimization variation the Second,

Size of Residual (bytes) 2.45 2.55 2.65 2.4 2.5 2.6 2.7 × iue31:Rsda ieDpneto Variations on Dependent Size Residual 3.17: Figure 10 4 72 31 4 5 6 12 13 24 27 Variation OptimizationResidualSizes Number ofVariationsUsed 43 Figure 3.18: Top Left: Chest Xray256a, Top Right: xr chest1 Bottom Left: xr chest3, Bottom Right: xr skull1

The process of optimizing the variations was a slow process that needed to be completed in many steps for the four training images as when the optimization was based only on Chest Xray256a. In each round of reduction, as some variations were removed, the blocks that were using the removed variations had to adjust and use other variations that were still being offered. This is why the process was done in stages to determine which variations were used the most frequently in the training images based on the variations that were being offered. Table 3.3 shows the reduction process of the variations for the four training images.

As with the other optimization test, though there were a total of 35 variations tested, not all of them were used for any of the blocks. Some variations never provided a minimum difference and are not efficient enough for any of the blocks. This is why the number of variations used is less than

44 Table 3.3: Variation Reduction Based on Four Training Images

Stage Variations Variations Comments Used Tested 1 27 35 35 variations created; not all used in min difference 2 24 30 removed position D for all blocks 3 15 19 removed variations used for <1000 blocks 4 12 16 reduced position C to 1 variation 5 7 8 removed variations used for <2200 blocks 6 5 7 removed variations used for <3500 blocks 7 4 6 removed variations used for <5000 blocks

the number of variations tested. Figure 3.19 through Figure 3.22 shows the graph of each of the variations used and by how many blocks throughout the four images. By looking at the graphs, it was determined which of the variations were to be removed until the final four were used for all of the blocks in the images.

45 Figure 3.19: Variations Used: Top: Stage 1, Bottom: Stage 2

46 Figure 3.20: Variations Used: Top: Stage 3, Bottom: Stage 4

47 Figure 3.21: Variations Used: Top: Stage 5, Bottom: Stage 6

48 Figure 3.22: Variations Used: Stage 7

Based on the last graph in the above image which represents the last stage of the optimization process, the top four variations based on the four training images were Close Mirror A, Block Mean

A, Nearest Neighbor A, and Nearest Neighbor C. These top four variations are the same top four variations when the process was optimized by only using Chest Xray256a. Therefore, based on these created 256x256 images, the variations Close Mirror A, Block Mean A, Nearest Neighbor A, and Nearest Neighbor C are the ones that are used the most and provide the minimum residual value for multiple images. From this point, the LND process determines the minimum difference of the top four variations to create the variation file. The residual file along with the variation file are then used in the reverse process to reconstruct the image as explained in Chapter IV.

49 3.5 LND with Two Variations

Now that LND is finalized with using the top four variations, it is important to prove that four variations is the optimum amount of options for each of the blocks. This test was performed us- ing the image Chest Xray256a. The same LND process can be performed with only offering two variations for the blocks to use instead of four. Of course, the edge and corner blocks are special situations so those locations have different variations depending on their location in the image. By only offering two variations per block, determining the top two variations had to be done in a more location specific manner. To determine the top two variations, the blocks on each edge and middle were individually gauged to find which two variations were used the most depending on the loca- tion of the blocks. Figure 3.23 shows the different edges and middle blocks that were polled to determine which two variations were the top two used for that specific edge. Table 3.4 lists the top two variations for each edge and middle block locations based on the optimized top four variations.

Figure 3.23: Location of Edge and Middle Blocks

50 Table 3.4: Top 2 Variations per Block Location

Block Location Top 2 Variations Top Edge (TE) Close Mirror A Nearest Neighbor C Right Edge (RE) Nearest Neighbor C Left Edge (LE) Close Mirror A Nearest Neighbor A Bottom Edge (BE) Block Mean A Nearest Neighbor A Middle (M) Close Mirror A Nearest Neighbor A

After the LND is performed with the top two variations, the residual file and the variations file

are compressed using XZ as in the proposed process. The residual file size using the two variations

is 28,028 bytes. To determine the best way to reduce the size of the variations file, three different

methods were used. First, the variation file was compressed by XZ without any processing on the

values before being sent into the compressor. This resulted in 1,080 bytes for the variation file.

Second, since there are only two variations that are offered for each block, this information can

be recorded by only using 1 bit. This method of compressing the variation file consists of first

combining four variations into one 8 bit value. Then, it is sent into XZ compress resulting in a

variation file of the size 984 bytes. The third method performed was combining eight variations into

one 8 bit value before being compressed. This results in a variation file of the size 888 bytes. Table

3.5 shows the same information along with the total file size for the image once compressed.

Table 3.5: File Sizes with 2 Variations

Residual File Size Variation File Size Total File Size Comments 28028 1080 29108 no processing on variation file 28028 984 29012 combining every 4 values into 8bit number 28028 888 28916 combining every 8 values into 8bit number

51 Based on the above values, there are a few conclusions that can be made. First, by only using the top two variations, the variation file is drastically reduced especially when eight variation values can be combined into one 8 bit number. Second, reducing the variations down to the top two causes the residual file to grow since blocks are being limited to options that may or may not provide the minimum difference. Another variation may be the minimum for a particular block but since that is not the variation most used for that edge, it has to settle for one of the top options. Lastly, the minimum file size created by only offering two variations is 28,916 bytes which is larger than offering four variations on this image which is 28,314 bytes. Therefore, limiting the LND process to the top two variations is not beneficial to reducing the size of the compressed image.

3.6 LND with Eight Variations

Since limiting the LND process to the top two variations was not effective, the same process must be tested but with offering the top eight varitions to the LND process. This test was also performed using the image Chest Xray256a. To determine the top eight variations in the image, the optimization stage that offered twelve methods for the Chest Xray256a image, Stage 4 from

Table 3.2 was used and variation options that were used for <420 blocks were then eliminated.

This results in the following top eight variations:

• Close Mirror A • Nearest Neighbor A

• Block Mean A • CCW Spiral A

• Col/Row Mean A • Close Mirror Diagonal B

• Edge Mean A • Nearest Neighbor C

After the LND is performed with the top eight variations, the residual file and the variation

file were compressed using XZ as in the proposed process. The residual file size using the eight

52 variations is 26,036 bytes. To determine the best way to reduce the size of the variation file, two

different methods were used. First, the variation file was compressed by XZ without any processing

on the values before being sent into the compressor. This resulted in 2,668 bytes for the variation

file. Second, since there are eight variations that are offered for each block, this information can

be recorded by using three bits. This method of compressing the variation file consists of first

combining two variations into one 8 bit value. This is performed by placing the two variation values

at the end of the 8 bit stream resulting in a value as shown in Figure 3.24 where the two most

significant bits are always ’0’. Then, it is sent into XZ compress resulting in a variation file of

the size 2,492 bytes. Table 3.6 shows the same information along with the total file size for the

compressed image.

Figure 3.24: Combination of 2 Variations into 8bit Value

Table 3.6: File Sizes with 8 Variations

Residual File Size Variation File Size Total File Size Comments 26036 2668 28704 no processing on variation file 26036 2492 28528 combining every 2 values into 8bit number

Based on the above values, there are a few conclusions that can be made. First, by only using the

top eight variations, the residual file is only slightly reduced compared to the residual file when using

four variations. This reduction is about 600 bytes. Second, reducing the variations down to the top

53 eight causes the variation file to grow due to needing three bits to represent a single variation since there are eight options that need to be recorded. Lastly, the minimum file size created by offering eight variations is 28,528 bytes which is larger than offering four variations on this image which is

28,314 bytes. Therefore, limiting the LND process to the top eight variations is not beneficial to reducing the size of the compressed image.

3.7 Optimum Block Size Revisited

Before, when the optimum block size was determined, the testing was performed using only the Basic LND variation. Now that it was proven that the four best variations to be used are Close

Mirror, Block Mean, and Nearest Neighbor (A and C) and not Basic LND, it was important to revisit the optimum block size testing. By using the top four variations with 3x3 blocks, the average compression percentage of the original medical images resulted in 52.26%. When the block size was changed to 4x4 blocks with the same top four variations, the average compression percentage of the original images resulted in 51.87%. This compression percentage value is less than that of the 3x3 blocks since there are less variation values that need to be saved. Both of these compression percentages include the residual file and the variation file. Therefore, by using the four optimum

LND variations, the optimum block size that should be used in the LND process is 4x4 blocks.

3.8 Pre-processing Comparison

The final LND process that is being proposed uses 4x4 blocks on the image with four variations being offered to each block resulting in two files, which are both processed before being compressed by a commercial-off-the-shelf compressor, XZ. There are other currently used pre-processes that reduce the entropy in an image. To compare the pre-processes, images are being processed and then sent into the XZ compressor to determine the best pre-processor. Figure 3.25 shows the overall process of image compression. Having a pre-process that is separate and uncoupled from the

54 compressor allows flexibility to change the compressor as more efficient compressors are developed, allowing the overall system to be up-to-date.

Figure 3.25: Process of Image Compression

Three different pre-processes will be compared in this test. The first pre-process is a simple difference calculator that determines the difference between a pixel at the location (i,j) and a pixel at location (i,j+1). The second pre-process is the finalized LND process. To compare the effects of both block sizes, the test images will be processed using both 3x3 and 4x4 blocks and offering the top four variations for each block. The third pre-process is a wavelet transform 5-3 (WT 5-3) which is the pre-process that is used in JPEG2000. Since JPEG2000 can perform multiple levels of the wavelet transform on an image, different levels were created and tested on each image. A level 1, level 3, and level 5 wavelet transforms were created and reversed to confirm a lossless process but only level 5 is shown in the following results. This resulted in a total of four different pre-process that are being tested and compared before using the XZ compressor. Table 3.7 provides the total

file sizes for each of the images and pre-processing options.

55 Table 3.7: Pre-Process Comparison of 8 Images

Image (.bpm) Image Only XZ LND LND Simple WT 5-3 WT 5-3 WT 5-3 Size (3x3) (4x4) Difference (level 1) (level 3) (level 5) Chest Xray256a 256x256 32908 28312 28212 28448 30184 28128 27984 Chest Xray256 256x256 40172 35408 35176 35672 35324 33236 33140 xr chest1 256x256 40732 35992 35780 36240 36192 33984 33816 xr chest2 256x256 38408 34192 33980 34068 35892 33296 33072 xr chest3 256x256 42604 37580 37328 37800 37968 35368 35204 xr hands1 256x256 45428 41700 41404 43580 41316 39984 39864 xr skull1 256x256 33928 32432 32076 32276 32940 31180 30988 xr skull2 256x256 33184 28360 28012 27736 30696 26732 26500 Total 524288 307364 273976 271968 275820 280512 261908 260568 Percent of Original 100% 58.63% 52.26% 51.87% 52.61% 53.50% 49.95% 49.70%

For easy comparison, Figure 3.26 shows a graph of the same values listed above for each image tested and Figure 3.27 is for an average of the images. Each image individually provides slightly different results due to the various amounts of information and data in the pixels.

×104 Pre-Processing Results 5 XZ 4.5 LND(3x3) LND(4x4) Simple Difference 4 Wavelet Transform

3.5

3

2.5

2 File Size (bytes)

1.5

1

0.5

0

xrskull1 xrskull2 xrchest1 xrchest2 xrchest3 xrhands1 ChestXray256a ChestXray256

Figure 3.26: Pre-Process Comparison of 8 Images

56 aiu nrp euto hnuigX opesi h aee rnfr rmJPEG2000. from transform wavelet the is compress XZ using the when and reduction size entropy file minimum maximum the in results that pre-process the commercial-off-the-shelf average, a on into Therefore, sent XZ. and compressor, uncoupled when image the original to the the of compared reduces 49.70% JPEG2000 52.61% be in to at used image is image that original pre-process 5 the level of 5-3 transform percent wavelet The larger LND. a using purposed not still than is ratio but compression all higher at a pre-process in a result does calculator difference original simple the The of 58.63% image. to image the the compressed into which image pre-processing the any sending without than compressor smaller is XZ This size. image original the of 51.87% to compressed be ae nterslspeetdaoe naeae h upsdLD(x)alw h mg to image the allows (4x4) LND purposed the average, on above, presented results the on Based

Percent of Original 100 10 20 30 40 50 60 70 80 90 iue32:PePoesCmaio vrg f8Images 8 of Average Comparison Pre-Process 3.27: Figure 0 58.63 XZ

LND(3x3) 52.26 Pre-Processing Results

LND(4x4) 57 51.87

Simple Difference 52.61

Wavelet Transform 49.7 3.9 Variation Prediction

By looking at the above results, it can be seen that JPEG2000 is only performing slightly better than the proposed LND process. With the removal of the variation file in each tested image, the

LND process would result in a smaller ratio of the original image to reverse the process, therefore, would perform better than JPEG2000. Table 3.8 shows the original LND values for both 3x3 and

4x4, the original JPEG2000 values, and the values of each image when the variation file is removed.

Table 3.8: Prediction Comparison of 8 Images

Image (.bpm) LND LND WT LND with Prediction LND with Prediction (3x3) (4x4) (level 5) (3x3) (4x4) Chest Xray256a 28312 28212 27984 26664 27260 Chest Xray256 35408 35176 33140 33504 34108 xr chest1 35992 35780 33816 34088 34708 xr chest2 34192 33980 33072 32312 32908 xr chest3 37580 37328 35204 35676 36252 xr hands1 41700 41404 39864 39896 40396 xr skull1 32432 32076 30988 30548 31000 xr skull2 28360 28012 26500 26452 26928 Total 273976 271968 260568 259140 263560 Percent of Original 52.26% 51.87% 49.70% 49.43% 50.27%

For easy comparison, Figure 3.28 shows a graph of the same values listed above for each image tested and Figure 3.29 is for an average of the images. Each image individually provides slightly different results due to the various amounts of information and data in those pixels.

58 File Size (bytes) 0.5 1.5 2.5 3.5 4.5 0 1 2 3 4 × 10

ChestXray256a 4

ChestXray256 iue32:Peito oprsno Images 8 of Comparison Prediction 3.28: Figure

xrchest1 Pre-Processing Results xrchest2 59

xrchest3

xrhands1

xrskull1 LND(4x4) withPred LND(3x3) withPred Wavelet Transform LND(4x4) LND(3x3) xrskull2 htacrtl rdcstevrainue vral rms,bok nteiae urnl,the Currently, image. the in blocks most, or all, over method used prediction single variation a the not predicts is there accurately far, that So etc. blocks, surrounding the with edges blocks difference the minimum of block, reconstructed tested the been in already variance have means, block methods neighboring prediction using Many including block. specific a for determine accurately used to was used variation be which would methods prediction same marked. the be process, to decoding correctly be the predicted in can get doesn’t Then, This that block block. any allow each to for process used encoding the being on was tested variations four the of which predict consistently and h a ormv h aito l ol et s eiso rdcinmtost accurately to methods prediction of series a use to be would file variation the remove to way The

Percent of Original 100 10 20 30 40 50 60 70 80 90 0

LND(3x3) 52.26 iue32:Peito oprsnAverage Comparison Prediction 3.29: Figure

LND(4x4) 51.87 Pre-Processing Results Wavelet Transform 60 49.7

LND(3x3) with Pred 49.43

LND(4x4) with Pred 50.27 best prediction method is by using the edges of the surrounding blocks. By taking the minimum difference of the edges, the prediction method that creates the block that matches the neighboring blocks the most is chosen. When 3x3 blocks are used in LND, the average correct prediction is about

60% of the blocks. When 4x4 blocks are used, the average correct prediction is about 65% with this prediction method. A possible prediction method that could be tried would be to incorporate a machine learning system. This would allow a system to determine the best way to predict the variation used and could result in more consistent predictions over the images. With the inclusion of prediction into the LND process, the 3x3 LND process would result in better performance as shown in Figure 3.30. These results can then be compared with JPEG2000 which is at 49.70%.

This would be very beneficial to the LND process and the image compression field.

Figure 3.30: Versions of LND

The above image shows the current and potential results of the proposed LND process. If no prediction is used, the best LND is the 4x4 blocks. Though this does not prove better performance

61 than JPEG2000, with some future work and modifications, it has potential to be beneficial to im- age compression. The 4x4 LND does, however, perform better than the simple difference of pixels and better than not using any pre-process before using the xz compressor. Once prediction be- comes more accurate, allowing the variation file to be removed, the 3x3 LND performs better than

JPEG2000. The 4x4 LND with prediction does not reduce as much as 3x3 LND with prediction since there are bigger blocks, there are less amounts of variations that need to be saved for the sys- tem to be reversible. The variation file is a smaller percentage of the overall file size for 4x4 blocks as compared to 3x3 blocks. Therefore, the 3x3 LND with prediction provides the best results and, on average, has potential to perform better than JPEG2000.

3.10 Large Image Testing

Once the LND process is finalized, the algorithm is tested using images larger than 256x256.

The four images are shown in Figure 3.31 below and are the whole images from which the previous testing images were taken from.

Figure 3.31: Left to Right: Imdent-0100 (512x512), Chest X-ray (1760x1760), Hands X-ray (2577x2048), Skull X-ray (2048x2577)

62 These four images are tested with the same pre-processes as the others which include the LND with both 3x3 and 4x4 blocks, the simple difference method, and the wavelet transform 5-3 from

JPEG2000. Table 3.9 shows the original LND values for both 3x3 and 4x4, the original JPEG2000 values, and the values of each image when the variation file is removed.

Table 3.9: Prediction Comparison of Large Images

Image (.bpm) Image Size LND LND Simple WT LND with LND with (3x3) (4x4) Difference (level 5) Pred (3x3) Pred (4x4) Imdent-0100 512x512 143120 141376 149168 133356 136832 138028 xr chest 1760x1760 821908 818188 844508 783620 781300 796096 xr hands 2577x2048 3451420 3421072 3604128 3363500 3317780 3350812 xr skull 2048x2577 2074128 2059352 2144788 1977488 1950304 1991952 Total 6490576 6439988 6742592 6257964 6186216 6276888 Percent of Original 46.64% 46.28% 48.46% 44.97% 44.46% 45.11%

For easy comparison, Figure 3.32 shows a graph of the same values listed above for each image tested and Figure 3.33 is for an average of the images. Each image individually provides slightly different results due to the various amounts of information and data in those pixels.

63 File Size (bytes) 0.5 1.5 2.5 3.5 0 1 2 3 4 × 10 6 Imdent-0100 iue33:Peito oprsno ag Images Large of Comparison Prediction 3.32: Figure Pre-Processing ResultsofLargeImages

xrchest 64

xrhands LND(4x4) withPred LND(3x3) withPred Wavelet Transform Simple Difference LND(4x4) LND(3x3)

xrskull N ihpeito rvdstebs eut n,o vrg,hsptnilt efr etrthan better perform to potential has average, on 3x3 and, the results best Therefore, the JPEG2000. provides than prediction better with performs LND LND 3x3 the removed, allowing be accurate, to more file becomes variation prediction the Once pixels. per- of however, difference does, simple the LND than 4x4 better the form JPEG2000, blocks. than 4x4 the performance is better LND prove best not the does used, this is Though prediction no discov- If as images. same size 256x256 the the generally with are before trends ered the pre-processes, the comparing When used. are images ae nterslssonaoe h N rcs rdcsteepce eut hnlarge when results expected the produces process LND the above, shown results the on Based

Percent of Original 100 10 20 30 40 50 60 70 80 90 0

LND(3x3) iue33:Peito oprsnAeaeo ag Images Large of Average Comparison Prediction 3.33: Figure 46.64

LND(4x4) 46.28 Pre-Processing ResultsofLargeImages

Simple Difference 48.46

Wavelet Transform 65 44.97

LND(3x3) with Pred 44.46

LND(4x4) with Pred 45.11 JPEG2000 even with the larger images. What is interesting to note is that the compression percent- ages are smaller for all of the pre-process when larger images are used. Before, with the 256x256 size images, the compression percentage was about 50% on average, but with the larger images, the average compression percentage is about 45%.

66 CHAPTER IV

REVERSE PROCESS

4.1 Importance

Medical images contain a large amount of information that is necessary for correct diagnosis by doctors and professionals. When these images are being transferred from one medical center or hospital to another, it is important that none of the critical data in the images is being lost. Losing the details in the images can result in incorrect diagnosis, difficulty reading the images, or other issues which leaves the patient receiving poor treatment. Therefore, the best way to ensure the best treatment for the patient and the fastest and easiest diagnosis by medical personnel is to compress the images in a lossless manner. This lossless constraint results in a smaller compression ratio for the medical images but provides a sense of certainty that all of the information in the images is conserved through transferring between hospitals.

4.2 Process

The reverse process for the LND pre-process is the forward process in the opposite order. Figure

4.1 shows the stages of the reverse LND process.

67 Figure 4.1: Final LND Process

First, the variation file is decompressed by XZ and then the variation values are separated from the 8bit values they were originally combined into. This results in one variation value per block in the image. Then, the residual file is decompressed by XZ. The sign magnitude is then reversed on the residual value to result in positive and negative values where necessary. At this point, the original variation and residual files are recreated. By using the variation file, the residual values are added back to the variation that was used to get the minimum difference. This results in the correct reconstructed block for the image. Since the bottom right corner of the image is the only pixel that is from the original image, the reverse process starts there and then raster scans through the image from right to left, bottom to top resulting in the lossless reconstructed image.

68 CHAPTER V

CONCLUSION & FUTURE WORK

By comparing the proposed LND 3x3 pre-process with prediction to other pre-processors, it can be determined that the LND process results in a lower compression percentage. This is based on the optimum four variations that are created and tested but other variations could be proven to be better than those used currently. The LND process, on average, performs better than only using XZ compress without any pre-process and is better than a simple difference performed on neighboring pixels to the right. The Optimum Block Size test and revisit proves that moving across the image in blocks of size 4x4 pixels allows for the values of the residual file to be small while only needing one variation value for each block when the optimum four variations are being offered. Thus, the

final LND process uses the 4x4 blocks and the top four optimum variations resulting in compressing images to 51.87% of the original image, on average.

There are many improvements to the LND process that can be applied in the future to allow the process to be more versatile. One improvement would be to use more efficient and different types of compressors. The XZ compressor is used here due to some testing performed that suggested that

XZ was the best commercial-off-the-shelf compressor for medical images. As new compressors are developed currently and in the future, replacing the XZ compression stage in the LND process would be easy and would allow the process to always be up-to-date.

69 The improvement listed above is minor compared to the two major improvements that would allow the LND process to be a great improvement in image compression. First, adding the predic- tion method, like machine learning, would allow the purposed LND process to perform better than

JPEG2000 as explained in Section 3.9. Another improvement is to deal with images with large amounts of noise. Currently, there is an overflow issue that could happen due to subtracting a pixel value of 255 from a neighboring pixel value of 0 resulting in a range of values from (-255,255). The

LND process relies on the property of pixel correlation in images where the value between the two neighboring pixels is not large. Taking care of the overflow issue would allow images with large amounts of noise to be sent into the LND process and be reconstructed lossslessly.

70 BIBLIOGRAPHY

[1] J. M. Santos, A. F. R. Guarda, L. A. da Silva Cruz, N. M. M. Rodrigues, and S. M. M. Faria, “Compression of medical images using mrp with bi-directional prediction and histogram - ing,” in 2016 Picture Coding Symposium (PCS), Dec 2016, pp. 1–5.

[2] R. Pizzolante and B. Carpentieri, “Lossless, low-complexity, compression of three- dimensional volumetric medical images via linear prediction,” in 2013 18th International Con- ference on Digital Signal Processing (DSP), July 2013, pp. 1–6.

[3] N. Goel, A. Yadav, and B. M. Singh, “Medical image processing: A review,” in 2016 Second International Innovative Applications of Computational Intelligence on Power, Energy and Controls with their Impact on Humanity (CIPECH), Nov 2016, pp. 57–62.

[4] M. A. Kabir and M. R. H. Mondal, “Edge-based transformation and entropy coding for lossless image compression,” in 2017 International Conference on Electrical, Computer and Commu- nication Engineering (ECCE), Feb 2017, pp. 717–722.

[5] M. S. Ibraheem, S. Z. Ahmed, K. Hachicha, S. Hochberg, and P. Garda, “Medical images compression with clinical diagnostic quality using logarithmic dwt,” in 2016 IEEE-EMBS International Conference on Biomedical and Health Informatics (BHI), Feb 2016, pp. 402– 405.

[6] A. D. M. R., M. G. Ahamad, and D. Ravichandran, “Medical image compression using em- bedded zerotree wavelet (ezw) coder,” in 2016 International Conference System Modeling Advancement in Research Trends (SMART), Nov 2016, pp. 17–23.

[7] P. Jindal and R. B. Kaur, “Lossless image compression for storage reduction using pollination based optimization,” in 2016 International Conference on Communication and Electronics Systems (ICCES), Oct 2016, pp. 1–6.

[8] J. Weiss and D. Schremp, “Putting data on a diet,” IEEE Spectrum, vol. 30, no. 8, pp. 36–39, Aug 1993.

[9] L. Collin. (2007) Tukaani project: Xz utils. [Online]. Available: https://tukaani.org/

[10] J. Miano, Compressed Image File Formats: JPEG, PNG, GIF, XBM, BMP. New York, NY, USA: ACM Press/Addison-Wesley Publishing Co., 1999. 71 [11] T. Lane. (1999, mar) Image compression faq, part 1/2. [Online]. Available: http://artscene.textfiles.com/information/jpeg-faq-part1.html

[12] D. Santa-Cruz, T. Ebrahimi, J. Askelof, M. Larsson, and C. A. Christopoulos, “Jpeg 2000 still image coding versus other standards,” Proc. SPIE, vol. 4115, pp. 446–454, 2000. [Online]. Available: http://dx.doi.org/10.1117/12.411564

72