Image Cropping with Python: ITD104 Building IT Systems Assignment

Verified

Added on  2023/06/15

|6
|956
|294
Practical Assignment
AI Summary
This document provides a solution to an assignment focused on image cropping using Python and the PIL (Python Imaging Library). The assignment, likely part of a Building IT Systems course (ITD104), requires the implementation of image handling capabilities, specifically cropping an image to fit a specified view. The solution discusses the use of PIL methods for loading, manipulating, and saving images, including techniques for cropping, pasting, and merging image regions. It emphasizes the importance of coordinate specification in the cropping process and provides a basic code structure for achieving the desired image manipulation. The conclusion reiterates the usefulness of Python and PIL for image processing tasks.
Document Page
BUILDING IN IT SYSTEMS
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Table of Contents
1. Introduction.......................................................................................................................................1
2. Image class in python........................................................................................................................1
3. Implementation..................................................................................................................................2
4. Conclusion..........................................................................................................................................3
Document Page
1. Introduction
The python libraries are needed for implementing the code. This provides an extensive
format .PIL (Python Imaging Library) adds the image handling capabilities and abilities to
Python interpreter. The library offers wide-ranging of file formats and supports, a proficient
internal depiction, and powerful image handling capabilities. This objective is to crop image in
python code and is fix it in the correct view of the image provided.
2. Image class in python
Imaging library methods is an important concept in python. This methods is used for
loading or filling images from various files, creating pictures from scratch and handling other
images.
Loading image from a file
In python, open() function is used in the Image part module.
Syntax
Image Sequence
PIL (Python Imaging Library) covers the image sequences function in python. It is named as
animation designs formats. Image sequence design contains the FLC/ FLI, GIF as well as
experimental formats. The TIFF file holds more number of frame. User open the sequence series
file, Python Imaging Library (PIL) spontaneously loads an initial frame in the image sequence.
Cut, Paste and Merge the Pictures
Image class cover the procedures authorizing us to activate regions inside the image. In order to
remove or extract the particular part from an image, we have to use crop process and methods.
For instance: Copy the sub rectangle from an images (Python Multimedia, 2010).
Document Page
The area is defined via the four attributes in which the coordinates are
1. Upper
2. Left
3. Lower
4. Right
PIL (Python Image Library) used for the coordinate method through (0, 0) in a high left angle. In
additionally, the matches coordinates are discuss to places among the pixels. For instance
consider which correctly around the exact pixels. Region can be managed in convinced manner
and arranged back.
For Instance: Handling sub rectangle, attached it back.
When we pasting regions back, magnitude of region should equal the indicated region
accurately. It also, region can’t range outside images. (Somervill, 2010).
For extra advanced trickeries, the paste method or process could also takes a slide cover as a
possible argument. In mask, value of 255 specifies that past pictures is dense which location
(which is, pasted pictures need be used). Value of 0 resources that pasted pictures is totally clear.
The values specify the various stages of slide.
PIL (Python Image Library) permits the separate groups or bands of a numerous-band
image, likes a Red, Green, Blue (RGB) image. The split method or process makes an array of
different new pictures, every covering individual band from a unique numerous band image. This
merge method take a mode type as well as attributes of pictures and images. it also merged and
created the new image.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
3. Implementation
Image is selected randomly and it’s cropped with help of python code (Changingminds.org,
2017).
The very important thing for the python code is mainly to import all the Image which has sub-
module. It is needed to import all the packages for implementing the code. The function named
crop() is used. The function is accompanied with 3 different parameters. They are the following.
The image path is the file path for the specified file that the user can crop. The coordinates are
more important in this. As the user set the coordinates in the right way the picture comes as well.
The file path is most essential for the implementation to be done in python. This is the most
important element in which the cropped image will be spited and it will be saved to some other
location. The location can mentioned in the code as well (McNeil, 2010).
saved_location – The file path to save the cropped file to
After we open the initial image, we get an object back that we can call crop() on. The crop
method takes the coordinates we passed in and crops the image down appropriately and returns a
second image object. We then call this second image object’s save() method and tell it to save it
to the specified location.
4. Conclusion
The python libraries are used for implementing the code. This helps in providing an
extensive format .PIL (Python Imaging Library) is added in image handling competences to
Python interpreter. This image library provided a wide-ranging of file format maintenance and
support. The image is cropped in python code and is implemented.
Document Page
References
Changingminds.org. (2017). Schema. [online] Available at:
http://changingminds.org/explanations/theories/schema.htm [Accessed 28 Nov. 2017].
McNeil, J. (2010). Python text processing beginner's guide. Birmingham, U.K.: Packt Pub.
Python Multimedia. (2010). Packt Pub.
Somervill, B. (2010). Python. Ann Arbor, Mich.: Cherry Lake Pub.
chevron_up_icon
1 out of 6
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]