Challenge

Project 1

import cv2
import numpy as np

def read_image(image_path):
image = cv2.imread(image_path)
return image

def display_image(window_name,read_image):
cv2.imshow(window_name,read_image)
cv2.waitKey(0)

def save_image(image_name,image):
cv2.imwrite(image_name,image)

def resize_image(image,dimensions,method_number):
methods = [cv2.INTER_AREA,cv2.INTER_LINEAR,cv2.INTER_NEAREST,cv2.INTER_CUBIC,cv2.INTER_LANCZOS4]
resize_method = methods[method_number]
resized_image = cv2.resize(image,dimensions,interpolation=resize_method)
return resized_image

def crop_image(image,dimensions):
image_dims = image.shape
h_s , h_e , w_s , w_e = dimensions
width_dims = [w_s,w_e]
height_dims = [h_s,h_e]
np.clip(height_dims,a_min=0,a_max=image_dims[0])
np.clip(width_dims,a_min=0,a_max=image_dims[1])
crop_image = image[height_dims[0]:height_dims[1],width_dims[0]:width_dims[1]]
return crop_image

image = read_image("C:\\Users\\Welcome\\Pictures\\Skill-lync\\Challenge1_1638957930.png")
display_image('window_name',image)
save_image('saved_image.jpg',image)

#image_rotation #Here the original image is rotated at 140 degree angle using rotation matrix
height , width = image.shape[:2]
matrix = cv2.getRotationMatrix2D((width/2,height/2),140,1)
rotated_image = cv2.warpAffine(image,matrix,(height,width))
cv2.imshow('rotation',rotated_image)
cv2.waitKey(0)

#resizing_rotated_image #Here after rotating the image the size of the rotated image is reduced by 50% of its original size
print(image.shape)
dimensions = (305,498) #As the original dimensions of the image is (610,996), so to reduce its size by 50% we have to reduce its dimensions by half of its original dimensions i.e. (305,498)
methods = 0
resized_image = resize_image(rotated_image,dimensions,methods)
display_image('resized_image',resized_image)

#image_cropping #Here the image is cropped in such way that it focuses only on the car
crop_dimensions = [80,550,150,850]
cropped_image = crop_image(image,crop_dimensions)
display_image('cropped image',cropped_image)

image_shape

Cropped_image

Rotated_image

Resized_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.