Image_Handling_Session -1_PDF
Image_Handling_Session -1_PDF
This Session:
• Image Handling
DATA PRESENTATION
Audio File
Numerical File
Text File
Image File
DATA PRESENTATION
array2d.shape
Binary Images
• A 2D array of pixels that can have one of two colors, black and white.
• Each pixel is stored as a single bit — i.e. either 0 or 1 where ‘0’ represents black and ‘1’
represents white.
• Example: For above black and white image, have a shape of (8, 8).
Activity 2: Create 2D numpy array
arr2d.shape
Activity 3: Create 3D numpy array
arr2d.shape
Grayscale Image
plt.imshow(arr2d)
plt.show()
arr2d.shape
RGB Image
arr3d_copy1 = arr3d.copy()
arr3d_copy1[:, :, 1] = 0 # Green
Channel
arr3d_copy1[:, :, 2] = 0 # Blue
Channel
plt.figure(figsize = (3,3))
plt.imshow(arr3d_copy1)
plt.show()
Image Handling
Functions
• imread(): read or load an image from a file into a program
Syntax:
Syntax:
Loading Image from a file
- Use imread() function to image from a file
import numpy as np
import matplotlib.pylab as plt
%matplotlib inline
my_image =
plt.imread(r"/shareddata/datasets/ngitcourse4/swathi/panda.jpeg")
print(my_image)
plt.imshow(my_image)
plt.show()
Image Manipulations