Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
63 views49 pages

Image Processing Internship Report

This document summarizes a student's internship report on image processing and analysis conducted at the National Informatics Centre in Hyderabad, India from July 2022 to December 2022. The student used Python libraries like OpenCV and Pillow to compare different image formats, resolutions, and sizes. Key findings were that Pillow was more accurate than OpenCV for image processing tasks and the Bitmap format was best for image processing. The internship provided hands-on experience in areas like computer vision, image comparison, and one class classification.

Uploaded by

Vedarutvija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views49 pages

Image Processing Internship Report

This document summarizes a student's internship report on image processing and analysis conducted at the National Informatics Centre in Hyderabad, India from July 2022 to December 2022. The student used Python libraries like OpenCV and Pillow to compare different image formats, resolutions, and sizes. Key findings were that Pillow was more accurate than OpenCV for image processing tasks and the Bitmap format was best for image processing. The internship provided hands-on experience in areas like computer vision, image comparison, and one class classification.

Uploaded by

Vedarutvija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

A

REPORT

ON

IMAGE PROCESSING AND ANALYSIS


BY

Name of the Student: J Vedarutvija ID.No. 19STUCHH010281

AT

National Informatics Centre, Hyderabad


An Internship Program - II
station of

Faculty of Science & Technology,

The ICFAI Foundation for Higher Education, Hyderabad

(2022)

1
A

REPORT

ON

IMAGE PROCESSING AND ANALYSIS


BY

Name of the Student: J Vedarutvija ID.No. 19STUCHH010281

AT

National Informatics Centre, Hyderabad


An Internship Program - II
station of

Faculty of Science & Technology,

The ICFAI Foundation for Higher Education, Hyderabad

(2022)

2
Faculty of Science & Technology, IFHE University

Station: National Informatics Centre Centre: Hyderabad

Duration: 6 months Date of Start: 01-July-2022

Date of Submission: 12-December-2022

Title of the Project: Image Processing and Analysis

Name of the student: Joopally Vedarutvija

Name of the Company’s mentors: Ms. Annapurna, Technical Director (Scientist-E)

Name of the IP Faculty: Avinash Malladi

Key Words:
• Computer Vision
• Image Processing
• Pillow
• Open CV
• Classification
• Tensorflow
• Grayscale
• Binary

Project Areas:
• Image Comparison and Analysis
• One class classification

Signature(s) of Student(s) Signature of IP Faculty


Date: Date:
3
Acknowledgment
I’m glad to be working on this research project i.e, Image Processing and Analysis under the
guidance of Annapurna madam and under the supervision of 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 comfortably 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.

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 us a great clarity in
understanding the concepts deeper and better. The interlinked technical tasks gives 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 National Informatics
Centre for a duration of 6 months to foster our practical knowledge and skills.

4
ii

Abstract
The preparation of this internship report would not have been possible without the
help and cooperation of a large number of people and organizations. We consider
ourselves extremely fortunate to have received this throughout our internship.

Annapurna mam, our company (National Informatics Centre) mentor, provided me


with this opportunity to work as an intern whose contributions in generating
suggestions and encouragement enabled me to successfully finish our project.

I'd want to express my gratitude to Avinash Malladi Sir for guiding us through this
opportunity to work as interns, as well as for assisting and supporting me during this
project.

TABLE OF CONTENTS
1 Introduction………………………………………………………………………………………8
5
1.1 Anaconda Jupyter Notebook…………………………………………………………………..9
1.2 Computer Vision…………………………………………………………………………..... 10

1.2.1 Open CV………………………………………………………………………………..11

1.2.2 Pillow………………………………………………………………………………..….12

1.2 Pixels……………………………………………………………………………………….….13

1.3 Image………………………………………………………………………………………..…13

1.4 RGB values…………………………………………………………………………………….14

2 Image Formats…………………………………………………………………………………..15

2.1 JPG…………………………………………………………………………………………….15

2.2 PNG…………………………………………………………………………………………....17

2.3 BMP……………………………………………………………………………………………17

2.4 GIF……………………………………………………………………………………………..18

2.5 TIFF……………………………………………………………………………………………19

2.6 Binary or Grayscale…………………………………………………………………………….19

3 Image Comparison………………………………………………………………………………21

3.1 Comparison of two different images…………………………………………………………..21

3.2 Comparison of two same images with different image properties………………………..23

3.2.1 Comparison of two Same images of different Resolution……………….…………..……23

3.2.2 Comparison of two Same images of different Size……. …………………..……………..24

3.2.3 Comparison of two Same images of different Formats …………………………………..25

3.2.3.1 JPG with JPG………………………………………………………………………25.

3.2.3.2 PNG with JPG……………………………………………………………………………..25.

6
3.2.3.3 BMP with JPG……………………………………………………………………………..27

3.2.3.4 GIF with JPG………………………………………………………………………………28

3.2.3.5 TIFF With BMP……………………………………………………………………………30

3.2.3.6 Grayscale with Grayscale…………………………………………………………………..32

4 Inserting and retriving images from DB...…………………………..…………………………33

5 Comparison of frameworks/libraries for processing.…………………………………………36

8 Conclusion ……………………………………..………………………………………………..45

Aprndi

Chapter 1 – Introduction
7
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. In our analysis, we found working with the pillow library is more accurate than working with

the OpenCV library and best format for image processing is Bitmap.

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

file has its own applications and advantages.

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

helps in what kind of scenarios.

In our study, we used the famous library OpenCV and Pillow library to work on the images to

understand the differences in them.

1.2 Anaconda Jupyter Notebook

8
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 the release. Anaconda, Inc., created in 2012 by Peter Wang and

Travis Oliphant, develops and maintains it. Anaconda comes with Jupyter Notebook, the software

is free to download and deploy the python codes.

A Jupyter notebook is a document that mixes graphics, narrative prose, mathematical formulae, and

other rich media with code and its output. In other words, it's a single page in which we can execute

code, view the results, and add explanations, formulae, and charts to make your work more clear,

intelligible, repeatable, and shared.

Notebooks are becoming an important element of the data science process at firms all around the

world. If we want to work with data, having a Notebook can help us get there faster and make it

easier to discuss and share your findings.

The python libraries and packages we’ll use in this project are namely:

• NumPy

• Pandas

9
• Pillow

• Matplotlib

• OpenCV

• Scikit-learn

• Tensorflow

1.2 Computer Vision

Computer vision is the process of understanding how pictures and videos are stored and how we

may change and retrieve data from them. Computer Vision is the foundation or primary application

of Artificial Intelligence. Computer vision is becoming increasingly important in self-driving cars,

robots, and picture-editing apps.

The Python Imaging Library extends your Python interpreter's image processing capabilities.

This library supports a wide range of file formats, has an efficient internal representation, and has

rather robust image processing features.

The core image library was created to provide quick access to data contained in a few fundamental

pixel formats. It should be a good starting point for a broad image processing programme.

1.2.1 Open CV

10
OpenCV is a large open-source library for computer vision, machine learning, and image processing,

and it currently plays a significant part in real-time operation, which is critical in today's systems. It

can analyse photos and movies to recognise items, people, and even human handwriting. Python can

process the OpenCV array structure for analysis when combined with other libraries such as NumPy.

We employ vector space and execute mathematical operations on these characteristics to identify

visual patterns and their different features.

Many bits of information that are contained in the original image may be acquired from the

aforementioned original image. For example, in the following image, there are two faces visible, and

the person (I) in the image is wearing a bracelet, watch, and so on, so we can extract all of this

information from the original image using OpenCV.

It's a basic introduction to OpenCV; we'll go through applications and other topics in future

posts.OpenCV applications include: Many applications are solved with OpenCV, some of which are

given here.

OpenCV Applications: OpenCV is used to tackle a variety of problems, some of which are described

below.

• Automated inspection and surveillance


11
• number of people – count (foot traffic in a mall, etc)

• Vehicle counting on highways along with their speeds

• Interactive art installations

• Anomaly (defect) detection in the manufacturing process (the odd defective products)

• Street view image stitching

• Video/image search and retrieval

• Robot and driver-less car navigation and control

• object recognition

• Medical image analysis

• Movies – 3D structure from motion

• TV Channels advertisement recognition

• Face recognition

1.2.3 Pillow

The Python Imaging Library (PIL expansion) is the de facto image processing package for the

Python programming language. It includes lightweight image processing tools that help with picture

editing, creation, and storing. Python Imaging Library support was dropped in 2011, however a

project called pillow cloned the original PIL project and provided Python3.x support. Pillow was

announced as a potential successor for PIL. 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.

1.3 Pixels

12
Pixels are the 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

colours Red, Blue and Green (RGB). If all the three values are 255 (infinity) that means it is a white

color and if all of them are 0 it shows black color. As each digit is an 8-bit digit the values range

from 0-255.

1.4 Image

An image is a numeric representation of images. A digital image is a 2D representation of an object

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). [3] Raster images

contain pixel values arranged in a matrix fashion whereas vector images are characterized

geometric objects using continuous coordinates. The image quality of these types of images is good

13
compared to raster images. Examples of vector images are SVG, PDF, and EPS and examples of

raster images are JPG, PN, BMP, and GIF.

In our research, we mainly focus on raster images and work on them to find the differences and

analyze the results.

1.5 RGB Values

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

display, it forms a colour image on the screen.

Because of the accuracy with which a real-life image can be duplicated, an RGB image is also

referred to as a genuine colour image.

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.

For example, RGB (255, 0, 0) is rendered as red because red is set to its greatest value 255, while

the other two (green and blue) are set to 0.

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).

14
2 Types of Image Formats

There are different image file formats and each has its own advantages and disadvantages. In this

section, we will study about each image format in detail. We have considered JPEG/JPG, PNG,

BMP, and GIF image formats for our analysis.

2.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.

JPG is similar to JPEG with an extension of .jpg.

The Joint Photographic Experts Group standardized the JPEG picture file format, giving rise to the

acronym JPEG. The format has been 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. JPEG pictures may be seen in web

browsers as well. Before delving into the JPEG file format standards, it is necessary to discuss the

general sequence of processes involved in JPEG generation.

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

lose a lot of data and thus be significantly compressed).

15
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

columns are duplicated.

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

some loss in image quality, but it is usually little.

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

tables specified by the JPEG standard.

Encoding: Each data unit's 64 quantized transformed coefficients (now integers) are encoded using

a mix of RLE and Huffman coding.

Adding Header: The last step adds a header and all of the JPEG parameters that were used, and

then outputs the result.

The JPEG decoder reverses the processes to create the original picture from the compressed one.

16
2.2 PNG

PNG 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. Image data is usually uncompressed or compressed with a lossless compression

algorithm. It also contains an Alpha channel like a PNG file. It uses more space. When BMP format

is compared with JPG in OpenCV we get the output image which is completely black (as in the

case of JPE vs JPG comparison), which means the images are similar, it is because of the pixel-

wise comparison of the images. Files with the extension Bitmap Image Files (BMP) are used to

store bitmap digital images. These pictures are device independent bitmap (DIB) file formats that

are independent of the graphics adapter. This independence allows the file to be opened on different

systems, including Microsoft Windows and Mac. The BMP file format is capable of storing data as

17
two-dimensional digital pictures in both monochrome and colour formats with varying colour

depths.

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

file format is covered by the Windows Metafile (WMF) standard.

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. Hence the comparison of a JPG or PNG

