0% found this document useful (0 votes)
24 views1 page

2 ND

Uploaded by

patrick Park
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

2 ND

Uploaded by

patrick Park
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

6.Develop a program to demonstrate Animation effects on simple objects.

import pygame/import random/pygame.init()/screen_width = 800


screen_height = 600/screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Animation Effects")
BLACK = (0, 0, 0)/WHITE = (255, 255, 255)/RED = (255, 0, 0)/GREEN = (0, 255, 0)
BLUE = (0, 0, 255)/num_objects = 10objects = []/for _ in range(num_objects):
x = random.randint(50, screen_width - 50)/y = random.randint(50, screen_height - 50)
radius = random.randint(10, 30)/color = random.choice([RED, GREEN, BLUE])
speed_x = random.randint(-5, 5)/speed_y = random.randint(-5, 5)/
objects.append({"x": x, "y": y, "radius": radius, "color":
color, "speed_x": speed_x, "speed_y": speed_y})/running = True/clock = pygame.time.Clock()
while running:/for event in pygame.event.get():/if event.type == pygame.QUIT:
running = False/screen.fill(WHITE)/for obj in objects:/obj["x"] += obj["speed_x"]
obj["y"] += obj["speed_y"]/if obj["x"] - obj["radius"] < 0 or obj["x"] + obj["radius"] > screen_width:
/obj["speed_x"] = -obj["speed_x"]/if obj["y"] - obj["radius"] < 0 or obj["y"] +
obj["radius"] > screen_height:/obj["speed_y"] = -obj["speed_y"]
/pygame.draw.circle(screen, obj["color"], (obj["x"], obj["y"]), obj["radius"])
/pygame.display.flip()/clock.tick(60) # Limit the frame rate to 60 FPS/pygame.quit()
7.Write a Program to read a digital image. Split and display image into 4 quadrants
, up, down, right and left.
import cv2/import numpy as np/image_path = "image/atc.jpg"
img = cv2.imread(image_path)/height, width, _ = img.shape
up_left = img[0:height//2, 0:width//2]/up_right = img[0:height//2, width//2:width]
down_left = img[height//2:height, 0:width//2]down_right = img[height//2:height, width//2:width]
canvas = np.zeros((height, width, 3), dtype=np.uint8)/canvas[0:height//2, 0:width//2] = up_left
canvas[0:height//2, width//2:width] = up_right/canvas[height//2:height, 0:width//2] = down_left
canvas[height//2:height, width//2:width] = down_right/cv2.imshow("Image Quadrants", canvas)
cv2.waitKey(0)/cv2.destroyAllWindows()
8.Write a program to show rotation, scaling, and translation on an image
import cv2/import numpy as np
image_path = "image/atc.jpg" # Replace with the path to your image
img = cv2.imread(image_path)/height, width, _ = img.shape
rotation_matrix = cv2.getRotationMatrix2D((width/2, height/2), 45, 1) # Rotate by 45 degrees
scaling_matrix = np.float32([[1.5, 0, 0], [0, 1.5, 0]]) # Scale by 1.5x
translation_matrix = np.float32([[1, 0, 100], [0, 1, 50]]) # Translate by (100, 50)
rotated_img = cv2.warpAffine(img, rotation_matrix, (width, height))
scaled_img = cv2.warpAffine(img, scaling_matrix, (int(width*1.5), int(height*1.5)))
translated_img = cv2.warpAffine(img, translation_matrix, (width, height))
cv2.imshow("Original Image", img)/cv2.imshow("Rotated Image", rotated_img)
cv2.imshow("Scaled Image", scaled_img)/cv2.imshow("Translated Image", translated_img)
cv2.waitKey(0)/cv2.destroyAllWindows()
9.Read an image and extract and display low-level features such as edges,
textures using filtering techniques.
import cv2/import numpy as np/image_path = "image/atc.jpg"
img = cv2.imread(image_path)/gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 100, 200) kernel = np.ones((5, 5), np.float32) divide 25
texture = cv2.filter2D(gray, -1, kernel) /cv2.imshow("Original Image", img)
cv2.imshow("Edges", edges)/cv2.imshow("Texture", texture)
cv2.waitKey(0)/cv2.destroyAllWindows()
10.Write a program to blur and smoothing an image.
import cv2/image = cv2.imread('image/atc.jpg')
gaussian_blur = cv2.GaussianBlur(image, (5, 5), 0)
median_blur = cv2.medianBlur(image, 5)
bilateral_filter = cv2.bilateralFilter(image, 9, 75, 75)
cv2.imshow('Original Image', image)/cv2.imshow('Gaussian Blur', gaussian_blur)
cv2.imshow('Median Blur', median_blur)/cv2.imshow('Bilateral Filter', bilateral_filter)
cv2.waitKey(0)/cv2.destroyAllWindows()

You might also like