Professional Documents
Culture Documents
CssyllCG LAB
CssyllCG LAB
CssyllCG LAB
BE – IV
Computer Graphics & Image Processing Lab
(21CSL66)
USN: _______________________________________________
Department: __________________________________________
The split-up of CIE marks for record/ journal and test are in the ratio 60:40.
• Each experiment to be evaluated for conduction with observation sheet and record write-up.
Rubrics for the evaluation of the journal/write-up for hardware/software experiments designed
by the faculty who is handling the laboratory session and is made known to students at the
beginning of the practical session.
• Record should contain all the specified experiments in the syllabus and each experiment write-
up will be evaluated for 10 marks.
• Total marks scored by the students are scaled downed to 30 marks (60% of maximum marks).
• Weightage to be given for neatness and submission of record/write-up on time.
• Department shall conduct 02 tests for 100 marks, the first test shall be conducted after the 8th
week of the semester and the second test shall be conducted after the 14th week of the semester.
• In each test, test write-up, conduction of experiment, acceptable result, and procedural
knowledge will carry a weightage of 60% and the rest 40% for viva-voce.
• The suitable rubrics can be designed to evaluate each student’s performance and learning ability.
Rubrics suggested in Annexure-II of Regulation book
• The average of 02 tests is scaled down to 20 marks (40% of the maximum marks).
The Sum of scaled-down marks scored in the report write-up/journal and average marks of two
tests is the total CIE marks scored by the student.
Semester End Evaluation (SEE):
import turtle
return line_points
# Example usage
turtle.setup(500, 500)
turtle.speed(0) # Fastest drawing speed
turtle.exitonclick()
Output:
import turtle
import math
# Draw a rectangle
draw_rectangle(-200, 0, 100, 50, "blue")
# Draw a circle
draw_circle(100, 100, 50, "red")
Output:
# Create a 3D canvas
scene = canvas(width=800, height=600, background=color.white)
# Draw a cuboid
cuboid = draw_cuboid((-2, 0, 0), 2, 2, 2, color.blue)
# Draw a cylinder
cylinder = draw_cylinder((2, 2, 0), 1, 10, color.red)
# Create a 3D canvas
scene = canvas(width=800, height=600, background=color.white)
Output:
4. Develop a program to demonstrate 2D transformation on basic objects
import cv2
import numpy as np
# Apply transformations
translated_obj = np.array([np.dot(translation_matrix, [x, y, 1])[:2] for x, y in
obj_points], dtype=np.int32)
rotated_obj = np.array([np.dot(rotation_matrix, [x, y, 1])[:2] for x, y in
translated_obj], dtype=np.int32)
scaled_obj = np.array([np.dot(scaling_matrix, [x, y, 1])[:2] for x, y in rotated_obj],
dtype=np.int32)
Output:
5. Develop a program to demonstrate 3D transformation on 3D objects.
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import numpy as np
# Initialize Pygame
pygame.init()
# Set up OpenGL
glClearColor(0.0, 0.0, 0.0, 1.0)
glEnable(GL_DEPTH_TEST)
glMatrixMode(GL_PROJECTION)
gluPerspective(45, (display_width / display_height), 0.1, 50.0)
glMatrixMode(GL_MODELVIEW)
edges = np.array([
[0, 1], [1, 2], [2, 3], [3, 0],
[4, 5], [5, 6], [6, 7], [7, 4],
[0, 4], [1, 5], [2, 6], [3, 7]
], dtype=np.uint32)
# Main loop
running = True
angle = 0
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Apply transformations
glLoadIdentity()
glMultMatrixf(translation_matrix)
glRotatef(angle, 1, 1, 0)
glMultMatrixf(rotation_matrix)
glMultMatrixf(scaling_matrix)
# Quit Pygame
pygame.quit()
Output:
6. Develop a program to demonstrate Animation effects on simple objects.
import pygame
import random
# Initialize Pygame
pygame.init()
# Define colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# Main loop
running = True
clock = pygame.time.Clock()
while running:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Quit Pygame
pygame.quit()
Output:
7. Write a Program to read a digital image. Split and display image into 4 quadrants,
up, down, right and left.
import cv2
if image is None:
print("Failed to load the image.")
else:
# Split the image into quadrants
top_left, top_right, bottom_left, bottom_right = split_image(image)
Input image
Output images
8. Write a program to show rotation, scaling, and translation on an image.
import cv2
import numpy as np
if image is None:
print("Failed to load the image.")
else:
# Display the original image
cv2.imshow("Original Image", image)
# Rotation
angle = 45 # Rotation angle in degrees
center = (image.shape[1] // 2, image.shape[0] // 2) # Center of rotation
rotation_matrix = cv2.getRotationMatrix2D(center, angle, 1.0) # Rotation matrix
rotated_image = cv2.warpAffine(image, rotation_matrix, (image.shape[1],
image.shape[0]))
# Scaling
scale_factor = 0.5 # Scaling factor (0.5 means half the size)
scaled_image = cv2.resize(image, None, fx=scale_factor, fy=scale_factor)
# Translation
translation_matrix = np.float32([[1, 0, 100], [0, 1, -50]]) # Translation matrix (100
pixels right, 50 pixels up)
translated_image = cv2.warpAffine(image, translation_matrix, (image.shape[1],
image.shape[0]))
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
Input image
Output images
9. Read an image and extract and display low-level features such as edges, textures
using filtering techniques.
import cv2
import numpy as np
# Read the image
image_path = r"C:\Users\user\Downloads\gandhi.jpg" # Replace "your_image.jpg"
with the path to your image
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
if image is None:
print("Failed to load the image.")
else:
# Display the original image
cv2.imshow("Original Image", image)
# Apply Sobel filter to extract edges
sobel_x = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=3)
sobel_y = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize=3)
sobel_edges = cv2.magnitude(sobel_x, sobel_y)
sobel_edges = cv2.normalize(sobel_edges, None, 0, 255,
cv2.NORM_MINMAX, dtype=cv2.CV_8U)
# Display edges extracted using Sobel filter
cv2.imshow("Edges (Sobel Filter)", sobel_edges)
# Apply Laplacian filter to extract edges
laplacian_edges = cv2.Laplacian(image, cv2.CV_64F)
laplacian_edges = cv2.normalize(laplacian_edges, None, 0, 255,
cv2.NORM_MINMAX, dtype=cv2.CV_8U)
# Display edges extracted using Laplacian filter
cv2.imshow("Edges (Laplacian Filter)", laplacian_edges)
# Apply Gaussian blur to extract textures
gaussian_blur = cv2.GaussianBlur(image, (5, 5), 0)
# Display image with Gaussian blur
cv2.imshow("Gaussian Blur", gaussian_blur)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
10. Write a program to blur and smoothing an image.
import cv2
if image is None:
print("Failed to load the image.")
else:
# Display the original image
cv2.imshow("Original Image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
Input Image
Output images
11. Write a program to contour an image.
import cv2
if image is None:
print("Failed to load the image.")
else:
# Convert the image to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
import cv2
# Load the cascade classifier for face detection
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +
'haarcascade_frontalface_default.xml')
# Load the image
image = cv2.imread( r"C:\Users\user\Downloads\ucl.png")
# Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect faces in the grayscale image
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30,
30))
# Draw rectangles around the detected faces
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
# Display the image with detected faces
cv2.imshow('Face Detection', image)
# Wait for a key press to close the window
cv2.waitKey(0)
cv2.destroyAllWindows()
Output: