CG & IP Lab Manual-21CSL66
CG & IP Lab Manual-21CSL66
Lab Manual
Laboratory: Computer Graphics and Image
Processing Laboratory
Subject Code: 21CSL66
For IV Semester CSE
Prepared By:
PSO1: Students will have the knowledge of Software, Hardware, Network Models, Algorithms
and various Computer Programming Languages.
PSO2: Students will be able to develop computer applications in the areas related to Artificial
Intelligence, Machine Learning and IOT for efficient design of computer based system.
PSO3: Students will be able to develop Database Applications.
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):
Write a Program to read a digital image. Split and display image into 4
7 15 - 16
quadrants, up, down, right and left.
Read an image and extract and display low-level features such as edges,
9 19 - 20
textures using filtering techniques.
Program 01: Develop a program to draw a line using Bresenham’s line drawing technique.
import turtle
return line_points
# Example usage
turtle.setup(500, 500)
turtle.speed(0) # Fastest drawing speed
turtle.exitonclick()
OUTPUT:
Program 02: Develop a program to demonstrate basic geometric operations on the 2D object.
import turtle
import math
t.penup()
t.goto(x, y)
t.setheading(angle)
t.pendown()
# Draw a rectangle
draw_rectangle(-200, 0, 100, 50, "blue")
# Draw a circle
draw_circle(100, 100, 50, "red")
turtle.done()
OUTPUT:
Program 03: Develop a program to demonstrate basic geometric operations on the 3D object.
# 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
OUTPUT:
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:
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:
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:
Program-07: 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)
OUTPUT:
import cv2
import numpy as np
# Apply transformations
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))
OUTPUT:
Program-09: Read an image and extract and display low-level features such as edges, textures using
filtering techniques.
import cv2
import numpy as np
# Edge detection
edges = cv2.Canny(gray, 100, 200) # Use Canny edge detector
# Texture extraction
kernel = np.ones((5, 5), np.float32) / 25 # Define a 5x5 averaging kernel
texture = cv2.filter2D(gray, -1, kernel) # Apply the averaging filter for texture extraction
OUTPUT:
import cv2
# Gaussian Blur
gaussian_blur = cv2.GaussianBlur(image, (5, 5), 0)
# Median Blur
median_blur = cv2.medianBlur(image, 5)
# Bilateral Filter
bilateral_filter = cv2.bilateralFilter(image, 9, 75, 75)
OUTPUT:
import cv2
import numpy as np
# Find contours
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
OUTPUT:
import cv2
OUTPUT: