In [12]:
import cv2
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams["figure.figsize"] = (8,6)
In [16]:
np_bgr_image = cv2.imread('./lena2.png', 1)
np_rgb_image = cv2.cvtColor(np_bgr_image, cv2.COLOR_BGR2RGB)
plt.imshow(np_rgb_image)
plt.show()
In [18]:
np_bgr_image.shape
Out[18]:
In [19]:
np_bgr_image.dtype
Out[19]:
In [24]:
height, width = np_rgb_image.shape[:2]
resized_image = cv2.resize(np_rgb_image, (int(width/2), int(height/2)))
In [25]:
print ('resized image shape:', resized_image.shape)
plt.imshow(resized_image)
plt.show()
In [28]:
M = np.float32([[1,0,20],[0,1,40]])
translated_image = cv2.warpAffine(np_rgb_image, M,(width, height))
print ('translated image shape:', translated_image.shape)
plt.imshow(translated_image)
plt.show()
In [29]:
M= cv2.getRotationMatrix2D((width/2, height/2), 45, 1)
rotated_image = cv2.warpAffine(np_rgb_image, M, (width, height))
print ('rotated image shape:',rotated_image.shape)
plt.imshow(rotated_image)
plt.show()
In [30]:
np_gray_image = cv2.cvtColor(np_bgr_image, cv2.COLOR_BGR2GRAY)
laplacian = cv2.Laplacian(np_gray_image, cv2.CV_8U)
print ('gradient image shape:',laplacian.shape)
plt.imshow(laplacian, cmap='gray')
plt.show()
In [ ]: