Python Code
Python Code
Matplotlib
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
img.rotate(-90)
type(img)
img_array = np.asarray(img)
type(img_array)
numpy.ndarray
img_array.shape
plt.imshow(img_array)
img_test = img_array.copy()
plt.imshow(img_test[:,:,0}) //red
plt.imshow(img_test[:,:,0}, cmap='gray')
plt.imshow(img_test[:,:,1}) //green
plt.imshow(img_test[:,:,2}) // blue
img_test[:,:,0] = 0
plt.imshow(img_test)
import cv2
img = cv2.imread('images/rock.jpg')
type(img)
img.shape
plt.imshow(img)
img_fix = cv2.cvtcolor(img,cv2.COLOR_BGR2RGB)
plt.imshow(img_fix)
Resize Image
width_ratio = 0.5
height_ration = 0.5
img2 = cv2.resize(img_fix,(0,0),img_fix,width_ratio,height_ratio)
plt.imshow(img2)
img2.shape
img_3 = cv2.flip(img_fix,0)
plt.imshow(img_3)
last_img = plt.figure(figsize=(10,7))
ilp = last_img.add_subplot(111)
ilp.imshow(img_fix)
draw shapes
black_img = np.zeros(shape=(512,512,3),dtype=np.int16)
black_img.shape
plt.imshow(black_img
draw a circle
cv2.circle(img=black_img,center=(400,100),radius=50,color=(255,0,0),thickness=8)
plt.imshow(black_img)
cv2.circle(img=black_img,center=(400,200),radius=50,color=(0,255,0),thickness=-1)
plt.imshow(black_img)
cv2.rectangle(black_img,pt1=(200,200),pt2=(300,300),color(0,255,0),thickness=5)
plt.imshow(black_img)
vertices = np.array([[10,450,[110,350],[180,450]],np.int32)
pts = vertices.reshape(-1,1,2)
cv2.polylines(black_img,[pts],isClosed=True,color=(0,0,255),thickness=3)
plt.imshow(black_img)
cv2.rectangle(black_img,pt1=(200,50),pt2=(300,150),color(137,79,213),thickness=-1)
plt.imshow(black_img)
vertices = np.array([[10,250,[110,150],[180,250]],np.int32)
pts = vertices.reshape(-1,1,2)
cv2.fillpoly(black_img,[pts],color=(255,167,201))
plt.imshow(black_img)
cv2.line(black_img,pt1=(512,0),pt2=(0,512),color=(255,0,255),thickness=3)
plt.imshow(black_img)
font = cv2.font_hershey_simplex
cv2.putText(black_img,text='Rhyme',org(210,
500),fontFace=font,fontscale=3,color=(255,255,0),thickness=3,lineType=cv2.LINE_AA)
plt.imshow(black_img)