file format with a GIF file is unveiled. 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 the start of a

standard GIF file, depending on the version.

18
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-

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 dependant 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 standardised 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

colour pictures and LZW compression. Following that, TIFF file format revision 6.0 was released

in 1992.

2.6 GrayScale

Grayscale pictures are a subset of bilevel images. Bilevel pictures can only contain black-and-white

19
image data, but grayscale images can hold shades of grey. You must add or update the following

fields to characterize such photos. The remaining essential fields are the same as for bilevel

pictures. Compression # 1 or 32773 for grayscale images (PackBits). Grayscale photos in Baseline

TIFF can be saved as uncompressed data or compressed using the PackBits technique.

For grayscale photos, the BitsPerSample information is as follows:

Type = SHORT Tag = 258 (102.H)

The number of bits assigned to each component.

Baseline TIFF grayscale pictures can have values between 4 and 8, allowing for either 16 or 256

different shades of grey

20
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

the type of picture.

3.2 Comparison of two different images

Comparing two completely different images( a rose with a sunflower) using Open CV and Pillow:

21
Graphical image output using OpenCV library

Graphical image output using Pillow library

22
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

differences in the images

3.2.1 Comparison of two same images of different resolution

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 dim graphical image.

Resolution is crucial in image processing to analyze and study differences between two images. It

also helps us a lot in object detection.

23
3.2.2 Comparison of two same images of different Size

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. Therefore, we also compared the images using

the Pillow library, and surprisingly we found the graphical image difference of the two images in

not completely black. The output image is as follows:

3.2.3 Comparison of two same images of different formats

There are different image file formats and each has its own advantages and disadvantages. In this

section, we will study the differences in the image formats and analyze them. We have considered

JPEG/JPG, PNG, BMP, and GIF image formats for our analysis.

24
3.2.3.1 JPG with JPG

Comparing JPG images of the same image with JPG file type doesn’t show any difference as both

of the images have the same pixel values, same size, and same resolution.

The result is a complete black image.

3.2.3.2 PNG with JPG

But 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 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.

25
The graphical image difference of both JPG and PNG is shown below

Whereas the graphical representation of the difference of two images after converting them to rgb

images is as shown

26
3.2.3.3 BMP with JPG

When BMP format is compared with JPG in OpenCV we get the output image which is completely

black (as in the case of JPE vs JPG comparison), which means the images are similar, it is because

of the pixel-wise comparison of the images. But when the same task is performed using the pillow

library, the pixel-wise comparison of two images gave false as the output. Then when we compared

the two images using pillow library we didn’t get a completely black image. We observed some

light blue sparks on the graphical image output.

27
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.

3.2.3.4 GIF with JPG

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. 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

28
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 difference in a color map fashion. The difference

can be seen below.

In the same way when a GIF image is compared with a PNG file, the graphical image output is as

shown below

29
3.2.3.5 TIFF with BMP

A TIFF image format is converted into BMP format and then compared with the original TIFF

image and analyzed the results

The graphical image output is shown below 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 pencil and highlight it dark at some places and light at other places.

30
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.

RGB-wise comparison of the images doesn’t conclude the images to be the same or different, from

the above research it is clear that though the pixel values are different images are not the same.

31
3.2.3.5 Grayscale with Grayscale

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

output and if not we get a false value as output.

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.

32
4 Inserting and retrieving images from DB

Till 3rd chapter we have worked on python libraries and frameworks using the python programming

language, now we will use java programming to insert the images and retrieve them to compare

bulk images using RGB or binary comparison method

4.1 Eclipse IDE


The Eclipse IDE is best known for its Java Integrated Development Environment (IDE).

Multiple language support and other features may be readily combined into any of the preset

packages, and the Eclipse Marketplace allows for nearly limitless customization and expansion. We

can install the software online for free.

Above is the workplace of eclipse IDE to run any java programs so we will use this IDE to connect

with the database in the next section.

