Working with Image basically based on python. It uses python libraries.With the help of this Software we can easily edit our image in just two minutes without using any extra software. It is very easy to use and also user friendly interface made him very effective for editing.
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
Working With Image
1. PROJECT REPORT
OF
WORKING WITH IMAGE
A major project report submitted in the partial fulfillment
Of the requirement for the award of degree of
Bachelor of Technology (Computer Science & Engineering)
(Session: 2016-2020)
Submitted to:
Dr. Naresh Kumar
Assistant Professor
CSE Department
UIET, KUK
Submitted by:
Vicky Kumar
251602176
CSE-8th
B
Btech
University Institute of Engineering and Technology
Kurukshetra University, Kurukshetra – 136119
2. INDEX
SERIAL
NO.
CONTENTS PAGE
NO.
1. Declaration 3
2. Certificate 4
3. Acknowledgement 5
4. Abstract 6
5. Introduction 7-8
6. Technology Used 9-10
7. Hardware and Software
Requirements
11
8. Experiments and Results 12-23
9. Conclusion 24
10. Future Scope 25
11. References 26
3. 1. DECLARATION
I hereby declare that the work, which is being presented in the project report
entitled “WORKING WITH IMAGE” submitted as a part of course
curriculum for BACHELOR OF TECHNOLOGY in COMPUTER
SCIENCE & ENGINEERING is an authentic record of my own work carried
out under the guidance of Dr. Naresh Kumar, Assistant Professor, CSE –
Department, UIET( KUK).
The information and data given in the report is authentic to best of my knowledge.
The matter embodied in the report has not been submitted for the award of any
other degree.
Vicky Kumar
(Rollno: 251602176)
4. 2. CERTIFICATE
This is to certify that the report entitled “WORKING WITH IMAGE” submitted
by VICKY KUMAR, Roll No. 251602176 to the Department of CSE of
University Institute of Engineering and Technology, Kurukshetra University,
Kurukshetra for the award of the Degree of Bachelor of Technology in CSE, is a
bonfire project work carried out by her under my supervision and guidance. Her
report has reached the standard of fulfilling the requirements of regulations
relating to degree.
I wish her success in all her future endeavors.
Dr. NARESH KUMAR
Assistant Professor
CSE Dept.
UIET, KUK
5. 3. ACKNOWLEDGEMENT
At the very outset, I am highly indebted to The UIET for giving me an opportunity
to carry out my project on “WORKING WITH IMAGE”. In the course of
present work it has been my privilege to receive help and assistance from many
quarters. I take great pleasure in acknowledging here, my debt to them.
I am deeply indebted to my project supervisor, Dr. Naresh Kumar, Asstt. Prof.,
UIET KUK whose inspiration and invaluable guidance has been unfailingly
available to me at all stages of my practical. It proved an opportunity for me to
upgrade my skills and added to my professional knowledge, in an environment
that was intellectually stimulating one, moreover that maintained the highest
standard of academic excellence.
At more personal level I am thankful to my friends who knowingly or
unknowingly helped in my project in many ways.
I also want to thank my ‘parents’ for their entire support and morale boost in the
development phase of this project.
Vicky Kumar
(Rollno: 251602176)
6. 4. ABSTRACT
“Image processing” is normally used by a wide range of applications and in
different types of electronics like computers, digital cameras, mobile phones etc.
The image properties can be changed with the least investment such as contrast
enhancement, borders detection, intensity measurement & apply different
mathematical functions to enhance the imagery. Even though these methods can
be very influential, the consumer frequently controls images with dump, but
understanding the fundamental values behind the effortless image processing
routine is rare. Though this may be suitable for some persons, it frequently leads
to a picture that is extensively corrupted.“Image processing” is normally used by
a wide range of applications and in different types of electronics like computers,
digital cameras, mobile phones etc. The image properties can be changed with
the least investment such as contrast enhancement, borders detection, intensity
measurement & apply different mathematical functions to enhance the imagery.
Even though these methods can be very influential, the consumer frequently
controls images with dump, but understanding the fundamental values behind
the effortless image processing routine is rare. Though this may be suitable for
some persons, it frequently leads to a picture that is extensively corrupted.
Vicky Kumar
(Rollno: 251602176)
7. 5. INTRODUCTION
In “Working with image” project we have used PIL library of python.PIL is the
Python Imaging Library which provides the python interpreter with image
editing capabilities.The method of image processing is used to do some processes
on a picture like an image enhancement or to remove some functional data from
the image. Image processing is one kind of signal processing, where the input is
a picture, as well as the output, are features or characteristics allied with the
image.
Image processing:
We’ll be working with the Image Module here which provides a class of the same
name and provides a lot of functions to work on our images.One of the most
popular and considered as default library of python for image processing is Pillow.
Pillow is an updated version of the Python Image Library or PIL and supports a
range of simple and advanced image manipulation functionality. It is also the
basis for simple image support in other Python libraries such as sciPy and
Matplotlib.
Normally, we used to work with an image of constant size. But in some
occassions, we need to work with images of different resolution of the same
image. For example, while searching for something in an image, like face, we are
not sure at what size the object will be present in the image. In that case, we will
need to create a set of images with different resolution and search for object in all
the images. These set of images with different resolution are called Image
Pyramids (because when they are kept in a stack with biggest image at bottom and
smallest image at top look like a pyramid).
There are two kinds of Image Pyramids. 1) Gaussian Pyramid and 2) Laplacian
Pyramids
Higher level (Low resolution) in a Gaussian Pyramid is formed by removing
8. consecutive rows and columns in Lower level (higher resolution) image. Then
each pixel in higher level is formed by the contribution from 5 pixels in
underlying level with gaussian weights. By doing so, a image
becomes image. So area reduces to one-fourth of original area. It is
called an Octave. The same pattern continues as we go upper in pyramid (ie,
resolution decreases). Similarly while expanding, area becomes 4 times in each
level. We’ll be working with the Image Module here which provides a class of the
same name and provides a lot of functions to work on our images.
Today's world is full of data, and images form a significant part of this data.
However, before they can be used, these digital images must be processed—
analyzed and manipulated in order to improve their quality or extract some
information that can be put to use.
Common image processing tasks include displays; basic manipulations like
cropping, flipping, rotating, etc.; image segmentation, classification, and feature
extractions; image restoration; and image recognition. Python is an excellent
choice for these types of image processing tasks due to its growing popularity as a
scientific programming language and the free availability of many state-of-the-art
image processing tools in its ecosystem.
9. Python:
6. TECHNOLOGY USED
Python is an interpreter, high-level, general-purpose programming language.
Created by Guido van Rossum and first released in 1991, Python's design
philosophy emphasizes code readability with its notable use of significant
whitespace. Its language constructs and object-oriented approach aim to help
programmers write clear, logical code for small and large-scale projects.
Python is dynamically typed and garbage-collected. It supports multiple
programming paradigms, including procedural, object-oriented, and functional
programming. Python is often described as a "batteries included" language due to
its comprehensive standard library.
Jupyter Notebook:
The Jupyter Notebook is an open-source web application that allows you to create
and share documents that contain live code, equations, visualizations and
narrative text. Uses include: data cleaning and transformation, numerical
simulation, statistical modeling, data visualization, machine learning, and much
more.
COMPARISON WITH OTHER TECHNOLOGIES :
For this project, we have used machine learning using python to build our model.
As AI and ML are being applied across various channels and industries, big
corporations invest in these fields, and the demand for experts in ML and AI
grows accordingly. Jean Francois Puget, from IBM’s machine learning
department, expressed his opinion that Python is the most popular language for
AI and ML and based it on a trend search results on indeed.com.
A great library ecosystem :
A library is a module or a group of modules published by different sources like
PyPi which include a pre-written piece of code that allows users to reach some
functionality or perform different actions. Python libraries provide base level
10. items so developers don’t have to code them from the very beginning every time.
ML requires continuous data processing, and Python’s libraries let you access,
handle and transform data. These are some of the most widespread libraries you
can use for ML and AI: NumPy, Pandas, Matplotlib, Seaborn, Scikitlearn
Easy to learn:
The simplicity of the language allows more data scientists to quickly pick up
Python and start using it for AI development without wasting too much effort into
learning the language.
Flexibility:
Python for machine learning is a great choice, as this language is very flexible: It
offers an option to choose either to use OOPs or scripting. There’s also no need
to recompile the source code, developers can implement any changes and quickly
see the results. Programmers can combine Python and other languages to reach
their goals.
Platform independence:
Platform independence refers to a programming language or framework allowing
developers to implement things on one machine and use them on another machine
without any (or with only minimal) changes. One key to Python’s popularity is
that it’s a platform independent language. Python is supported by many platforms
including Linux, Windows, and macOS. Python code can be used to create
standalone executable programs for most common operating systems, which
means that Python software can be easily distributed and used on those operating
systems without a Python interpreter.
What’s more, developers usually use services such as Google or Amazon for their
computing needs. However, you can often find companies and data scientists who
use their own machines with powerful Graphics Processing Units (GPUs) to train
their ML models. And the fact that Python is platform independent makes this
training a lot cheaper and easier.
11. 7. HARDWARE AND SOFTWARE AND TOOLS
REQUREMENTS
1) Programming Language:
Python is an interpreter, high-level, general-purpose programming language. It
supports modules and packages, which encourages program modularity and code
reuse.
2) Tools :
Jupyter Notebook
The Jupyter Notebook is an open-source web application that allows you to create
and share documents that contain live code, equations, visualizations and
narrative text. Uses include: data cleaning and transformation, numerical
simulation, statistical modeling, data visualization, machine learning, and much
more.
3) Python libraries:
There is extensive use of python libraries such as:
Pandas: Used for data manipulation and analysis.
Scikit-learn: Used for data preprocessing and accessing various machine
learning algorithms.
Matplotlib: Used for data visualisation purpose.
Numpy
Pil : PIL is the Python Imaging Library which provides the python
interpreter with image editing capabilities.
4) Minimum Hardware Requirements:
Processor: Pentium 4
RAM: 1GB
Hard disk: 50GB
Display: SVGA(800X600)
5) Minimum System Software Requriments:
Operating System: Windows 98/2000/XP/7/8/10, Unix, Linix
Front End: Jupyter notebook
12. Install Pillow:
8.Experiments and Results
The easiest way to install it is to use pip:
Pip install pillow
1) Load and Display image:
First we need a test image to demonstrate some important features of using the
python Pillow library.
I’ve used the opera house photo as a sample image. Download the image and save
it in your current working directory
#Load and show an image with Pillowfrom PIL import Image
#Load the image
img = Image.open('statue_of_unity.jpg')
#Get basic details about the imageprint(img.format)print(img.mode)print(img.size)
#show the image
img.show()
RESULTS:
JPG
RGB
(1920, 1200)
13. 2) Convert an image to grayscale:
To convert an image to grayscale, display it and then save it is very easy, just do
the following:
#Import required libraryfrom PIL import Image#Read an image & convert it to
gray-scale
image = Image.open('Opera House.jpg').convert('L')#Display image
image.show()#Save image
image.save('opera houseg.jpg')
RESULTS:
14. 3) Resize an image:
The size(dimensions) of our current image file is 1920 * 1200px. Incase we want
to resize it, and make it of size 2130 * 1300px, can be done by:
image = Image.open('opera house.jpg')
newImage = image.resize((440, 600))
newImage.save('opera house 2130&1300.jpg')
Results:
15. 4) Rotate an image:
Below program loads an image, rotates it 45 degrees and display it using an
external viewer.
Code:
from PIL import Image
image = Image.open('opera house.jpg')
image.rotate(45).show()
Results:
16. 5) Cropping an image:
Image.crop(box) takes a 4-tuple (left, upper, right, lower) pixel coordinate, and
returns a rectangular region from the used image.
Code:
from PIL import Image
def main():
try:
#Relative Path
img = Image.open("Opera House.jpg")
width, height = img.size
area = (0, 0, width/2, height/2)
img = img.crop(area)
#Saved in the same relative location
img.save("cropped_picture.jpg")
except IOError:
pass
if __name__ == "__main__":
main()
Results:
Cropped image
17. 6) Pasting an image on another image:
The second argument can be a 2-tuple (specifying the top left corner), or a 4-
tuple (left, upper, right, lower) – in this case the size of pasted image must match
the size of this box region, or None which is equivalent to (0, 0).
Code:
from PIL import Image
def main():
try:
#Relative Path
#Image on which we want to paste
img = Image.open("opera house.jpg")
#Relative Path
#Image which we want to paste
img2 = Image.open("tajmahal.jpg")
img.paste(img2, (50, 50))
#Saved in the same relative location
img.save("pasted_picture.jpg")
except IOError:
pass
if __name__ == "__main__":
main()
Results:
18. 7) Getting a Histogram of an Image:
This will return a histogram of the image as a list of pixel counts, one for each
pixel in the image. (A histogram of an image is a graphical representation of the
tonal distribution in a digital image. It contains what all the brightness values
contained in an image are. It plots the number of pixels for each brightness value.
It helps in doing the exposure settings.
Code:-
from PIL import Image
def main():
try:
# Relative Path
img = Image.open("Opera House.jpg")
# Getting histogram of image
print(img.histogram())
except IOError:
pass
if __name__ == "__main__":
main()
Results:
[72051, 53556, 55639, 44840, 34715, 33432, 25849, 27882, 26880, 22810, 22210,
22112, 21343, 20229, 18042, 16571, 15864, 14829, 14279, 14172, 14106, 14411,
14974, 15635, 16656, 17688, 20078, 19637, 23502, 19732, 23035, 24212, 24146,
22869, 21934, 23327, 22768, 20936, 19229, 16532, 15780, 17285, 13545, 12895,
11444, 10119, 9572, 8962, 8684, 8648, 8773, 8892, 8713, 8713, 8643, 8389, 8429,
8040, 7978, 7715, 7585, 7391, 7286, 7180, 6892, 6741, 6372, 6114, 6051, 5937,
5698, 5772, 5217, 5098, 4904, 4773, 4820, 4734, 4633, 4615, 4450, 4430, 4252,
4183, 4094, 3891, 3896, 3861, 3738, 3732, 3768, 3525, 3473, 3415, 3347, 3336,
3232, 3216, 3118, 3014, 2933, 2973, 2983, 2911, 2722, 2835, 2739, 2619, 2594,
2632, 2574, 2581, 2454, 2399, 2383, 2303, 2304, 2257, 2106, 2219, 2193, 2114,
2173, 2014, 2034, 2003, 1922, 1956, 1943, 1946, 1903, 1948, 1822, 1792, 1775,
1787, 1683, 1741, 1682, 1740, 1652, 1633, 1580, 1600, 1553, 1586, 1552, 1544,
1523, 1525, 1522, 1542, 1532, 1436, 1454, 1533, 1474, 1497, 1486, 1496, 1453,
1459, 1427, 1472, 1449, 1394, 1470, 1362, 1416, 1389, 1313, 1355, 1391, 1337,
1315, 1296, 1302, 1309, 1325, 1182, 1254, 1264, 1235, 1245, 1253, 1275, 1337, ]
19. 8) Transposing an Image: This feature gives us the mirror image of an image.
Code:
from PIL import Image
def main():
try:
# Relative Path
img = Image.open("Opera House.jpg")
# transposing image
transposed_img = img.transpose(Image.FLIP_LEFT_RIGHT)
# Save transposed image
transposed_img.save("transposed.jpg")
except IOError:
pass
if __name__ == "__main__":
main()
Results:
20. 9) Split an image into individual bands: Splitting an image in RGB mode,
creates three new images each containing a copy of the original individual bands.
Code:
from PIL import Image
def main():
try:
# Relative Path
img = Image.open("Opera House.jpg")
# splitting the image
print(img.split())
except IOError:
pass
if __name__ == "__main__":
main()
Results:
(<PIL.Image.Image image mode=L size=1600x1000 at 0x3132BD0>,
<PIL.Image.Image image mode=L size=1600x1000 at 0x3132BF0>,
<PIL.Image.Image image mode=L size=1600x1000 at 0x3132C10>)
21. 10) Transform an Image to a bitmap:
The program takes an rgb image and converts it in a numpy array. It then splits it
in 3 vectors, one for each channel. I uses the color vectors to create a gray vector.
After that it comperes elements with 128, if lower than writes 0(black) else is 255.
Next step is reshape and save.
Code:
from PIL import Image
import numpy as np
img = Image.open('Opera House.jpg')
ary = np.array(img)
# Split the three channels
r,g,b = np.split(ary,3,axis=2)
r=r.reshape(-1)
g=r.reshape(-1)
b=r.reshape(-1)
# Standard RGB to grayscale
bitmap = list(map(lambda x: 0.299*x[0]+0.587*x[1]+0.114*x[2],
zip(r,g,b)))
bitmap = np.array(bitmap).reshape([ary.shape[0], ary.shape[1]])
bitmap = np.dot((bitmap > 128).astype(float),255)
im = Image.fromarray(bitmap.astype(np.uint8))
im.save('road.bmp')
Results:
22. 11) Creating a thumbnail: This method creates a thumbnail of the image that is
opened. It does not return a new image object, it makes in-place modification to
the currently opened image object itself. If you do not want to change the original
image object, create a copy and then apply this method. This method also
evaluates the appropriate to maintain the aspect ratio of the image according to the
size passed.
Code:
from PIL import Image
def main():
try:
# Relative Path
img = Image.open("Opera House.jpg")
# In-place modification
img.thumbnail((200, 200))
img.save("thumb1.jpg")
except IOError:
pass
if __name__ == "__main__":
main()
Results:
23. 12) Enhancing an image in Pillow using ImageFilter:
Code:
from PIL import Image, ImageFilter
# Read image
im = Image.open('Opera House.jpg')
# Display image
im.show()
from PIL import ImageEnhance
enh = ImageEnhance.Contrast(im)
enh.enhance(2.8).show("30% more contrast")
Results:
Before:
After:
24. 8. CONCLUSION
Today's world is full of data, and images form a significant part of this data.
However, before they can be used, these digital images must be processed
analyzed and manipulated in order to improve their quality or extract some
information that can be put to use.
Common image processing tasks include displays; basic manipulations like
cropping, flipping, rotating, etc.; image segmentation, classification, and feature
extractions; image restoration; and image recognition. Python is an excellent
choice for these types of image processing tasks due to its growing popularity as a
scientific programming language and the free availability of many state-of-the-art
image processing tools in its ecosystem. We can use image processing technique
for vechical recognization,face detection etc
25. 9. FUTURE SCOPE
Since the accuracy provided by the Image processing system there are many ways
to improvement.
We can improve the image processing by using more advanced techniques and
more machine learning tools. We can take the image as target variable, train
the sub model to find the more accurate values missing in those places. But
this process is very expensive and time consuming. It requires more powerful
machines.
Similarly there are algorithms which can be used in powerful architectures
which provide a better score and give accurate Result.