Challenge

Project 1

import cv2
import numpy as np

image_path = 'Challenge1_1638957930.png'
image = cv2.imread(image_path) # reads image in BGR format

image.shape #output: (610, 996, 3)

# get rotation matrix
rotation_matrix = cv2.getRotationMatrix2D(center = (image.shape[1]/2,image.shape[0]/2),angle = 140 ,scale = 1)

#rotate image using affine transformation
rotated_image = cv2.warpAffine(image, rotation_matrix, (image.shape[1],image.shape[0]))


scale_percentage = 50

# dimensions of the scaled image part
width = int(rotated_image.shape[1] * scale_percentage / 100)
height = int(rotated_image.shape[0] * scale_percentage / 100)
dims  = (width, height)

# scaling the image using resize function
scaled_image = cv2.resize(rotated_image, dims, interpolation = cv2.INTER_AREA)


print(image.shape, " vs ", scaled_image.shape) #output: (610, 996, 3)  vs  (305, 498, 3)



# crop the image
image_dims = image.shape

#dimensions for start and end of the croping shape
h_s, h_e, w_s, w_e = [100, 550, 170 , 850] #defined by trail and error
width_dims = [w_s,w_e]
height_dims = [h_s,h_e]

#cliping the dimensions to avoid spilling over the image
np.clip(height_dims, a_min = 0, a_max = image_dims[0])
np.clip(width_dims, a_min = 0, a_max = image_dims[1])

#slicing the required matric from original image
croped_image = image[height_dims[0]:height_dims[1], width_dims[0]:width_dims[1]]

cv2.imwrite('Rotated_image.png', rotated_image)
cv2.imwrite('Scaled_image.png', scaled_image)
cv2.imwrite('Croped_image.png', croped_image)
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.