In [2]:
import cv2
import os
import matplotlib.pyplot as plt
%matplotlib inline
IMG = 'imgs/'
In [26]:
def show_img(img):
"""
Function takes an image, and shows the image using pyplot.
The image is shown in RGB
"""
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img)
In [4]:
img_path = os.path.join(IMG, 'sea.jpeg')
img = cv2.imread(img_path)
# What is the size of the Image?
print img.shape
# What is the class of the image?
print img.dtype
show_img(img)
In [5]:
img[50,100]
Out[5]:
In [6]:
plt.plot(img[1500,:,2])
Out[6]:
TODO: Extract a 2D slice between rows 101 to 103 and columns 201 to 203 (inclusive)
In [7]:
extraction = img[101:103,201:203]
In [8]:
cropped = img[1700:,300:,:]
In [9]:
show_img(cropped)
In [55]:
# Size of Cropped Image
cropped.shape
Out[55]:
In [36]:
img_green = img[:,:,1]
Out[36]:
In [40]:
plt.imshow(img_green, cmap='gray')
Out[40]:
In [48]:
# Load the Dog Image
dog_path = os.path.join(IMG, 'dog.jpeg')
dog = cv2.imread(dog_path)
#dog = cv2.resize
dog = cv2.resize(dog, (img.shape[1], img.shape[0]))
show_img(dog)
In [49]:
summed = dog + img
In [ ]: