Final Report
Final Report
REPORT
ON
AT
2022
1
A
REPORT
ON
2022
2
DECLARATION
I, Joopally Vedarutvija hereby declare that my Project Report entitled “IMAGE PROCESSING
AND ANALYSIS” is a bonafide record of the work which is uniquely prepared by me on the basis
of my own work that I have submitted to ICFAI Foundation for Higher Education in academic
fulfillment of Internship – II at IP station National Informatics Centre, Hyderabad.
3
Faculty of Science & Technology, IFHE University
Key Words:
• Computer Vision
• Image Processing
• Pillow
• Open CV
• Tensorflow
• Pytorch
Project Area: Image Comparison and Analysis
4
Acknowledgment
I’m glad to be working on this research project i.e, Image Processing and Analysis under the
guidance of Ms. Annapurna madam and under the supervision of Ms. Radha madam and Dr.
Avinash Malladi sir
Thanks to Avinash Sir for his kind and understanding nature, giving us the freedom to work for
NIC without any evaluation pressure on us. Making sure that we are comfortable in working and
safe at the company. I'd want to express my gratitude to Avinash Malladi sir for continuously
taking updates about our work and if we are facing any difficulties.
Thanks to our point of contact Radha mam from the company for giving me this opportunity to
work on the Artificial Intelligence Project under Annapurna mam. A special thanks for giving us
the freedom in working on the projects that interests us with good consent. It gives pleasure in
discussing environmental projects that she assigns tasks, without her support, it would have been
difficult to work on projects other than AI at NIC.
Special thanks to my guide and mentor Annapurna mam for showing immense support in the
completion of this project with a great understanding and kind nature. It brings immense pleasure in
working under my mentor who is always available for me for any kind of help within or outside the
project work. The step-by-step aligned tasks that madam assigns us gives a great clarity in
understanding the concepts deeper and better. The interlinked technical tasks bring us hands-on
experience that helps me in my future research projects. It would have not been possible without
her guidance and support.
Thanks to IcfaiTech for providing such an amazing opportunity to work at the National Informatics
Centre for a duration of 6 months to foster our practical knowledge and skills.
5
Abstract
This research work aims to predict which image format and library/framework are better for
performing image processing tasks. The image formats considered in our project work are JPEG or
JPG, BMP, PNG, TIFF, and PNG.
We started by comparing two same images of different resolutions, different sizes, and different
formats (JPG, PNG, BMP, GIF and TIFF ) to find out which format is the best and how well python
libraries or frameworks work in identifying the differences in the images before and after resizing
them.
Next, we dived a little deeper and integrated the task with a java program to get output from the
bulk of images. First, uploaded the images along with their RGB data values in the PostgreSQL
database and retrieved them back onto the web page. Next downloaded the data from the database
as a CSV file and compared the images using python with the given input data iteratively along all
the data columns.
After we are successful in performing all the above tasks by our analysis we come to a final
conclusion that bitmap images are good for image processing and pillow library in addition with
TensorFlow framework works is better than OpenCV, and TensorFlow is one of the best for
computer vision as it is a framework and is provided with necessary tools for better processing.The
OpenCV library needs modifications to work better.
6
TABLE OF CONTENTS
1 Introduction…………………………………………………………………………………….…8
1.2 Computer Vision…………………………………………………………………………..... 11
1.3 Pixels…………………………………………………………………….…………….….….12
1.4 Image…………………………………………………………….………………………..….12
2.1 OpenCV……………………………………………………………………………………….19
2.2 Pillow………………………………………………………………………………………….20
2.3 TensorFlow…………………………………………………………………………………...21
3 Image Comparison………………………………………………………………………………22
8 Conclusion ……………………………………..…………………….…………………………..46
7
References……...…………………………………………………………………………………..48
Appendices……………………...………………………………………………………………….49
Glossary…………………………………………………………………………………………….50
8
Chapter 1 – Introduction to Image Processing
Image Processing is a type of signal processing that involves performing operations on images for
obtaining desired output. There are many image processing techniques we can use in predicting the
results using advanced algorithms in machine learning and deep learning. In our research, we
compared two same images of different formats, different resolutions, and different sizes and
analyzed the results. All the image file formats don’t have the same information stored, and each
Working with image processing techniques, it is important to understand the difference in the
information stored in the digital images that we process. One has to keep in mind which file format
In our study, we used the famous library OpenCV and Pillow library to work on the images to
As technology is growing drastically day by day, undoubtedly there is a rapid growth in the internet
for storage. Each day billions of images are clicked. Collecting and analyzing those images may
give us amazing results. There are many different applications of image processing in the areas of
space, medical, traffic, and banking, such as planet discovery, brain tumor detection, fraud
detection, and object detection etc. The objective of this research is to compare and analysis the
images and their formats then conclude the best format for performing image processing tasks. We
used open-source python libraries, OpenCV, and Pillow which are helpful in the computer vision
area.
9
1.1 Integrated Development Environment
Anaconda is a Python and R programming language distribution aimed for simplifying package
management and deployment in scientific computing (data science, machine learning applications,
large-scale data processing, predictive analytics, and so on). Data science software for Windows,
Linux, and macOS are included in it. Anaconda, Inc., was created in 2012 by Peter Wang and
Travis Oliphant, and developers maintain it. Anaconda comes with Jupyter Notebook, the software
A Jupyter notebook is an open source IDE (Integrated Development Environment) which is used to
work on data science tasks using languages like Python, Julia, Scala, R etc. But in our work we
Notebooks are becoming an important element of the data science process at firms all around the
world, they are also very helpful in teaching data Science to students in universities and Schools as
it's a single page in which we can execute code, view the results, and add explanations, formulae,
and charts to make our work more clear, intelligible, repeatable, and sharable. If we want to work
with data, having a Notebook can help us get there faster and make it easier to discuss and share our
findings.
The python libraries and packages we’ll use in this project are namely:
10
• NumPy
• Pandas
• Pillow
• Matplotlib
• OpenCV
• Scikit-learn
• Tensorflow
Computer vision is the process of understanding how pictures and videos are stored and how we
may change and retrieve data from them. It is the field of Artificial Intelligence which trains to
understand and interpret the visual world. It is becoming increasingly important in self-driving cars,
robots, and picture-editing apps. Computer vision models can easily understand digital images from
cameras and videos using deep learning techniques but it is still a huge research area to train the
models to work even better. There are many different python libraries used in support of computer
vision to perform visual tasks. The next chapter clearly mentions about the python libraries and
11
1.3 Pixels
Pixels are the core elements of the images, abbreviated as px. The size of the pixel depends on how
we set the resolution, the higher the resolution, the higher the pixel values, and vice versa. Each
pixel is a sample unit of the original image, higher samples give an accurate representation of the
original image which is clear. A simple way to describe each pixel is by using a combination of the
three colors Red, Blue and Green (RGB). If all three values are 255 (infinity) that means it is a
white color and if all of them are set to 0 it shows black color. As each digit is an 8-bit digit the
1.4 Image
and is processed as signals by optical devices. The two fundamental image format types are raster
images and vector images (some formats, however, allow a mix of the two).
12
1.4.1 Raster image: Raster images contain pixel values arranged in a matrix fashion. These are the
pictures that result from scanning or photographing an item. Raster pictures are created by
combining pixels, or small dots, each of which has unique colour and tone information.
Raster pictures are resolution dependent since they are pixel-based. The number of pixels in a
picture, as well as the number of pixels displayed per inch, both determine image quality. As you
can expect, the greater the resolution and the number of pixels in an image, the higher the quality of
1.4.2 Vector image: Vector images are characterized as geometric objects using continuous
coordinates. The image quality of these types of images is good compared to raster images. They
are infinitely scalable as they are made of line art or paths. Examples of vector images are SVG,
PDF, and EPS and examples of raster images are JPG, PN, BMP, and GIF. The resolution of
In our research, we mainly focus on raster images and work on them to find the differences and
An RGB picture is three images layered on top of each other (a red scale image, a green scale
image, and a blue scale image), and when fed into the red, green, and blue inputs of a colour
Because of the accuracy with which a real-life image can be duplicated, an RGB image is also
Each parameter (red, green, and blue) specifies the color's intensity with a value between 0 and 255.
This means that there are 256 × 256 x 256 = 16777216 different colors.
13
For example, RGB (255, 0, 0) is rendered as red because red is set to its greatest value 255, while
Another example is RGB (0, 255, 0), which is shown as green because green is set to its maximum
value 255, while the other two (red and blue) are set to 0.
To display black, set all color parameters to 0, as seen below: RGB (0, 0, 0).
To display white, set all color parameters to 255, as seen here: RGB (255, 255, 255).
There are different image file formats and each has its own advantages and disadvantages. In this
section, we will study each image format in detail. We have considered JPEG/JPG, PNG, BMP, and
1.6.1 JPG
JPG (Joint Photographic Experts Group) is a standard image file format and requires less storage
than other formats. It uses a lossy compression algorithm which means there is a loss in the image
information while reducing the number of bits to represent the given information unlike PNG
(Portable Network Graphics), BMP(Bitmap Image File), and GIF. Alpha channel is absent in JPG.
The format is widely chosen for storing and sending photographic pictures over the internet.
Almost all operating systems now provide viewers that handle the display of JPEG pictures, which
are frequently saved with the JPG extension. The steps involved in JPG file compression is as
follows.
14
Steps involved in Compression:
Transformation: Color photos are converted from RGB to luminance/chrominance images (the
eye is sensitive to brightness rather than chrominance, therefore the chrominance component can
Down Sampling: The coloured component is down sampled, not the brightness component. Down
sampling is done in a 2:1 horizontally and 1:1 vertically ratio (2h 1 V). As a result of not touching
the 'y' component, the image shrinks in size while maintaining visual quality.
Organizing in groups: Each colour component's pixels are grouped in groups of 82 pixels called
"data units." If the number of rows or columns is not a multiple of 8, the bottom row and rightmost
Discrete Cosine Transform: Discrete Cosine Transform (DCT) is performed to each data unit to
provide an 8-map of changed components. Due to the limited accuracy of computer arithmetic,
DCT implies some information loss. This implies that even if the map is not there, there will be
Quantization: Each of the 64 altered components in the data unit is divided by a distinct value
known as the QC and then rounded to an integer. This is where information is irretrievably lost, and
high QC causes even more loss. In general, most JPEG implementations permit the use of QC
Encoding: Each data unit's 64 quantized transformed coefficients (now integers) are encoded using
15
Adding Header: The last step adds a header and all of the JPEG parameters that were used, and
The JPEG decoder reverses the processes to create the original picture from the compressed one.
2.2 PNG
PNG (Portable Network Graphics) pictures can be palette-based (with palettes of 24-bit RGB or 32-
bit RGBA colours), grayscale (with or without an alpha channel for transparency), or full-color
RGB or RGBA images. Because the PNG working group created the format for Internet image
transfer rather than professional-quality print graphics, non-RGB colour spaces such as CMYK are
not supported. A PNG file comprises a single picture in an extensible chunk structure, storing basic
pixels as well as additional information such as textual comments and integrity checks.PNG files
support transparent backgrounds which are preferable for graphic designs and can also be used as
frames for making a GIF image. It can be with or without an alpha channel and supports up to 16
million colors.
Medical Imaging is the main application area of PNG images because the reconstructed image after
decompression is exactly the same as the original image. The PNG files are stored with an
extension .png.
2.3 BMP
Bitmap Image Files (BMP) on the other hand contain bitmap graphics data, they are independent of
the device so they are known as Device Independent Bitmap (DIB). This independence allows the
file to be opened on different systems, including Microsoft Windows and Mac. Image data is
16
usually uncompressed or compressed with a lossless compression algorithm. It also contains an
The BMP file format may store two-dimensional digital pictures in monochrome and colour, with
varying colour depths and optional data compression, alpha channels, and colour profiles. The BMP
2.4 GIF
GIF(Graphics Interchange Format) uses a lossless compression algorithm it occupies less space and
is limited to 256 colors. The image contains multiple frames. Multiple JPG or PNG files together
make up a GIF file. Because it is animated video graphics. The format allows for up to 8 bits per
pixel for each picture, allowing a single image to refer to its own palette of up to 256 distinct
colours selected from the 24-bit RGB colour space. It also enables animations and has a palette of
up to 256 colours for each frame. Because of these palette constraints, GIF is less appropriate for
replicating colour pictures and other images with colour gradients, but it is ideal for simpler images
such as designs or logos with solid colour sections. GIF files feature a fixed-sized graphical region
that contains zero or more pictures. In the case of animated GIF, certain GIF files break the fixed-
sized graphical region or blocks into sub-images capable of operating as animated frames. The GIF
format stores bitmap data at pixel depths ranging from 1 to 8 bits. To save photos, the RGB colour
model and palette data are always utilised. A fixed-length header ("GIF87a" or "GIF89a") specifies
2.5 TIFF
TIFF or TIF, Tagged Image File Format, is a file format that represents raster images for use on a
range of devices that support this file format standard. It may describe bilevel, grayscale, palette-
17
color, and full-color picture data in a variety of colour spaces. It supports both lossy and lossless
compression algorithms, allowing users of the format to select between space and time. The format
is not machine dependent and is not limited by constraints such as processor, operating system, or
file systems. The tiff images are saved as .tif format. After a series of discussions with several
scanner manufacturers and software developers, Aldus Corporation invented the TIFF file format in
the fall of 1986. The fundamental goal of the TIFF file format was to create a standardized scanned
image file format for all desktop scanner suppliers. With the passage of time, the format expanded
from support for solely binary image formats to support for grayscale and colour images. Because
there were two previous draught releases, the original version of TIFF file format standards can be
classified as Reivision 3.0. In 1988, Revision 5.0 was released, which provided support for palette
18
2 Python Libraries and Frameworks
A library is a collection of packages that perform specific operations whereas a framework contains
the basic flow and architecture of an application. The major difference between them is the
complexity. Libraries contain a number of methods that a developer can just call whenever they
write code. In our project, we used Python’s PIL and OpenCV libraries whereas Tensorflow and
Pytorch frameworks
2.1 Open CV
OpenCV is a large open-source library for computer vision, machine learning, and image processing
tasks and it currently plays a significant part in real-time projects, which is critical in today's
systems. It can analyze photos and movies to recognize items, people, and even human handwriting
i.e, character or text recognition. Python can process the OpenCV array structure for analysis when
combined with other libraries such as NumPy. We can employ vector space and execute
mathematical operations on these characteristics to identify visual patterns and their different
features.
OpenCV by default uses integer accurate decompression method of the JPEG image. It adds half
19
pixel correction to the image while resizing and uses bilinear transformation technique. OpenCV
OpenCV is used to tackle a variety of problems, some of which are mentioned here.
• Anomaly (defect) detection in the manufacturing process (the odd defective products)
• object recognition
• Face recognition
2.2 Pillow
The Python Imaging Library (PIL) extends the Python interpreter's image-processing capabilities. It
includes lightweight image processing tools that help with picture editing, creation, and storing. This
library supports a wide range of file formats, has an efficient internal representation, and has robust
20
The core image library was created to provide quick access to data contained in a few fundamental
pixel formats which is a good starting point for broad image processing tasks.
Pillow is compatible with a wide range of image file types, including BMP, PNG, JPEG, and TIFF.
By providing new file decoders, the library supports the addition of support for future formats.
Pillow neither use half pixel correction method nor bilinear transformation technique for resizing of
the images. Pillow reads images in RGB format only. Pillow reads all the channels of the image by
default.
2.3 Tensorflow
TensorFlow is a framework developed by Google researchers to run machine learning deep learning
and other predictive and statistical workloads. It provides stable C++ and Python APIs, as well as
There are two steps involved in opening a JPEG image using Tensorflow they are
Step 2: Second step is to perform JPEG decoding because JPEG is a compressed image.
It can be referred from the introduction chapter in JPEG image format section.
Tensorflow is greatly used for deep learning and Machine learning models. Tensorflow works with
tensors. And for image resizing method expects a 4D tensor and returns a 4D tensor output only. To
make Tensorflow Consistant with OpenCV, we have to expand the image from three to four, then
resize the image and squeeze the dimentions back to three. As the image will still be a tensor we
should create and run a TensorFlow session to get back our resized image in NumPy format as
output.
21
3 Image Comparison
Image differencing is a method used in image processing to discover differences between pictures.
The difference between two photos is computed by calculating the difference between each pixel in
each image and then constructing an image based on the result. To use this approach, the two
pictures must first be aligned such that their corresponding points coincide, and their photometric
values must be made compatible, either by meticulous calibration or through post-processing (using
colour mapping). The amount of pre-processing required before differencing varies depending on
Comparing two completely different images( a rose with a sunflower) using Open CV and Pillow:
22
Graphical image output using OpenCV library
23
3.2 Comparison of two same images with different image properties
While comparison of images there can be huge varieties of image properties that can make an
image different, we have chosen the most important and effective image properties to analyze the
Resolution is crucial in image processing to analyze and study differences between two images. It
Changing the resolution (DPI – Dots per Inch ) of the image outputs both images as different with
OpenCV. The same is the case with Pillow library. When an image with low quality is compared to
an image of high quality, the PPI (Pixel Per Inch) varies in both images which makes a difference
in the quality of the image. The more the value higher the quality and vice versa. When we decrease
the quality and compare with high-quality image, the output we obtained is as shown using a pillow
library.
24
But when the same task is performed using OpenCV, we hardly see any difference in the graphical
image using our naked eye though the pixel values are different we see just a black image.
Comparing two images of different sizes gave us a completely black image as the output using the
OpenCV library. This implies the two images are equal, but when we compared the pixel values of
the two images, the values came out to be different. We also compared the images using the Pillow
library, and surprisingly we found the graphical image difference of the two images in not
25
3.2.3 Comparison of two same images of different formats
As we have studied in Chapter 1, there are different image file formats and each has its own
advantages and disadvantages. In this section, we will compare the differences in the image formats
and analyze them. We have considered JPG as a standard image and compared with all the other
formats like, PNG, BMP, and GIF. We also compared other possible formats along the process.
When the JPG image is compared with the PNG image we find a few of the pixel values different,
it can be due to the background that we get convinced when we visualize having both of the
pictures aside. This is because PNG files support transparent backgrounds which are preferable for
graphic designs and can also be used as frames for making a GIF image. It can be with or without
26
Medical Imaging is the main application area of PNG images because the reconstructed image after
The graphical image difference between both JPG and PNG using OpenCV is shown below
We get an error comparing both images using Pillow libray because PNG has an extra alpha
channel in it the reason for not getting an error using OpenCV is that it only compares three
channels from both the images. Inorder to compare the images using Pillow library, we have to
convert both images in RGB form and then perform comparison on the images. The graphical
27
The difference is seen even more clearly using Pillow library.
When BMP format is compared with JPG in OpenCV we get the output image which is completely
black, this happens when both the image’s pixel values get matched and when subtracted we get 0
values indicating a black color this shows the images are similar. Hence the graphical image output
28
is completely black image using OpenCV library. But when the same task is performed using the
Pillow library, the pixel-wise comparison of two images gave false as the output. Surprisingly the
graphical image output of the difference is not a completely black image. We observed some light
Then after our analysis, we found that the OpenCV library only compared 3 channels from the
BMP file whereas the pillow library also compared the fourth channel i.e., alpha(same in the case
with PNG as well). Hence the output image is as follows with light blue lines on the image output
as highlighted.
29
3.2.3.3 GIF with JPG
Multiple JPG or PNG files together make up a GIF file. Because it is animated video graphics.
Hence the comparison of a JPG or PNG file format with a GIF file is unveiled. It is not possible to
compare GIF, a multi-frame image with JPG, which is a single-frame image. In order to achieve
this, the frames from the GIF image file need to be extracted to be compared with a JPG file with a
single frame iteratively. But doing this is not useful, because in this case, we will be comparing a
JPG file with a JPG file that is present in GIF. So, to accomplish this task we have converted a GIF
file to RGB format and then compared it with the RGB format of a JPG image. We got the
30
3.2.3.4 GIF with PNG
In the same way as the previous section above, when a GIF image is compared with a PNG file, the
A TIFF image format is converted into BMP format and then compared with the original TIFF
The graphical image output is shown in the next page when both images are directly compared
It can be clearly seen that there are some layer-like paint structures observed which is similar to
when we use the same color colour-pencil and highlight it dark at some places and light at other
places.
31
Image pixel values in both images are equal with no difference in their size or resolution.
Since the image pixel values are equal, we got a complete black image as the output when their
RGB images are compared which doesn’t mean both the images are same and equal.
The output when the images are compared after converting them into RGB can be seen below.
32
We got a completely black image using RGB-wise comparison of the images, so RGB comparison
doesn’t conclude the images to be the same or different, from the above research it is clear that,
though the pixel values are the same images are different.
Grayscale pictures are a subset of bilevel images. Bilevel pictures can only contain black-and-white
33
image data, but grayscale images can hold shades of grey. Grayscale photos in Baseline TIFF can
Baseline TIFF grayscale pictures can have values between 4 and 8, allowing for either 16 or 256
In order to compare a grayscale image with another grayscale image we have to first extract their
RGB values or the binary data (01) and then compare the binary values with each other to check if
they are matching. The output is a boolean variable i.e, if the images match we get a true value
In the next section, we work with multiple bulk-class images which are stored in the database using
Java Programming language and are retrieved as a CSV file. For the same, we use a binary
comparison technique iteratively over all the cells of the column to identify the class of the image.
34
4. Inserting and Retriving Images from DB
Till 3rd chapter we understood python libraries and frameworks using the python programming
language, now we will use java programming to insert the images and retrieve them to compare
Multiple languages are supported and other features may be readily combined into any of the preset
Above is the workplace of eclipse IDE to run any java programs so we will use this as our IDE to
35
4.2 PostgreSQL
We use postgres as our backend database to store the data and work on it. PostgreSQL is a
sophisticated, open-source object-relational database system that has been actively developed for
over 35 years and has a high reputation for dependability, feature robustness, and speed.
Postgres is similar to that of SQL, where in we have to run SQL queries to interact, change or
So first we have to install Tomcat Server on Eclipse IDE and connect it, then we run our program
on the webpage as it is visible to us what changes we make in the program. After retrieving the
images on to the webpage using the Java Code we need to download the CSV file which contains
the Binary Data of the stored images. The next step is the insert the CSV file back into jupyter
notebook and use a for loop to run and compare the Binary data iteratively to check if the data
matches with the given input and output the result if the match is found.
36
In the same way the Binary data is compared and the result of the image class is mapped with the id
37
5 Comparison of frameworks/libraries for Processing
Modern Computer Vision (CV) is a trendy topic of study that mostly includes dealing with pictures.
To do this, one must utilise a framework to open the photos and perform some processing on them.
In today's fast-paced framework development, each framework has its own manner of managing
pictures, each with its own set of standards. As a result, CV solutions designed in one framework
may not operate as intended in another. It might take many days to figure out what went wrong,
which can significantly delay the project. In this chapter we have compared the frameworks with
We first used OpenCV library to compare with the reults with that of Tensorflow and then continue
38
Something is odd with the figure above. It does not resemble the original. We first have to
understanf how colours in photographs are represented. In general, pictures have three colour
channels that create the colours in the pixel: red, green, and blue (RGB). The sequence of these
channels affects the colour of the pixels, as pixels always perceive the first channel as red, the
However, when the image is shown, the pixels misread the channels (i.e. pixels get confused and
interpret Blue as Red and vice-versa). That is why the picture above has the incorrect colours. So,
we transform the picture from BGR to RGB after opening it. We do this by using the OpenCV
setting COLOR BGR2RGB. The code below demonstrates how to properly open an image with
OpenCV. After understanding how colour channels function in an image, ws investigated why we
39
observed a different colour image above. When we open an image using OpenCV, it opens the
Then we opened a picture in Tensorflow and checked whether we obtain the same results. It takes
two steps to open a JPEG picture in Tensorflow. The first step is to open the picture, followed by
40
Visually, the images read by OpenCV and Tensorflow appear to be the same. Subtracting the two
we discover a significant differences. If the two are identical, the picture should be totally black.
But we have seen a huge difference. This disparity is due to the fact that OpenCV utilises integer
correct decompression of the JPEG picture by default. TensorFlow, on the other hand, employs the
Discrete Cosine Transform as the default as mentioned in Chapter 3 about frameworks and
libraries. This method of decoding is wrong in tensorflow, we must decode it using integer-accurate
And then, when we compare it with the OpenCV picture, we obtain a black image. This indicates
that both our TF and OpenCV are now interpreting the picture consistently. This is an important
stage because even little variations in how we read the image might result in major differences in
41
The result we obtained after comparing the resized pictures from OpenCV and TF.
And now we got the anticipated outcome. Finally, Tensorflow and OpenCV are continuously
When moving from one framework to another, minute details like what we have seen must be
reviewed and maintained. Otherwise, they will produce different outcomes in different frameworks,
Differences between PIL and OpenCV are analyzed below. First, we read the image using PiL
library.
42
The output after comparing the results of Tensorflow with the Pillow image just like we did it using
OpenCV is as shown:
This indicates that, unlike OpenCV, Pillow and Tensorflow read the image properly in RGB
format.
Then we tested if there is any difference between the JPEG picture opened by PIL and the one
opened by OpenCV
43
There is a lot of difference as we can see above. Hence the resizing mechanism of the two
frameworks differs significantly once again. Even when we opened the pictures in both frameworks
regularly, the resizing approach produced different outcomes. By default, the OpenCV resize
method employs bilinear transformation. With Tensorflow, we applied the same bilinear technique.
Nonetheless, our outcomes differed. This occurred as a result of OpenCV's usage of half-pixel
adjustments when scaling images. Tensorflow, on the other hand, does not by default. This sums up
the resizing method output differences. To address this issue, there is a parameter in the
44
As a result, the desired difference in resizing is obtained. Because the PIL library does not allow
half-pixel correction, it is not enabled by default. We may assume the same findings when
evaluating the difference between PIL and TF because we know TF and OpenCV are consistent.
As a result, while utilizing the PIL framework, we should keep in mind that switching to another
framework is not an option if the task is dependent on picture pre-processing, as seen above. This
45
6 Conclusion
The images of different sizes, different resolutions, and different image formats have been
compared and analyzed. We have used two different libraries to achieve this. OpenCV (Open-
Source Computer Vision Library), developed by Intel, and Pillow (Python Imaging Library) by
In conclusion, we found that the pillow library is friendlier compared to OpenCV and gives the
correct output. Because the pillow library can be used to compare images in depth. It uses all the
channels while comparing two images including the alpha channel. OpenCV is built in C and C++,
but PIL is written in Python and C, When dealing with 1000s of photos for data extraction,
processing the speed is critical, so after resizing images Pillow was faster in prosessing.
But there are some problems using OpenCV, it only compares three channels which shows the
pixelwise output is the same and it outputs both the images are completely the same, which we
concluded as wrong in our case with BMP file format. Similarly, OpenCV outputted a completely
black graphical image when two images of different sizes are compared. This can give a wrong
conclusion that both the images are the same but when the pillow library is used the difference is
shown clearly, as their pixel values are also not the same.
And From the section comparing BMP with TIFF, we concluded Bitmap image format is the best
for image processing as the pixel values are still the same the image are not the same. This
indicated the digital information captured in a Bitmap file in smaller points of bits is higher in
From chapter 5 it is clear that OpenCV reads images in BGR format while TensorFlow doesn’t,
which gives us a different output than a completely black image that is expected when the results of
46
OpenCV are compared to that of Tensorflow. But when the image read using Tensorflow is
compared to the image read using Pillow library we got a completely black image as output. This
means the pillow library and TensorFlow read the images properly as the original but to do the
same in the case with OpenCV, we have to convert the BGR format to RGB and compare the
images to get a completely black image. Pillow is better at working with fewer image formats but
our research concludes Tensorflow is better to use than OpenCV. Tensorflow along with Pillow
gave better results than OpenCV. So CV solutions requires to be modified to work better for image
processing tasks. This project is successful in identifying the best format for image processing as a
47
References
1. Comparison and analysis of Image File Formats Gomathi Kasi Viswanathan, et al.
2. Concise Report on Image Types, Image File Format and Noise Model for Image Preprocessing,
5. Image File Formats: Past, Presnt, and Future, Richard. Wiggins III, MD, et al. 2000.
48
Appendices
Steps involved in JPEG compression……………………………………………………….15
Transformation
Down Sampling
Organizing in groups
Quantization
Encoding
Adding Header
49
Glossary
1 JPEG -Joint Photographic Experts Group………………………………….………………………………………………………………15
50
51