0% found this document useful (0 votes)
122 views

(CS-603 - Computer Graphics) Practical File

This document contains the practical file submission of a student named Zaid Kesarani for the course CS-603 Computer Graphics. It includes questions on matrix operations, converting an image to grayscale, plotting basic shapes like lines, circles, ellipses, rectangles and polygons using Python matplotlib library. For each question, relevant code is provided to demonstrate the concept along with sample output.

Uploaded by

Parth Virani
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)
122 views

(CS-603 - Computer Graphics) Practical File

This document contains the practical file submission of a student named Zaid Kesarani for the course CS-603 Computer Graphics. It includes questions on matrix operations, converting an image to grayscale, plotting basic shapes like lines, circles, ellipses, rectangles and polygons using Python matplotlib library. For each question, relevant code is provided to demonstrate the concept along with sample output.

Uploaded by

Parth Virani
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/ 6

[CS-603 | Computer Graphics]

PRACTICAL FILE
Name: Zaid Kesarani

Department: Computer Engineering

UIAR No.: 11300

Semester: IV

Submitted to: Dr. Sachin Sharma

Q.1 Understanding matrix operations like addition,


multiplication in software.
Matrix Addition

Matrix Multiplication

 
Q.2 Reading image file and converting RGB to gray image.

a=imread('E:\College Study Material\Second Year-2019-20\MidSem 2020\CS-603,


Computer Graphics\rose.jpg')
i=imresize(0,[256,256],"nearest");
d=rgb2gray(a);
subplot(2,2,4);
y=imshow(i);
b=imread('E:\College Study Material\Second Year-2019-20\MidSem 2020\CS-603,
Computer Graphics\rose.jpg')
e=rgb2gray(b);
subplot(2,2,1);
s=imshow(e);
c=imread('E:\College Study Material\Second Year-2019-20\MidSem 2020\CS-603,
Computer Graphics\rose.jpg')
f=rgb2gray(c);
subplot(2,2,3);
s1=imshow(f);
h=imread('E:\College Study Material\Second Year-2019-20\MidSem 2020\CS-603,
Computer Graphics\rose.jpg')
u=rgb2gray(h);
subplot(2,2,2);
s2=imshow(u);

Q.3 Plotting line graph and circle using python and other
graphics libraries.

import matplotlib.pyplot as plt


import matplotlib.patches as patches

defplotCircle(radius):
circle = patches.Circle((0,0), radius ,facecolor ='red',edgecolor =
'green',linestyle='dotted',linewidth='2.2')
plt.gca().add_patch(circle)
plt.axis('scaled')
plt.title('circle')
plt.show()

def main():
radius=float(input('enter the radius:'))
plotCircle(radius)
if __name__ == '__main__' :
main()

enter the radius:12

Q.4 Plotting rectangle and ellipse using python and other


graphics libraries.
Ellipse:

import matplotlib.pyplot as plt


importmatplotlib.patches as patches

def plotEllipse(width,height):
ellipse= patches.Ellipse((0,0), width,height, angle=15, fc='cyan',
ec='red',linestyle='dashed',lw='2.2')
plt.gca().add_patch(ellipse)
plt.axis('scaled')
plt.title('ellipse')
plt.show()
   
def main():
width=float(input('enter the width:'))
height=float(input('enter the height:'))
plotEllipse(width,height)
   
if __name__ == '__main__' :
main()

enter the width:4


enter the height:2
Rectangle:

import matplotlib.pyplot as plt


import matplotlib.patches as patches

def plotRectangle(length,breadth):
rect=patches.Rectangle((0,0),length,breadth)
plt.gca().add_patch(rect)
plt.axis('scaled')
plt.title('Rectangle')
plt.show()
   
def main():
length=float(input('enter the length:'))
breadth=float(input('enter the breadth:'))
plotRectangle(length,breadth)
   
if __name__ == '__main__' :
main()

enter the length:5


enter the breadth:3
Q.5 Plotting polygon shape using python and other graphics
libraries.

import matplotlib.pyplot as plt


import matplotlib.patches as patches

def plotPolygon(points):
poly = patches.Polygon(points,ec='red',linestyle='dashed',lw='4')
plt.gca().add_patch(poly)
plt.axis('scaled')
plt.title('polygon')
plt.show()
   
def main():
points=eval(input('enter the points:'))
plotPolygon(points)

if __name__ == '__main__':
main()

enter the points:[[2.5,4], [2,6], [4,8],[6,6],[5.5,4]]

You might also like