Image compression is the application of Data compression on digital images. In effect, the objective is to reduce redundancy of the image data in order to be able to store or transmit data in an efficient form.
INTEGRATED PROJECT REPORT
IMAGE COMPRESSION AND DECOMPRESSION
Submitted in partial fulfillment of the requirement for the Course
Integrated Project-II (CSP2204) of
COMPUTER SCIENCE AND ENGINEERING
Under the Guidance of: Submitted By:
Ms. Ankita Tuteja Vishesh
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
This is to be certified that the project entitled “Image Compression and Decompression
System” has been submitted for the Bachelor of Computer Science Engineering at Chitkara
University, Himachal Pradesh during the academic semester January 2016- May 2016 is
bonafide piece of project work carried out by Vishesh (1411981272), Shubham Kansal
(1411981225), Vipin Kumar (1411981265) and Vikrant Chaudhary (1411981261) towards the
partial fulfillment for the award of course Integrated Project (CSP-2204) under the guidance of
Ms. Ankita Tuteja and supervision.
Signature of Project Guide
Ms. Ankita Tuteja
(Assistant Professor, CSE Department)
We, Vishesh (1411981272), Shubham Kansal (1411981225), Vipin Kumar (1411981265) and
Vikrant Chaudhary (1411981261), B.E.-2014 of the Chitkara University, Himachal Pradesh
hereby declare that the Integrated Project Report entitled “Image Compression and
Decompression System” is an original work and data provided in the study is authentic to the
best of our knowledge. This report has not been submitted to any other Institute for the award
of any other course.
Sign. of Student 1 Sign. of Student 2 Sign. of Student 3 Sign. of Student 4
Vishesh Shubham Kansal Vipin Kumar Vikrant Chaudhary
1411981272 1411981225 1411981265 1411981261
The compression and decompression of continuous-tone images is important in document
management and transmission systems. Image compression is the application of Data
compression on digital images. In effect, the objective is to reduce redundancy of the image
data in order to be able to store or transmit data in an efficient form. Therefore, the theory of
data compression becomes more and more significant for reducing the data redundancy to
save more hardware space and transmission bandwidth. In computer science and information
theory, data compression or source coding is the process of encoding information using fewer
bits or other information-bearing units than an unencoded representation. Compression is
useful because it helps reduce the consumption of expensive resources such as hard disk space
or transmission bandwidth and Decompression is useful when we take quality of images is
taken into consideration. In this project, we briefly introduce both image compression and
It is our pleasure to be indebted to various people, who directly or indirectly contributed in the
development of this work and who influenced our thinking, behavior and acts during the
course of study.
We express our sincere gratitude to all for providing an opportunity to undergo Integrated
Project-II as the part of the curriculum.
We are thankful to “Ms. Ankita Tuteja” for her support, cooperation, and motivation provided
to us during the training for constant inspiration, presence and blessings.
Lastly, We would like to thank the almighty and our parents for their moral support and
friends with whom we shared our day-to day experience and received lots of suggestions that
improve our quality of work.
With Sincere Thanks,
Vishesh (1411981272), Shubham (1411981225), Vipin (1411981265), Vikrant (1411981261)
TABLE OF CONTENTS
List of Tables viii
List of Figures ix
Chapter 1: Introduction 1
1.1 Concept 2
1.2 Need of Compression 2
1.3 Image Compression 3
1.3.1 Advantages of Image Compression
1.3.2 Disadvantages of Image Compression
1.4 Image Decompression 3
1.4.1 Advantages of Image Decompression
1.4.2 Disadvantages of Image Decompression
1.5 Techniques used for Image Compression and De-Compression 4
Chapter 2: Literature Survey 8
Chapter 3: Methodology 10
3.1 Data Flow Diagram 12
3.2 Class Hierarchy 13
3.3 Software and Hardware Requirements 13
3.4 Layout of the project 14
3.4.1 Netbeans Part
3.4.2 Database Connectivity
Chapter 4: Modules 16
4.1 Compression Module 17
4.2 Decompression Module 21
Chapter 5: Results and Snapshots 22
5.1 Classes 23
5.2 Functions 28
Chapter 6: Conclusion and Future Scope 31
6.1 Conclusion 32
6.2 Future Scope 32
1.1 Concept :
In recent years, the development and demand of multimedia product grows increasingly fast,
contributing to insufficient bandwidth of network and storage of memory device. Therefore,
the theory of data compression becomes more and more significant for reducing the data
redundancy to save more hardware space and transmission bandwidth. In computer science
and information theory, data compression or source coding is the process of encoding
information using fewer bits or other information-bearing units than an unencoded
representation. Compression is useful because it helps reduce the consumption of expensive
resources such as hard disk space or transmission bandwidth and Decompression is useful
when we take quality of images is taken into consideration. In this project, we briefly
introduce both image compression and image decompression.
1.2 Need of Compression :
Compression means to convert a data of more memory storage to the lesser one. It is useful to
visit or re-visit the reasons why data compression is needed or useful.
One obvious reason is to save the cost of disk. While this may seem strange given that the
disks are cheap. First reason, for the uninitiated, is that the disks used for high-end systems are
not cheap. Secondly, there is rarely a single copy of the production data.
Second reason is the cost of managing the data. Larger the database, it takes longer to do the
Third reason is memory. Don’t we all wish we had more memory on our servers? Well, if the
data is compressed, you can fit more data in the same memory. So if you could compress the
data 50%, then suddenly you have increased your memory 100% (i.e. you can fit double the
size of the data). Is this not fantastic? Even if you have 64-bit machine with the capability for
huge amount of addressable memory, the databases, for most customers, is many order of
magnitude larger than the memory. So compression will benefit even for servers running on
64-bit architecture. Clearly your IO bound workloads are likely to see increase in
throughput with data compression as there is less data to be read.
1.3 Image Compression :
Image compression is an application of data compression that encodes the original image with
few bits. The objective of image compression is to reduce the redundancy of the image and to
store or transmit data in an efficient form. Image compression is minimizing the size in bytes
of a graphics file without degrading the quality of the image to an unacceptable level. It
involves minimization of the number of information carrying units, pixels. This means that an
image where adjacent pixels have almost the same values leads to spatial redundancy. The
reduction in file size allows more images to be stored in a given amount of disk or memory
space. It also reduces the time required for images to be sent over the Internet or downloaded
from Web pages.
1.3.1 Advantages of Image Compression :
Less disk space(more data in reality).
The quantity of bits used to store the data is reduced.
Faster insertion and deletion .
Faster file transfer.
Byte order independent.
Can zip up several small files into a single file
1.3.2 Disadvantages of Image Compression :
Effect of errors in transmission.
Slower for sophisticated methods.
Unknown byte/pixel relationship.
Need to decompress all previousdata.
1.4 Image De-Compression :
The major goal of Image decompression is to image decompression is to decode and
reconstruct the original image. It is an application to get a much better image in terms of
quality or size and also we can get original images from their compressed form where we need
that the quality of the image is high whether it may be of higher size.
1.4.1 Advantages of Image De-Compression :
Quality of the picture is maintained.
More advantageous where HD pictures are required.
Need not to decompress further.
Fine byte/pixel relationship.
1.4.2 Disadvantages of Image Compression :
Requires more disk space.
The quantity of bits used to store the data is increased.
Slower insertion and deletion .
Slower file transfer.
1.5 Techniques used for Image Compression and De-Compression :
There are several different ways in which image files can be compressed. For Internet use, the
two most common compressed graphic image formats are the JPEG format and the GIF
format. The JPEG method is more often used for photographs, while the GIF method is
commonly used for line art and other images in which geometric shapes are relatively simple.
Other techniques for image compression include the use of fractals and wavelets. These
methods have not gained widespread acceptance for use on the Internet as of this writing.
However, both methods offer promise because they offer higher compression ratios than the
JPEG or GIF methods for some types of images. Another new method that may in time
replace the GIF format is the PNG format.
It is very important to understand that there are two basic types of compression: lossless and
lossy. As the names imply, with lossless compression we will be able to reduce the number of
bytes required to represent the image without losing any information or contents; and with
lossy compression some information will be lost (discarded) in the compression.
A text file or program can be compressed without the introduction of errors, but only up to a
certain extent. This is called lossless compression. Beyond this point, errors are introduced. In
text and program files, it is crucial that compression be lossless because a single error can seriously
damage the meaning of a text file, or cause a program not to run. In image compression, a small loss in
quality is usually not noticeable. There is no "critical point" up to which compression works perfectly,
but beyond which it becomes impossible. When there is some tolerance for loss, the compression
factor can be greater than it can when there is no loss tolerance. For this reason, graphic images can be
compressed more than text files or programs.
One may ask why use lossy compression if computers are fast and smart and can deal with
complex algorithms for perfect compression and decompression. Since we are dealing with
images, in most cases losing some information will not compromise the visual quality of the
image and may yield much smaller file sizes. Partly this is because the human visual system is
not as accurate as we would like, and at the same time can easily deal with small details, often
ignoring them (can you really distinguish between the different 16777216 colors that can be
represented in the RGB digital color space?). In images we can expect some regions to have
almost the same color, and we've seen that repetition can lead to good compression.
Image processing algorithms basically use the redundant or almost-redundant information on
images to greatly reduce the number of bytes required to represent them. If a lossless format or
compression method is used, the algorithm will preserve the contents so it can be reproduced
exactly as the original, at the expense of a larger number of bytes to represent it. If a lossy
compression method is used, the algorithm will represent the image with fewer bytes but the
decompressed image will be slightly different from the original -- and for most applications
that will not matter. Exceptions are, of course, applications where the image must be stored
with the original content for further manipulation -- classification comes to mind.
Lossy compression algorithms often allow the user to set a value for the compression level for
the image, allowing the balance between quality and size. Few lossless algorithms allows this,
but often the trade is between better compression and faster processing -- better compression
requiring more processing time.
Image Compression using Java:
Using predefined ImageWriter class in java.
Here we use predefined class ImageWriteParam.
setCompressionmode() function is used.
Fig 1.3 (a) Original Image Fig 1.3 (b) Compressed Image
Data compression has only played a significant role in computing since the 1970s, when the
Internet was becoming more popular and the Lempel-Ziv algorithms were invented, but it has
a much longer history outside of computing. Morse code, invented in 1838, is the earliest
instance of data compression in that the most common letters in the English language such as
“e” and “t” are given shorter Morse codes. Later, as mainframe computers were starting to
take hold in 1949, Claude Shannon and Robert Fano invented Shannon-Fano coding. Their
algorithm assigns codes to symbols in a given block of data based on the probability of the
symbol occuring. The probability is of a symbol occuring is inversely proportional to the
length of the code, resulting in a shorter way to represent the data. Then many years passed
and images are also going to be used in most of the applications and there is a need to
compress those images so as to make the applications light. Many algorithms were designed
and implemented for the same like DCT algorithm, Huffman encoding technique used to
compress images. Our project is also doing the same. What we have taken into consideration
is to compress the image in terms of size by specifying the quality( high/normal/low). The
results we obtained after compressing are not that much poor but are quite similar to the
original image. Sometimes we need to send the file completely without any problem in that
case we can reduce the quality of the file. Reducing quality of images makes file transfer
process very easy and fast as they are of much bigger size. Today in this present time we are
not available with a lot of time/we want quick responses from every application and we have
tried to reduce application response time by compressing images in this project.
Image Compression is achieved by removing the redundancy in the image. Redundancies in
the image can be classified into three categories; inter-pixel or spatial redundancy, psycho-
visual redundancy and coding redundancy. Inter-pixel Redundancy: Natural images have high
degree of correlation among its pixels. This correlation is referred as inter-pixel redundancy or
spatial redundancy and is removed by either predictive coding or transform coding. Psycho-
visual redundancy: Images are normally meant for consumption of human eyes, which does
not respond with equal sensitivity to all visual information. The relative relevancy of various
image information components can be exploited to eliminate or reduce any amount of data that
is psycho-visually redundant. The process, which removes or reduces Psycho-visual
redundancy, is referred as quantization. Coding redundancy: variable-length codes matching to
the statistical model of the image or its processed version exploits the coding redundancy in
the image. Integral University, April 2014 PhD Thesis: Effective Image Compression for
Wireless Sensor Networks Naimur Rahman Kidwai 13 Lossy compression: An Image may be
lossy compressed by removing information, which are not redundant but irrelevant (psycho
visual redundancy). Lossy-compression introduces certain amount of distortion during
compression, resulting in more compression efficiency.
Anil Kumar et al. in their paper two image compression techniques namely, DCT and DWT
are simulated. They concluded that DWT technique is much efficient than DCT in quality and
efficiency wise but in performance time wise DCT is better than DWT. Swastik Das et al.
presented DWT and DCT transformations with their working. They concluded that image
compression is of prime importance in Real time applications like video conferencing where
data are transmitted through a channel. Using JPEG standard, DCT is used for mapping which
reduces the inter pixel redundancies followed by quantization which reduces the psycho visual
redundancies then coding redundancy is reduced by the use of optimal code word having
minimum average length. In JPEG 2000 standard of image compression DWT is used for
mapping, all other methods remaining same. They analysed that DWT is more general and
efficient than DCT.
3.2 Class Hierarchy :
o java.awt.Component (implements java.awt.image.ImageObserver,
o java.awt.Window (implements javax.accessibility.Accessible)
o java.awt.Frame (implements java.awt.MenuContainer)
o javax.swing.JFrame (implements
3.3 Software & Hardware Requirements :
Software requirements :
operating system :Windows 7/ Windows 8/ Windows 10
Languages : Java
Tools : Net Beans, Xampp
Hardware requirements :
Processor : 600 MHz or above.
RAM (SD/DDR) : 256 MB
Hard Disc : 30GB
3.4 Layout of the project :
3.4.1 Netbeans part:
First we have a frame through which we can sign up or login. In the frame we will take
username and password as inputs from user and then on clicking the login button the
application checks whether that username or password exists in the database or not. If
the username and password exists then the application will redirect the user to the
account page else it will display a message saying wrong username and password. On
the same frame we also have a button for signup through which user can create his/her
account if he/she not registered yet and we have also implemented the show password
and forgot password functionalities on the same frame. In the main page we have two
buttons named Compression and Decompression and the application will redirect the
user to the respective pages on clicking them. In Compression module we will load the
image on clicking the browse button and then upload the image in its original and
compressed form both in the database on clicking the upload button. On the same page
itself we have another button named myimages that will show all the images in the
form of tiles that user has uploaded in the database and then we can click on the image
to download it in its compressed. In Decompression module we have a dropdown list
listing the names of all the images that user has uploaded in the database and then we
can click on the button named Decompression to get the decompressed image. This is
all about this desktop application.
3.4.2 Database Connectivity:
Java Database Connectivity (JDBC) is an application programming interface (API) for
the programming language Java, which defines how a client may access a database. It
is part of the Java Standard Edition platform, from Oracle Corporation. It provides
methods to query and update data in a database, and is oriented towards relational
JDBC allows multiple implementations to exist and be used by the same application.
The API provides a mechanism for dynamically loading the correct Java packages and
registering them with the JDBC Driver Manager. The Driver Manager is used as a
connection factory for creating JDBC connections.
JDBC connections support creating and executing statements. These may be update
statements such as SQL's CREATE, INSERT, UPDATE and DELETE, or they may be
query statements such as SELECT.
Query statements return a JDBC row result set. The row result set is used to walk over
the result set. Individual columns in a row are retrieved either by name or by column
number. There may be any number of rows in the result set. The row result set has
metadata that describes the names of the columns and their types.
There is an extension to the basic JDBC API in the javax.sql. If a database operation
fails, JDBC raises an SQLException.
We have two tables under the database image compression:
1. Account(Id, Username, Password, SecurityQ, SecurityA)
2. Tbimages(Id, Username, Title, Original Compressed)
Field Type Null Default Extra
ID Int(11) No None Auto_Increment
Username Varchar(20) No None
Password Varchar(20) No None
SecurityQ Varchar(50) No None
SecurityA Varchar(50) No None
Table 3.1 User Account
Field Type Null Default Extra
ID Int(11) No None Auto_Increment
Username Varchar(20) No None
Title Varchar(100) No None
Original Longblob No None
Compressed Longblob No None
Table 3.2 Image Database
4.1 Compression Module :
Compression of image file is one of the important task when it comes to save the large number
of image files. It saves lot of space if you could compress the images when it is necessary. An
image can easily be compressed and stored through Java. Compression of image involves
converting an image into jpg and storing it. In order to compress an image, we read the image
and convert into BufferedImage object. Further, we get an ImageWriter from
getImageWritersByFormatName() method found in the ImageIO class. From this
ImageWriter, create an ImageWriteParam object. ImageWriteParam class is mainly used for
compression the images. Its syntax is given below:
Iterator<ImageWriter> list = ImageIO.getImageWritersByFormatName("jpg");
ImageWriteParam obj = writer_From_List.getDefaultWriteParam();
It has two methods which is mostly used for changing the compression settings:
setCompressionQuality() method used for setting the quality of the compressed image the
value between 0 to 1. A compression quality setting of 0.0 is most generically interpreted as
“high compression is important,” while a setting of 1.0 is most generically interpreted as “high
image quality is important.” Also we used method setCompressionMode() to set the mode of
the compression. The setCompressionMode() method takes Mode_EXPLICIT as the
Some of the other modes are described briefly:
It is a constant value that may be passed into methods to enable that feature for future
It is a constant value that may be passed into methods to disable that feature for future
It is a constant value that may be passed into methods to enable that feature for future
Apart from the compressions methods, there are other methods provided by the
ImageWriteParam class. They are described briefly:
It returns true if the writer can perform tiling with non-zero grid offsets while writing.
It returns a float indicating an estimate of the number of bits of output data for each bit
of input image data at the given quality level.
It returns the currently set Locale, or null if only a default Locale is supported.
It returns true if the current compression type provides lossless compression.
It removes any previous compression type and quality settings.
It removes any previous tile grid parameters specified by calls to setTiling.
When you execute the code, it compresses the image to its equivalent compressed image
according to the choosen quality factor and writes it on the hard disk with the
4.2 Decompression Module :
It is an application to get a much better image in terms of quality or size and also we can get
original images from their compressed form where we need that the quality of the image is
high whether it may be of higher size.
Fig 4.5 Compressed Image
Fig 4.6 Decompressed Image
RESULTS AND SNAPSHOTS
5.1 Classes :
This class is being used for database connectivity. It is building a connection between
database server and java project.
Fig 5.1.1 Database Connectivity
It is jframe which acts as the login page of the project. It provides access to the project
to the registered users by identifying and authenticating themselves. This frame links
to three different frames:
ForgotPassword: In case users forgots his/her password he/she can change the
password by entering username and answering the security question set while
SignUp: For new users to register themselves and create their account.
This frame refers to the user account page and it contains to buttons that links to two
different modules: compression and decompression. User can choose any of the
functionality according to the need. Clicking on “compression” button will redirect the
user to compression page where user can upload images and compress it choosing
some quality according to the requirement. Clicking on “decompression” button will
redirect the user to decompression page where user can select uploaded and
compressed images to decompress and save it on the system. It also contains a button
with an option of change user password where user can change his/her password.
Fig 5.1.4 User Account Page Fig 5.1.5 Change Password Page
This frame contains the functionality of compression module. In this frame user
browse for the image on system and upload the image on the database. Before
uploading user needs to choose the quality of image after compression. Size of image
after compression depends on the quality choosen, i.e, choosing high quality will result
in compressed image bigger in size than that with normal or low quality. As soon as
the user clicks on the upload button compression process takes place and the original
image and compressed image gets stored in the database.
Fig 5.1.6 Compression Page
Using this frame user can choose uploaded and compressed images and can save it on
his/her system by selecting the image and clicking on download button on joptionpane.
Compressed images stored in the database are displayed on this frame in in form of
tiles with the help of jtable and its functions.
Fig 5.1.7 jTable
Fig 5.1.8 My Images Page
This frame consists of decompression part. In this frame user is allowed to choose
image from the the list of previously uploaded images. When user clicks on
“decompress” button he/she needs to choose the path where he/she wants to store the
decompressed image on the system and the extention in which he wants to write the
image.Choosing the correct extenstion is important as it decides the quality of image.
Fig 5.1.9 jFileChooser Syntax
Fig 5.1.10 Decompression Page
5.2 Functions :
Compression and Decompression
In order to compress an image, we read the image and convert into BufferedImage
object. Further, we get an ImageWriter from getImageWritersByFormatName()
method found in the ImageIO class. From this ImageWriter, create an
Fig 5.2.1 ImageWriter Syntax
We convert a BufferedImage to byte array in order to send it to server. We use Java
class ByteArrayOutputStream, which can be found underjava.io package. Its syntax is
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", baos);
In order to convert the image to byte array, we use toByteArray() method of
ByteArrayOutputStream class. Its syntax is given below:
byte bytes = baos.toByteArray();
Fig 5.2.2 Image Upload Syntax
To get the image from the databse and download it on system follwing functins are
Fig 5.2.3 Image Download Syntax
When you execute the code given above, output something like this seen:
Fig 5.2.3 Image Download Output
CONCLUSION AND FUTURE SCOPE
Data compression is very important in the computing world and it is commonly used by many
applications, including the suite of SyncBack programs. In providing a brief overview on how
compression works in general it is hoped this project allows users of data compression to
weigh the advantages and disadvantages.
6.2 Future Scope
In this project, many of the current important image compression and encryption techniques
have been presented and analyzed. The best way of fast and secure transmission is by using
compression and encryption of multimedia data like images. The compression technique
observed is either lossy or lossless. Always lossless compression is preferred but to achieve
secrecy some image quality degradation is accepted. Encryption applied by different
researchers by means of encrypting algorithm which encrypt the entire or partial multimedia
bit sequence using a fast conventional cryptosystem. Much of the past and current research
targets encrypting only a carefully selected part of the image bitstream in order to reduce the
computational load, and yet keep the security level high. In the proposed approach the key is
required to send separately. This is a different issue of securely transmitting the secret key.
Future scope of the proposed work is that we can design the mechanism to securely transmit
the key so that unauthorized person should have no access to it.