4.2 PostgreSQL

33
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

update the data tables.

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 retriving 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. 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.

34
In the same way the Binary data is compared and the result of the image class is mapped with the id

of the image data.

35
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.

Code to open any image using OpenCV:

Here we have taken a sunflower image as input.

36
Something is odd with the figure above. It does not resemble the original. Before we start, let's look

at 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 second as green, and

the third as blue.

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,

how do we remedy this? We transform the picture from BGR to RGB after opening it. We do this

by use the OpenCV setting COLOR BGR2RGB. The code below demonstrates how to properly

open an image with OpenCV. Now that we know how colour channels function in an image, let's

37
investigate why we observed a different colour image above. When we open an image using

OpenCV, it opens the picture in the Blue, Green, and Red channels by default (BGR).

Now, let's open a picture in Tensorflow and check 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 JPEG

decoding because JPEG is a compressed image.

Code to open an image using Tensors:

38
Visually, the images read by OpenCV and Tensorflow appear to be the same. But do they? Let's

subtract the two to discover what the differences are. If the two are identical, the picture should be

totally black. If not, we'll see some pixels with varying colours.

There is a significant 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. Because this method of decoding is wrong, we must

decode it using integer accurate decompression to match OpenCV. Setting the option dct

method='INTEGER ACCURATE' as shown below will do this.

39
And now, when we compare 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 you read the image might result in major differences in how

the image is processed later.

Let's compare the differences in the scaled photos from OpenCV and TF and see the result.

And now we have the anticipated outcome. Finally, Tensorflow and OpenCV are continuously

reading and resizing pictures.

40
A newcomer to the Computer Vision sector who tries out these functionalities is more likely to

make these errors and get off to a terrible start. This is not covered in depth in tutorials available on

the internet. I started this blog to show people that when moving from one framework to another,

minute details like what I described must be reviewed and maintained. Otherwise, they will produce

different outcomes in different frameworks, which would have a negative impact on their job.

Pillow is another popular framework (PIL). Let's look at the differences between PIL and OpenCV.

We'll start by reading the picture with PIL.

Opening an Image using Pillow:

Let us compare the results of Tensorflow with the Pillow image just like we did it using OpenCV

and see the output.

41
This indicates that unlike OpenCV, Pillow and Tensorflow read the image properly.

Now we'll test whether there's any difference between the JPEG picture opened by PIL and the one

opened by OpenCV.

The resizing mechanism of the two frameworks differs significantly once again. Even when we

opened the photos 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 the resizing method output differences.To address

this issue, there is a parameter in the TensorFlow bilinear resize that does half-pixel correction is

shown below:

42
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.

43
As a result, while utilising 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

will have unanticipated consequences.

44
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

Fredrik Lundh and Contributors.

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.

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.

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

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

45
images to get a completely black image. Pillow is better to use than OpenCV while working fewer

with image formats and OpenCV requires to be modified to work better for image processing as

OpenCV works better when speed is the critera. This report also concludes the best format for

performing Image processing tasks from our analysis is Bitmap image format due to its ability to

store the image data in smaller bits which gives a better processing experience than any other image

formats.

46
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,

rof. Shilpa Hiremath1, et al., 2020

3. Image file formats, Lk Tan, et al., 2006

47
Appendices

Steps involved in JPEG compression……………………………………………………….15

Transformation

Down Sampling

Organizing in groups

Discreate Cosine Transform

Quantization

Encoding

Adding Header

48
Glossary
1 JPEG -Joint Photographic Experts Group…………………………………………………………………………………………………15

2 PNG – Portable Network Graphics…………………………………………………………………………………………………………..17

3 BMP – Bitmap Image File…………………………………………………………………………………………………………………………17

4 GIF – Graphic Interchange Format………………………………………………………………………………………………………….18

5 TIFF – Tag Image File Format………………………………………………………………………………………………………………….19

49

You might also like