Preprocessing for JPEG Compression

The objective of this project is to improve JPEG Compression used for gray scale images that contains several of objects.

Abstract
The objective of this project is to improve JPEG Compression used for gray scale images that contains several of objects. The requested improvement is size reduction of the image file, while maintaining the quality of the image.
JPEG Compression is mostly suitable for ‘smooth’ images with a small difference between neighbor pixels. It is also known that in JPEG Compression part of the information in the image gets lost and the quality of the image is damaged. Therefore the possibility of pre-processing the image was examined. Using this pre-processing, the image was separated to 2 images:
An image that holds the objects in the original image. Each object is represented by one gray level that is the average of the object’s gray levels.
A smooth image that was accepted after subtracting the objects’ image from the original picture. This image is visually meaningless but it enables efficient and qualitative JPEG Compression.
The first image is compressed in GIF format that is suitable for compression of images with several gray levels. The second image will be compressed in JPEG format.
In order to build the objects’ image, morphological operations were performed on the original image. These operations sharpen the edges of the objects in the image. After that there was labeling of the image after the morphological operations, using REGION GROWING algorithm.
After decompressing the 2 images and adding the matrices to one image, a comparison was made between the original image and the new image. The following parameters were checked:
The file size.
The image quality.

The goal is to compress the image as maximum as possible, meaning that the sum of the images files’ sizes is as small as can be in reference to the JPEG Compression of the original image, while maintaining high quality of the image.
The algorithm is implemented in MATLAB.
The algorithm receives as input a gray scale picture or RGB picture, which is converted to gray scale picture.
The picture is represented as a matrix.
Using morphologic operations (first erosion and then dilation, with cross element) the elements in the picture are clearer and easier to be recognized.
The recognition of the elements, using raster algorithm, begins at the left corner of the image and continues to the right, through the columns and down the rows. Each pixel is compared to its left pixel. If there is a difference, the pixel is compared to the upper pixel. If the pixel’s value is similar or ‘close’ to one of his neighbors (left or up), then the new pixel is part of an element that was already identified. Otherwise the pixel is apart of a new element. In a new matrix, each element is represented by a different value. At the end of this process, the elements that were recognized will appear in this matrix.
Using this matrix the average value of each element is calculated from the real values of the pixels in the original picture. If there are several elements with ‘close’ average values, they are united and the average value is calculated again. Now the matrix is ready to be compressed as a gif picture.
Subtracting the gif matrix from the original picture creates the jpeg matrix that will be compressed as a jpeg picture.
The two matrices are compressed and examined by a few factors in order to determine whether the algorithm succeeded.
The checked parameters are:
The size of files after the compression – this is the basic standard for the algorithm success, and the other parameters show the efficiency of the algorithm.
The MSE (mean square error) and the PSNR of the pictures – Those parameters give a numeric comparison of jpeg compression of the original picture versus the new suggested algorithm.
Visual test – after compressing the gif and jpeg pictures, they are decompressed and added. Then the resemblance to the original picture is examined visually.

Results
As mentioned before three parameters were examined:
Visual results
Pictures in which the objects had sharp and recognizable edges, and a big difference between the objects’ gray levels returned a final
picture that is identical to the original one.
MSE and PSNR
The computed values of those parameters are considered good and were located in the upper level of the MSE and PSNR scale.
File size
After compression all the pictures were in a smaller size in compare to their original size, meaning that the total size of the GIF and JPEG pictures was smaller than the size of the original picture. The total size was about 2/3 of the file size of the original picture.

Conclusions
The algorithm was found efficient for pictures with clear and sharp objects, meaning that each pixel can be easily related to it’s own object.
The definition of the project is dealing with such pictures and therefore the algorithm is successful. In all the pictures there was an improvement in the size of the picture, a reduction in the size of the file. The difference between the checked pictures was in the quality of the final picture. The JPEG Compression was made in different levels of compression and thus different qualities.
As for the quality of the decompressed picture, it was found out that the main factor is the difference between an object gray scale values (of its pixels) and the background or another object gray scale value.
23
The original image                                          The image after Morphology
1 6
The CLUSTER matrix                                    a separated object
4 5
a separated object                                          a separated object
78
The decompressed image                                 The image to be compressed as GIF

Acknowledgments
We would like to thank our supervisor Ari Shenhar for his support and guidance throughout this project.
Also we would like to thank the Ollendorff Minerva Center Fund which supported this project.