Dip Lab 3
Dip Lab 3
NAME::Irfa n Haider
CLASS: BCE-7
ENROLLMENT NO: 01-132182-035
DEPARTMENT OF COMPUTER ENGINEERING
BAHRIA UNIVERSITY | ISLAMABAD CAMPUS
Title
Objective
The aim of this introductory lab is to introduce you to the basic functions in the Python. By the
end of today’s lab, you should be able to read images from the disk display them, write them back to the
disk and perform conversions between different image classes
Tools/ Software
Reading an Image
1. Reading, and displaying an image using PIL The PIL function, open(), reads an image from disk in an
Image object, as shown in the following code. The image is loaded as an object of the
PIL.PngImagePlugin.PngImageFile class, and we can use properties such as the width, height, and mode
to find the size (width x height in pixels or the resolution of the image) and mode of the image:
The next code block shows how to use the imread() function from matplotlib.image to read an image in
a floating-point numpy ndarray. The pixel values are represented as real values between 0 and 1:
3. Reading, saving, and displaying an image using scikit-image
The next code block uses the imread() function from scikit-image to read an image in a numpy ndarray
of type uint8 (8-bit unsigned integer). Hence, the pixel values will be in between 0 and 255. Then it
converts (changes the image type or mode, which will be discussed shortly) the colored RGB image into
an HSV image using the hsv2rgb() function from the Image.color module. Next, it changes the saturation
(colorfulness) to a constant value for all of the pixels by keeping the hue and value channels unchanged.
The image is then converted back into RGB mode with the rgb2hsv() function to create a new image,
which is then saved and displayed
Task 1
Load the image ‘camera.png’, find its dimensions and number of channels and display it
Task 2
Write a Python program which reads the image ‘chelsea.png’ available in the skimage distribution. Find
the size of the image and the number of channels in it. If it is a three channel image first convert it to
grayscale and display it.
Task 3
Load the image ‘parrot.png’, binarize it with a threshold of 127. Display both original and binarized
images using matplotlib and save binarized image to disk. (Open cv Functions)
Conclusion
In this lab I have learnt how to import image in python and change the original image to Binary Image.
I have also Load the image ‘camera.png and I have find its dimensions and number of channels and and I
have display it