Document 300712

SEC
IT/VII
GM LAB MANUAL
SRINIVASAN ENGINEERING COLLEGE
INFORMATION TECHOLOGY
ANNA UNIVERSITY OF TECHNOLOGY TRICHIRAPALLI
REGULATION 2008
VII IT (2010-2014)
CS1357
GRAPHICS AND MULTIMEDIA LABORATORY
LAB MANUAL
PREPARED BY
S.AMRITHA, Assistant Professor.
1
SEC
IT/VII
GM LAB MANUAL
PREFACE
This laboratory manual is prepared by the Department of Computer Science and engineering for
Graphics and Multimedia Laboratory (CS1357). This lab manual can be used as instructional
book for students, staff and instructors to assist in performing and understanding the experiments.
In the first part of the manual, experiments as per syllabus are described and in the second part of
the manual, experiments that are beyond the syllabus but expected for university laboratory
examination are displayed. This manual will be available in electronic form from College’s
official website, for the betterment of students.
2
SEC
IT/VII
GM LAB MANUAL
ACKNOWLEDGEMENT
With great pleasure and deep sense of gratitude, we take this opportunity to express my
hearty thanks and deep regards to the support offered by the chairman Shri. A.Srinivasan.
We also take this opportunity to express a deep sense of gratitude to our Principal
Dr.B.Karthikeyan, for his valuable information and guidance, which helped me in completing
this task through various stages.
We extend our hearty thanks to our head of the department P.Manjula M.E, for her
constant encouragement and constructive comments.
Finally the valuable comments from fellow faculty and assistance provided by
the
department are highly acknowledged. We would like to thank everyone who helped us at
various stages in completing this work.
Last but not least we express our heartfelt thanks to Lord Almighty for being there
when we needed him most always.
3
SEC
IT/VII
GM LAB MANUAL
TABLE OF CONTENTS
CHAPTER NO .
TITLE
PAGE NO.
1
SYLLABUS
6
2
INTRODUCTION TO THE LANGUAGE
7
3
SYSTEM REQUIREMENTS
13
1 Hardware Requirements
13
2 Software Requirements
13
ABOUT EACH EXPERIMENT
14
1. Aim
14
2. Description About Each Experiment
14
3. Learning Objective
15
4. General procedure to execute programs
16
LIST OF EXPERIMENTS
17
1. To implement Bresenham’s algorithms for line, circle
17
4
5
and ellipse drawing.
2. To perform 2D Transformations such as translation,
29
rotation, scaling, reflection and sharing
3. To implement Cohen-Sutherland 2D clipping and
38
window-viewport mapping
4. To perform 3D Transformations such as translation,
55
rotation and scaling
5. To visualize projections of 3D images
64
4
SEC
IT/VII
GM LAB MANUAL
6. To convert between colour models
71
7. To implement text compression algorithm.
79
8. To implement image compression algorithm.
83
9. To perform animation using any Animation software.
88
10. To perform basic operations on image using any
93
image editing software
6
7
EXPERIMENTS BEYOND THE SYLLABUS
98
1. Huffman Encoding
98
2. Graphical Animation
106
3. Image Decompression
109
FUTURE ENHANCEMENTS
110
REFERENCES
111
5
SEC
IT/VII
GM LAB MANUAL
CHAPTER 1
SYLLABUS
CS1357 – GRAPHICS AND MULTIMEDIA LABORATORY
LIST OF EXPERIMENTS
1. To implement Bresenham’s algorithms for line, circle and ellipse drawing.
2. To perform 2D Transformations such as translation, rotation, scaling, reflection and sharing.
3. To implement Cohen-Sutherland 2D clipping and window-viewport mapping.
4. To perform 3D Transformations such as translation, rotation and scaling.
5. To visualize projections of 3D images and Hidden Surface Elimination.
6. To convert between color models.
7. To implement text compression algorithm.
8. To implement image compression algorithm.
9. To perform animation using any Animation software.
10. To perform basic operations on image using any image editing software.
6
SEC
IT/VII
GM LAB MANUAL
CHAPTER 2
INTRODUCTION OF THE LANGUAGE (CORRESPONDING VERSION)
TURBO C
C is a general-purpose programming language initially developed by Dennis Ritchie
between 1969 and 1973 at AT&T Bell Labs.
The initial development of C occurred at AT&T Bell Labs between 1969 and
1973; according to Ritchie, the most creative period occurred in 1972. It was named "C"
because its features were derived from an earlier language called "B", which according to Ken
Thompson was a stripped-down version of the BCPL programming language.
The origin of C is closely tied to the development of the Unix operating system,
originally implemented in assembly language on a PDP-7 by Ritchie and Thompson,
incorporating several ideas from colleagues. Eventually they decided to port the operating
system to a PDP-11. B's inability to take advantage of some of the PDP-11's features,
notably byte addressability, led to the development of an early version of C.
C is one of the most widely used programming languages of all time, and there are very
few computer architectures for which a C compiler does not exist.
C allows programmers to manipulate the main elements—bytes, bits, and addresses—
that influence the way a computer functions.
Programs written in C are efficient and fast. This is due to its variety of data types and
powerful operators. It is many times faster than BASIC.
Another important feature of C is its ability to extend itself. A program is basically a
collection of functions, which are supported by the C library
Importance/Advantages of programming in C:
1) Easy to understand.
2) Freedom of using different type of data.
3) Short listed words could be use.
7
SEC
IT/VII
GM LAB MANUAL
4) Efficient and fast programming.
5) It can be used as mid-level language.
6) Any type of software and operating system be developed with the help of C language.
LIMITATIONS
 Weak text processing capabilities - C's string library is extremely primitive (it doesn't
even define an actual string type), and text processing is labor-intensive and error-prone.

Security and safety issues: several library functions (gets() being the most notorious)
provide easy exploits for malware, and anything involving pointers is going to be
unsafe (it's hard to guard against being passed an invalid pointer);

Weak memory management capabilities - Like text processing, managing memory in
C is labor-intensive and error-prone

No built-in collections library - C doesn't provide ready made collections (lists,
queues, stacks, etc.), meaning you have to roll your own

No built-in support for networking, sound, graphics, etc. - C is a product of the
early 1970s and it shows; byte streams are about the highest level of abstraction you're
going to find in the C library.
APPLICATIONS

C language is used for creating computer applications and also used a lot in writing
embedded software/firmware for various electronics, industrial and communications
products which use micro-controllers.

It is also used in developing verification software, test code, simulators etc. for various
applications and hardware products.

C has been used successfully for every type of programming problem imaginable from
operating systems to spreadsheets to expert systems

C was initially used for system development work, in particular the programs that
make-up the operating system.

C has been used as a general-purpose language because of its popularity with
programmers
8
SEC
IT/VII
GM LAB MANUAL
JAVA
Java is an Object Oriented programming language developed by Sun Microsystems in
1991.Initially it was known as Oak but latter it renamed to java.
Java was developed by taking the best points from other programming languages,
primarily C and C++.
Java is such a great language and platform for any kind of application. It is open, fast,
powerful, runs on any platform, and there are more jobs for Java than any other programming
language.
Java is a well known technology which allows you for software designed and written
only once for an "virtual machine" to run on a different computers, supports various
Operating System like Windows PCs, Macintoshes, and Unix computers.
Error prone tasks such as pointers and memory management have either been
eliminated or are handled by the Java environment automatically rather than by the
programmer.
Advantages of JAVA
JAVA offers a number of advantages to developers.
Java is simple: Java was designed to be easy to use and is therefore easy to write, compile,
debug, and learn than other programming languages. The reason that why Java is much simpler
than C++
Java is object-oriented: Java is object-oriented because programming in Java is centered on
creating objects, manipulating objects, and making objects work together. This allows you to
create modular programs and reusable code.
Java is platform-independent: One of the most significant advantages of Java is its ability to
move easily from one computer system to another.
Java is distributed: Distributed computing involves several computers on a network working
together. Java is designed to make distributed computing easy with the networking capability
9
SEC
IT/VII
GM LAB MANUAL
that is inherently integrated into it. Writing network programs in Java is like sending and
receiving data to and from a file.
Java is interpreted: An interpreter is needed in order to run Java programs. The programs are
compiled into Java Virtual Machine code called bytecode. The bytecode is machine
independent and is able to run on any machine that has a Java interpreter.
Java is secure: Java is one of the first programming languages to consider security as part of
its design. The Java language, compiler, interpreter, and runtime environment were each
developed with security in mind.
Current Limitations and Disadvantages of Java
These exist mostly because the language is still evolving.
It is unclear which problems will be solved and when.
1. Slow
o
Internet as a whole

Potential huge show-stopper problem.

Bandwidth is a limited resource that is easily squandered.

Minimal incentive for people to conserve.

Potential demand is unbounded, potential supply is bounded.
Solutions:

Write applications instead of applets (but then you lose some
advantages)

o
Cache your applets (only partial solution).
Java compiler

Not yet well optimized.

Takes more time to compile a large program than a good C++ compiler.
2. Environment limitations
Currently lacks:
10
SEC
IT/VII
o
Browser
o
Interactive source-level debugger
o
User interface builder
GM LAB MANUAL
3. Applet limitations imposed due to security model
o
Cannot access local data
o
Can only download data from the site where the applet is located
o
Cannot make system calls
o
Solution: Use applications
4. Programming language limitations
o
No `Templates' yet.

o
Limits ability to create really good data structures
No `Function pointers' or `blocks'

These would allow greater abstraction and more flexible data-structure
design

o
Available in both C++ and Smalltalk
Basic classes in class library are lacking important features

The class library was created to quickly and has now been widely
adopted, making it hard to change.

This is also a problem with other languages

We can expect the current widespread standardization to fragment as
vendors introduce competing classes to fill the gaps
5. Platform limitations
Full environment available only for:
o
Windows 95/NT
o
Macintosh
o
Sun Solaris
Other platforms must wait for 3rd party support
11
SEC
IT/VII
GM LAB MANUAL
Application Java programming Language :
1.Since Java has inbuilt networking features so it is widely used for developing network related
programs and softwares. Socket Programming using JAVA is very simple and efficient and
simple as compared to c.
2.It is widely used for creating web applications and it can also generate static HTML content
like php and JavaScript so it is used in website designing too.
3.In application software development Java is widely used because it is a fully Object Oriented
programming language.
4.Creating Graphical User Interface(GUI) in Java is very simple and efficient as compared to c
and c++.So it is also used in creating GUI for applications.
12
SEC
IT/VII
GM LAB MANUAL
CHAPTER 3
SYSTEM REQUIREMENTS
1 HARDWARE REQUIREMENTS:
Intel Pentium 915 GV
80GB SATA II
512MB DDR
2 SOFTWARE REQUIREMENTS:
TURBO C
Java
Macromedia Flash
Adobe Photoshop
13
SEC
IT/VII
GM LAB MANUAL
CHAPTER 4
ABOUT THE GRAPHICS AND MULTIMEDIA LABORATORY :
1 AIM
The aim of the graphics and multimedia laboratory is to give students a good
understanding of basic concepts of computer graphics and the need of developing
graphics applications.
2 DESCRIPTION ABOUT EACH EXPERIMENT
EXPERIMENT No 1:TO IMPLEMENT BRESENHAM’S ALGORITHMS FOR
LINE, CIRCLE AND ELLIPSE DRAWING
The bersenham’s algorithm was developed to draw lines using two end points and to
draw circle using radius and center point and ellipse using center coordinates.
EXPERIMENT No 2: TO PERFORM 2D TRANSFORMATIONS SUCH AS
TRANSLATION, ROTATION, SCALING, REFLECTION AND SHARING
2D Transformations are used to locate objects, to shape objects, to change
viewing positions, and even to change how something is viewed.
EXPERIMENT No 3: TO IMPLEMENT COHEN-SUTHERLAND 2D
CLIPPING AND WINDOW-VIEWPORT MAPPING
Clipping window: Part of the scene we want to draw on the screen.
Viewport: Part of the display window where the contents of the clipping
window is mapped to/drawn.
EXPERIMENT No 4: TO PERFORM 3D TRANSFORMATIONS SUCH AS
TRANSLATION, ROTATION AND SCALING
This program describes how to apply transformations to 3-D models in the Windows
Presentation Foundation (WPF) graphics system. Transformations allow the developer to
reposition, resize, and reorient models without changing the base values that define them
14
SEC
IT/VII
GM LAB MANUAL
EXPERIMENT NO 5: TO VISUALIZE PROJECTIONS OF 3D IMAGES AND
HIDDEN SURFACE ELIMINATION
This program describes how to view the front, side and top elevation of the 3D
image by projecting the 3D image using the parallel line projection.
EXPERIMENT NO 6: TO CONVERT BETWEEN COLOR MODELS.
Color model is a method for explaining the properties or behavior of the color within
some context. This conversion can be achieved by transformed the parameters of HSV to the
RGB settings needed for the color monitor
EXPERIMENT
NO
7:
TO
IMPLEMENT
TEXT
COMPRESSION
ALGORITHM
The main Objective is to compress the data without any loss using text compression
algorithm. It can be achieved by replace a long sequence of the same symbol by a shorter
sequence of a symbol.
EXPERIMENT
NO
8:
TO
IMPLEMENT
IMAGE
COMPRESSION
ALGORITHM
The basic idea behind this method of compression is to treat a digital image as an array
of numbers i.e., a matrix. Each image consists of a fairly large number of little squares called
pixels.
EXPERIMENT
NO
9:
TO
PERFORM
ANIMATION
USING
ANY
ANIMATION SOFTWARE
Animation is anything that moves on your screen like a cartoon character. It can be
achieved by using animation software like swims, flash
EXPERIMENT NO 10: TO PERFORM BASIC OPERATIONS ON IMAGE
USING ANY IMAGE EDITING SOFTWARE
The main Objective of this program is to use various image painting tools in
Photoshop.
3 LEARNING OBJECTIVES:
To understand the need of developing graphics applications.
To learn the hardware involved in building graphics applications.
15
SEC
IT/VII
GM LAB MANUAL
To learn algorithmic development of graphics primitives like: line, circle, ellipse,
polygon etc.
To learn the representation and transformation of graphical images and pictures.
To learn the concept of Color Generation.
4 GENERAL PROCEDURE FOR EXECUTING PROGRAM
First of all the source code is get compiled and the object code is returned i.e.binary
code(machine language).Then the linker is called Linker, a computer program that takes one or
more objects generated by a compiler and combines them into a single executable program.
Now when the program is executed then the .exe file is first loaded into the memory and then
executed by the processor.
In short the steps are:
1.Compilation
2.Linking
3.Loading
4.execution
16
SEC
IT/VII
GM LAB MANUAL
CHAPTER 5
TO IMPLEMENT BRESENHAM’S ALGORITHMS FOR LINE
EX NO: 1 A
DESCRIPTION ABOUT THE EXPERIMENT
It is the path between two end points. This algorithm was developed to draw lines on digital
plotters, but has found wide-spread usage in computer graphics
Objective
The Bresenham’s line algorithm is an algorithm which determines which order to form
a close approximation to a straight line between two given points
How it is being achieved?
The Cartesian slope-intercept equation for a straight line is
y=m.x+b
Line draws a line between two specified points.
Syntaxes & keywords
Void initgraph()-switches to graphics mode.
Putpixel- void putpixel(int x, int y, int color);
HOW TO EXECUTE THE SOURCE CODE
REQUIREMENTS FOR EXECUTION
S.No.
Facilities required
Quantity
1
System
1
2
O/S
Windws 98
3
Compiler
C
17
SEC
IT/VII
GM LAB MANUAL
EXPECTED OUTPUT AND ITS FORM
This program takes end coordinates as input and display the line as output
ADVANTAGES
An fast incremental algorithm
Uses only integer calculations
ALGORITHM
Step 1: Start.
Step 2: Initialize the graphics header files and functions.
Step 3: Declare the required variables and functions.
Step 4: Get the four points for drawing a line namely x1,x2,y1,y2.
Step 5: Draw the line using the algorithm.
Step 6: Display the output.
Step 7: stop.
SOURCE CODE
PROGRAM NAME: LINE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int x1,x2,y1,y2,gd=DETECT,gm,dx,dy,step;
int x,y,const1,const2,k,p,x_end;
initgraph(&gd,&gm,"");
printf("\nEnter the end point co-ordinates of the line.......\n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
dx=abs(x2-x1);
dy=abs(y2-y1);
p=2*dy-dx;
const1=2*dy;
18
SEC
IT/VII
GM LAB MANUAL
const2=2*(dy-dx);
if(x1>x2)
{
x=x2; y=y2;
x_end=x1;
}
else
{
x=x1; y=y1;
x_end=x2;
}
putpixel(x,y,15);
while(x<x_end)
{
x++;
if(p<0)
p+=const1;
else
{
y++;
p+=const2;
}
putpixel(x,y,15);
}
getch();
closegraph();
}
OUTPUT
Enter the end point co-ordinates of the line.......
100 200 300 400
19
SEC
IT/VII
GM LAB MANUAL
RESULT
Thus the Bresenham’s algorithm has been executed and the result is as shown above..
VIVA QUESTIONS
1. What is the purpose of presentation graphics?
Presentation graphics is used to produce illustrations for reports or to generate 35mm slides or transparencies for use with projectors. Presentation graphics is commonly used to
summarize financial, statical, mathematical, scientific, and economic data for research reports,
managerial reports, consumer information bulletins, and other types of reports.
2. What is pixel?
Each screen point in a monitor is called a pixel/pel. It is also called picture
element.
3. What are the disadvantages of DDA algorithm?
• Round-off error in successive additions of the floating-point increment can
cause the calculated pixel positions to drift away from the true line path for long line
segments.
• Rounding operations and floating-point arithmetic in procedure are still time consuming.
20
SEC
IT/VII
EX NO: 1B
GM LAB MANUAL
TO IMPLEMENT BRESENHAM’S ALGORITHMS FOR CIRCLE
DESCRIPTION ABOUT THE EXPERIMENT
The purpose of Bresenham’s circle algorithm is to generate the set of points that approximate a
circle on a pixel-based display
Objective
A circle is defined as a set of points that are all at a given distance r form the center
position(x1, y1).
How it is being achieved?
The distance relationship is expressed by the Pythagorean theorem in Cartesian coordinates as
(x – x c )2+(y-y c)2=r2
The algorithm starts with the circle equation
.
Syntaxes & keywords
Void initgraph()-switches to graphics mode.
Putpixel- void putpixel(int x, int y, int color);
HOW TO EXECUTE THE SOURCE CODE
REQUIREMENTS FOR EXECUTION
S.No.
Facilities required
Quantity
1
System
1
2
O/S
Windows 98
3
Compiler
Turbo C
21
SEC
IT/VII
GM LAB MANUAL
EXPECTED OUTPUT AND ITS FORM:
This program takes center coordinates and radius as input and display the output as the
circle.
LIMITATIONS
Time consumption is high
The distance between the pixels is not equal so we wont get smooth circle
ALGORITHM
Step 1: Start.
Step 2: Initialize the graphics header files and functions.
Step 3: Declare the required variables and functions.
Step 4: Get the co-ordinates and radius of the circle.
Step 5: Draw the circle using the algorithm.
Step 6: Display the output.
Step 7: stop.
SOURCE CODE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
void plotpoint(int,int,int,int);
int xc,yc,r,x,y,p;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm," ");
printf("Enter the center co-ordinates of the circle:\n");
scanf("%d%d",&xc,&yc);
printf("Enter the radius of the circle:\n");
22
SEC
IT/VII
GM LAB MANUAL
scanf("%d",&r);
x=0; y=r;
plotpoint(xc,yc,x,y);
p=1-r;
while(x<y)
{
if(p<0)
x=x+1;
else
{
x=x+1; y=y-1;
}
if(p<0)
p=p+2*x+1;
else
p=p+2*(x-y)+1;
plotpoint(xc,yc,x,y);
}
getch();
}
void plotpoint(int xc,int yc,int x,int y)
{
putpixel(xc+x,yc+y,1);
putpixel(xc-x,yc+y,1);
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,1);
putpixel(xc+y,yc+x,1);
putpixel(xc-y,yc+x,1);
putpixel(xc+y,yc-x,1);
putpixel(xc-y,yc-x,1);
}
23
SEC
IT/VII
GM LAB MANUAL
OUTPUT
Enter the center co-ordinates of the circle:
200
200
Enter the radius of the circle:
50
RESULT
The Bresenham’s algorithm for circle has been executed and the result is as shown above..
24
SEC
IT/VII
EX NO: 1C
GM LAB MANUAL
TO IMPLEMENT BRESENHAM’S ALGORITHMS FOR ELLIPSE
DESCRIPTION ABOUT THE EXPERIMENT
An ellipse is defined as the set of points such that the sum of the distance from two fixed
positions is the same for all points. if the distances to the two point P=(x,y) on the ellipse are
labeled d1 and d2, the general equation of an ellipse can be stated as
d1+d2=constant
Objective
An ellipse is an elongated circle, therefore elliptical curves can be generated by
modifying circle drawing procedures to take into account the different dimensions of an ellipse
along the major and minor axes.
Syntaxes & keywords
Void initgraph()-switches to graphics mode.
Putpixel- void putpixel(int x, int y, int color);
HOW TO EXECUTE THE SOURCE CODE
EXPECTED OUTPUT AND ITS FORM
This program takes center coordinates and x axis and y axis as input and display the
output as the circle.
ALGORITHM
Step 1 : Start.
Step 2 : Initialize the graphics header files and functions.
Step 3 : Declare the required variables and functions.
Step 4 : Get the co-ordinates and radius of the ellipse.
25
SEC
IT/VII
GM LAB MANUAL
Step 5 : Draw the ellipse using the algorithm.
Step 6 : Display the output.
Step 7 : stop.
.
SOURCE CODE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define ROUND(a) ((int)(a+0.5))
void plotpoint(long int,long int,long int,long int);
void main()
{
long int xc,yc,rx,ry,rx2,ry2,x,y,px,p,tworx2,twory2,py;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
printf("Enter the center co-ordinates of the ellipse:\n");
scanf("%ld %ld ",&xc,&yc);
printf("Enter the radius along x-axis and y-axis:\n");
scanf("%ld %ld",&rx,&ry);
x=0;
y=ry;
px=0;
rx2=rx*rx;
ry2=ry*ry;
tworx2=2*rx2;
twory2=2*ry2;
py=tworx2*y;
plotpoint(xc,yc,x,y);
p=ROUND(ry2-(rx2*ry)+(.25*rx2));
while(px<py)
{
26
SEC
IT/VII
GM LAB MANUAL
x++;
px+=twory2;
if(p<0)
{
p+=ry2+px;
}
else
{
y--;
py-=tworx2;
p+=ry2+px-py;
}
plotpoint(xc,yc,x,y);
}
p=ROUND(ry2*(x+0.5)*(x+0.5)+rx2*(y-1)*(y-1)-rx2*ry2);
while(y>0)
{
y--;
py-=tworx2;
if(p>0)
p+=rx2-py;
else
{
x++;
px+=twory2;
p+=rx2-py+px;
}
plotpoint(xc,yc,x,y);
}
getch();
27
SEC
IT/VII
GM LAB MANUAL
}
void plotpoint(long int xc,long int yc,long int x,long int y)
{
putpixel(xc+x,yc+y,156);
putpixel(xc-x,yc+y,156);
putpixel(xc+x,yc-y,156);
putpixel(xc-x,yc-y,156);
}
OUTPUT
Enter the center co-ordinates of the ellipse:
200
200
Enter the radius along x-axis and y-axis:
80
40
RESULT
The Bresenham’s algorithm for ellipse has been executed and the result is as shown
above.
POSSIBLE SET QUESTIONS:
1. Write a program to perform Bresenham’s algorithm for line, ellipse and circle.
2. Implementation of Line, ellipse and circle attributes using Bresenham’s algorithm.
28
SEC
IT/VII
GM LAB MANUAL
TO PERFORM 2D TRANSFORMATIONS SUCH AS TRANSLATION,
ROTATION, SCALING, REFLECTION AND SHEARING
EX NO: 2
DESCRIPTION ABOUT THE EXPERIMENT
2DTransformaions are a fundamental part of computer graphics. Transformations are
used to position objects, to shape objects, to change viewing positions, and even to change how
something is viewed.
Objective
Translation is a rigid body transformation that moves objects without
deformation. That is, every point on the object is translated by the same amount.
Polygons are translated by adding the translation vector to the coordinate position of each
vertex and regeneration the polygon using the new set of vertex. To change the position
of a circle or ellipse translate the center coordinates and redraw the figure in the now
location
Syntaxes & keywords
Drawpoly function is used to draw polygons i.e. triangle, rectangle, pentagon, hexagon etc.
Declaration :- void drawpoly( int num, int *polypoints );
outtextxy function display text or string at a specified point(x,y) on the screen.
Declaration :- void outtextxy(int x, int y, char *string);
HOW IT IS BEING ACHIEVED?
TRANSLATION
A translation is applied to an object by repositioning it along a straight line path from one
coordinate location to another. We translate a two-dimensional point by adding translation
distances, tx and ty, to original coordinate position (x, y) to move the point to a new position (x\',
y\'). x\' = x + tx, y\' = y + ty. The translation distance pair (tx, ty ) is called a translation vector or
shift vector.
P’=P+T
29
SEC
IT/VII
GM LAB MANUAL
ROTATION
A 2-D rotation is applied to an object by repositioning it along a circular path in
the xy plane
P’=P.R
SCALING
A scaling transformation alters the size of an object. This operation can be carried out for
polygons by multiplying the coordinate values (x,y) of each vertex by scaling factors sx and sy to
produce the transformed coordinates
X’=X.SX
SHEARING
A transformation that distorts the shape of an object such that the transformed shape
appears as if the object were composed of internal layers that had been caused to slide over each
other is called a shear.
REQUIREMENTS FOR EXECUTION
S.No.
Facilities required
Quantity
1
System
1
2
O/S
Windows 98
3
Compiler
C
HOW TO EXECUTE THE SOURCE CODE
EXPECTED OUTPUT AND ITS FORM
This program is used to perform the 2D transformation by rotation, translation, reflection,
shearing
ALGORITHM
Step 1: Start the program.
30
SEC
IT/VII
GM LAB MANUAL
Step 2: Draw the image with default parameters.
Step 3: Get the choice from the user.
Step 4: Get the parameters for transformation.
Step 5: Perform the transformation.
Step 6: Draw the image.
Step 7: Stop the program.
SOURCE CODE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int i,poly4[10],poly1[10],poly2[10],poly3[10],tx,ty,sx,n,xr,yr,a;
int poly[10],poly5[10],sy;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
printf("\nEnter the number of vertices of the polygon:\n");
scanf("%d",&n);
printf("Enter the(x,y) co-ordinates of the vertices:\n");
for(i=0;i<2*n;i++)
{
scanf("%d",&poly[i]);
}
poly[2*n]=poly[0];
poly[2*n+1]=poly[1];
outtextxy(70,70,"Original image");
drawpoly(n+1,poly);
//TRANSLATION
getch();
31
SEC
IT/VII
GM LAB MANUAL
cleardevice();
outtextxy(30,30,"OriginalImage");
drawpoly(n+1,poly);
outtextxy(10,10,"Enter the Translation Factor");
gotoxy(30,3);
scanf("%d %d",&tx,&ty);
for(i=0;i<2*n;i+=2)
{
poly1[i]=poly[i]+tx;
poly1[i+1]=poly[i+1]+ty;
}
poly1[2*n]=poly1[0];
poly1[2*n+1]=poly1[1];
drawpoly(n+1,poly1);
getch();
cleardevice();
//SCALING
outtextxy(30,30,"Original Image");
drawpoly(n+1,poly);
outtextxy(10,10,"Enter the Scaling Factor");
gotoxy(30,3);
scanf("%d",&sx);
for(i=0;i<2*n;i+=2)
{
poly2[i]=poly[i]*sx;
poly2[i+1]=poly[i+1]*sx;
}
poly2[2*n]=poly2[0];
poly2[2*n+1]=poly2[1];
drawpoly(n+1,poly2);
32
SEC
IT/VII
GM LAB MANUAL
getch();
cleardevice();
//ROTATION
outtextxy(30,30,"Original Image");
drawpoly(n+1,poly);
outtextxy(10,10,"Enter the Rotation Factor");
gotoxy(30,3);
scanf("%d%d%d",&xr,&yr,&a);
for(i=0;i<2*n;i+=2)
{
poly3[i]=xr+((poly[i]-xr)*cos(a))-((poly[i+1]-yr)*sin(a));
poly3[i+1]=yr+((poly[i+1]-yr)*cos(a))+((poly[i]-xr)*sin(a));
}
poly3[2*n]=poly3[0];
poly3[2*n+1]=poly3[1];
drawpoly(n+1,poly3);
getch();
cleardevice();
//REFLECTION
outtextxy(30,30,"Original Image");
drawpoly(n+1,poly);
outtextxy(10,10,"Reflected Image");
for(i=0;i<2*n;i+=2)
{
poly4[i]=640-poly[i];
poly4[i+1]=poly[i+1];
}
poly4[2*n]=poly4[0];
poly4[2*n+1]=poly4[1];
33
SEC
IT/VII
GM LAB MANUAL
drawpoly(n+1,poly4);
getch();
cleardevice();
//SHEARING
outtextxy(30,30,"Original Image");
drawpoly(n+1,poly);
outtextxy(10,10,"Enter the shear factor");
gotoxy(30,3);
scanf("%d",&sh);
for(i=0;i<2*n;i+=2)
{
poly5[i]=poly[i]+sh*poly[i+1];
poly5[i+1]=poly[i+1];
}
poly5[2*n]=poly5[0];
poly5[2*n+1]=poly5[1];
drawpoly(n+1,poly5);
getch();
cleardevice();}
OUTPUT
Enter the number of vertices of the polygon:
4
Enter the(x,y) co-ordinates of the vertices:
100 100 150 100 150 150 100 150
Output
Original image
34
SEC
IT/VII
GM LAB MANUAL
Translation
Input:
Enter the Translation Factor
Output
Original image
Scaling
Input: Enter the scaling Factor
Output
Original image
Rotation
Input: Enter the Reflection Factor:
Output
Original image
200 200
2
250 250
60
35
SEC
IT/VII
GM LAB MANUAL
Reflection:
Output
Original image
Shearing
Input:
Enter the Shearing Factor:
Output
Original image
1
36
SEC
IT/VII
GM LAB MANUAL
RESULT
The program to implement various 2D transformations like translation, scaling, rotation,
reflection & shearing has been executed and shown the results as above.
VIVA QUESTIONS:
1. Define Translation.
A translation is applied to an object by repositioning it along a straight line path
from one coordinate location to another. We translate a two-dimensional point by adding
translation distances, tx and ty, to original coordinate position (x, y) to move the point to a new
position (x\', y\'). x\' = x + tx, y\' = y + ty. The translation distance pair (tx, ty ) is called a
translation vector or shift vector.
2. Define Rotation.
A 2-D rotation is applied to an object by repositioning it along a circular path in
the xy plane.
3. Define Scaling.
A scaling transformation alters the size of an object. This operation can be carried out
for polygons by multiplying the coordinate values (x,y) of each vertex by scaling factors sx
and sy to produce the transformed coordinates ( x\', y\' ). x\' = x. sx, y\' = y. sy.
4. Define Shear.
A transformation that distorts the shape of an object such that the transformed shape
appears as if the object were composed of internal layers that had been caused to slide over
each other is called a shear.
POSSIBLE SET QUESTIONS:
1. Implementation of Basic 2D Transformations.
2. Write a program to perform scaling, shearing and rotation using 2D transformations.
37
SEC
IT/VII
EX NO: 3 A
GM LAB MANUAL
TO IMPLEMENT COHEN-SUTHERLAND 2D CLIPPING
DESCRIPTION ABOUT THE EXPERIMENT
Any procedure that identifies those portions of a picture that are either inside or outside
of a specified region of space is referred to as a clipping algorithm or simply clipping. The region
against which an object is clipped is called a clip window.
Objective
This method speeds up the processing of line segments by performing initial tests that reduce the
number of intersections that must be calculated. Every line endpoint is assigned to four digit,
binary code called‖ region code‖. Region code identifies the location of the pint relative to the
boundaries of the clipping rectangle.
Bit 1: left
Bit 2: right
Bit 3: below
Bit 4: above
Syntaxes & keywords:
Drawpoly function is used to draw polygons i.e. triangle, rectangle, pentagon, hexagon etc.
Declaration :- void drawpoly( int num, int *polypoints );
outtextxy function display text or string at a specified point(x,y) on the screen.
Declaration :- void outtextxy(int x, int y, char *string);
HOW IT IS BEING ACHIEVED?
For a line segment with endpoints (x1,y1) and (x2,y2) and one or both endpoints outside the
clipping rectangle, the parametric representation is,
X = x1+u(x2-x1)
38
SEC
IT/VII
GM LAB MANUAL
Y= y1+u(y2-y1)
HOW TO EXECUTE THE SOURCE CODE
REQUIREMENTS FOR EXECUTION
S.No.
Facilities required
Quantity
1
System
1
2
O/S
Windows 98
3
Compiler
Turbo C
EXPECTED OUTPUT
The program can be executed by clipping the line that are clipped outside the region
ADVANTAGES
The key advantage of the algorithm is that it vastly reduces the number of line intersections that
must be calculated
Clipping and testing are done in fixed order. .
Efficient when most of the lines to be clipped
LIMITATIONS
It cannot explain all the details of the given problem it has no standard rule to solve any
operation different users use their own point of views
The Cohen Sutherland algorithm requires calculation of intersection of the line with the
window
39
SEC
IT/VII
GM LAB MANUAL
ALGORITHM
Step 1: Start
Step 2: Get the bottom-left coordinate of view port from the user.
Step 3: Get the top-right coordinate of view port from the user.
Step 4: Get the coordinates of 1st end point of line from the user.
Step 5: Get the coordinates of 2nd endpoint of line from the user.
Step 6: Print the region code of the first and second point.
Step 7: If the points lie inside the view port, print ‖The line is totally visible‖.
Step 8: If the starting point lies outside the view port, print ―The line is invisible‖
Step 9: If the starting point lies inside the view port and the ending point lies outside the view port,
print ―The line is partially visible‖
Step 10: Clip the line present outside the view port.
Step 11: Draw the clipped line present inside the view port.
Step 12: Stop
SOURCE CODE
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
/* Defining structure for end point of line */
typedef struct coordinate
{
int x,y;
char code[4];
}pt;
void drawwindow();
void drawline(pt p1,pt p2,int c1);
pt setcode(pt p);
int visibility(pt p1,pt p2);
40
SEC
IT/VII
GM LAB MANUAL
pt resetendpt(pt p1,pt p2);
main()
{
int gd=DETECT,gm,v;
pt p1,p2,ptemp;
initgraph(&gd,&gm,"");
cleardevice();
printf("\n\n\tEnter End point 1 (x,y): ");
scanf("%d %d",&p1.x,&p1.y);
printf("\n\n\tEnter End point 2 (x,y):");
scanf("%d %d",&p2.x,&p2.y);
cleardevice();
drawwindow();
getch();
drawline(p1,p2,15);
getch();
p1=setcode(p1);
p2=setcode(p2);
v=visibility(p1,p2);
switch(v)
{
case 0:cleardevice();
drawwindow();
drawline(p1,p2,15);
break;
case 1: cleardevice();
drawwindow();
break;
case 2: cleardevice();
p1=resetendpt(p1,p2);
p2=resetendpt(p2,p1);
41
SEC
IT/VII
GM LAB MANUAL
drawwindow();
drawline(p1,p2,15);
break;
}
getch();
closegraph();
return(0);
}
/* function to draw window*/
void drawwindow()
{
setcolor(RED);
line(150,100,450,100);
line(450,100,450,350);
line(450,350,150,350);
line(150,350,150,100);
}
/*function to draw line between two points*/
void drawline(pt p1,pt p2,int c1)
{
setcolor(c1);
line(p1.x,p1.y,p2.x,p2.y);
}
/*function to set code of the coordinate*/
pt setcode(pt p)
{
pt ptemp;
if(p.y<100)
ptemp.code[0]='1'; //top
42
SEC
IT/VII
GM LAB MANUAL
else
ptemp.code[0]='0';
if(p.y>350)
ptemp.code[1]='1'; //bottom
else
ptemp.code[1]='0';
if(p.x>450)
ptemp.code[2]='1'; //right
else
ptemp.code[2]='0';
if(p.x<150)
ptemp.code[3]='1'; //left
else
ptemp.code[3]='0';
ptemp.x = p.x;
ptemp.y=p.y;
return(ptemp);
}
/*function to determine visibillity of line*/
int visibility(pt p1,pt p2)
{
int i,flag=0;
for(i=0;i<4;i++)
{
if((p1.code[i]!='0')||(p2.code[i]!='0'))
flag=1;
}
if(flag==0)
return(0);
for(i=0;i<4;i++)
{
43
SEC
IT/VII
GM LAB MANUAL
if((p1.code[i]==p2.code[i])&&(p1.code[i]=='1'))
flag=0;
}
if(flag==0)
return(1);
return(2);
}
/*function to find new end points*/
pt resetendpt(pt p1,pt p2)
{
pt temp;
int x,y,i;
float m,k;
if(p1.code[3]=='1')
x=150;
if(p1.code[2]=='1')
x=450;
if((p1.code[3]=='1')||(p1.code[2]=='1'))
{
m=(float)((p2.y-p1.y)/(p2.x-p1.x));
k=(p1.y+(m*(x-p1.x)));
temp.y=k;
temp.x=x;
for(i=0;i<4;i++)
temp.code[i]=p1.code[i];
if(temp.y<=350 && temp.y >=100)
return(temp);
}
if(p1.code[0]=='1') /*cutting top edge*/
y=100;
44
SEC
IT/VII
GM LAB MANUAL
if(p1.code[1]=='1') /*cutting bottom edge*/
y=350
;
if((p1.code[0]=='1')||(p1.code[1]=='1'))
{
m=(float)(p2.y-p1.y)/(p2.x-p1.x);
k=(float)p1.x+(float)(y-p1.y)/m;
temp.x=k;
temp.y=y;
for(i=0;i<4;i++)
temp.code[i]=p1.code[i];
return(temp);
}
else
return(p1);
}
OUTPUT
Enter the staring co ordinate:
130 90
Enter the ending co ordinate:
200 125
Output:
Line before clipping
45
SEC
IT/VII
GM LAB MANUAL
Line after clipping
RESULT:
The program to perform line clipping by Cohen Sutherland algorithm has been executed
and the result is as shown above.
VIVA QUESTION AND ANSWER
1. Define Clipping.
Any procedure that identifies those portions of a picture that are either inside or
outside of a specified region of space is referred to as a clipping algorithm or simply
clipping. The region against which an object is clipped is called a clip window.
1. What are the types of Clipping?
• Point clipping
• Line clipping
• Area clipping
• Curve clipping and
• Text clipping
2. What is exterior clipping?
The picture parts to be saved are those that are outside the region. This is referred
to as exterior clipping.
46
SEC
IT/VII
EX NO: 3 B
GM LAB MANUAL
WINDOW-VIEWPORT MAPPING
DESCRIPTION ABOUT THE EXPERIMENT
•
―Window‖ refers to the area in ―world space‖ or ―world coordinates‖ that you wish to
project onto the screen
•
The area on the screen that you will map the window to
coordinates‖ - (u,v) coordinates
•
The viewport can take up the entire screen, or just a portion of it
Specified in ―screen
Objective
Window: A region of the scene selected for viewing (also called clipping window)
Viewport: A region on display device for mapping to window
Translate lower-left corner of window to origin
Scale width and height of window to match viewport’s
Translate corner at origin to lower-left corner in viewport
Syntaxes & keywords
Void initgraph()::switches to graphics mode.
Settextstyle function is used to change the way in which text appears, using it we can modify the
size of text, change direction of text and change the font of text.
Declaration :- void settextstyle( int font, int direction, int charsize);
outtextxy function display text or string at a specified point(x,y) on the screen.
Declaration :- void outtextxy(int x, int y, char *string);
rectangle function is used to draw a rectangle.
Declaration :- void rectangle(int left, int top, int right, int bottom);
setfillstyle function sets the current fill pattern and fill color.
Declaration :- void setfillstyle( int pattern, int color);
47
SEC
IT/VII
GM LAB MANUAL
Fillpoly function draws and fills a polygon. It require same arguments as drawpoly.
Declaration :- void drawpoly( int num, int *polypoints );
moveto function changes the current position (CP) to (x, y)
Declaration :- void moveto(int x, int y);
lineto function draws a line from current
HOW IT IS BEING ACHIEVED?
A window defines a rectangular area in world coordinates. You define a window with a
GWINDOW statement
A viewport defines in normalized coordinates a rectangular area on the display device
where the image of the data appears.
HOW TO EXECUTE THE SOURCE CODE
REQUIREMENTS FOR EXECUTION
S.No.
Facilities required
Quantity
1
System
1
2
O/S
Windows 98
3
Compiler
Turbo C
EXPECTED OUTPUT AND ITS FORM
The program is to project the world view to view port
ADVANTAGES
Viewport limits—integer device coordinates.
The window is often centered around the origin, but need not be Specified as (x,y) coordinates
48
SEC
IT/VII
GM LAB MANUAL
APPLICATIONS:
Zooming in on a portion of object

Tiling

W-to-V in loop

Multiple adjacent viewports

Flipping drawings

Stereo viewing
ALGORITHM
1. Read the window & view port co-ordinates.
2. Read the number of polygon vertices
3. Draw the filled polygon inside the window.
4. Draw the view port
5. Map the polygon which is in the window to the view port.
6. Display the polygon inside the view port.
SOURCE CODE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int x[10],y[10],pol[25],ny,xymin,xymax,ywmax,ywmin,yymax,yymin,xwmax,xwmin;
void viewport()
{
float sx,sy;
int i,j,k;
49
SEC
IT/VII
GM LAB MANUAL
sx=(float)((float)(xymax-xymin)/(float)(xwmax-xwmin));
sy=(float)((float)(yymax-yymin)/(float)(ywmax-ywmin));
for(i=0;i<3;i++)
{
x[i]=sx*(x[i]-xwmin)+xymin;
y[i]=sy*(y[i]-ywmin)+yymin;
}
k=0;
for(i=0;i<ny;i++)
{
pol[k]=x[i];
pol[k+1]=y[i];
k+=2;
}
}
void main()
{
int i,j,d=DETECT, m=DETECT;
clrscr();
printf("Enter the window co ordinates:");
scanf("%d%d%d%d",&xwmin,&ywmin,&xwmax,&ywmax);
50
SEC
IT/VII
GM LAB MANUAL
printf("Enter the view port co ordinates:");
scanf("%d%d%d%d",&xymin,&yymin,&xymax,&yymax);
printf("Enter the number of vertices");
scanf("%d",&ny);
printf("Enter the %d values",ny*2);
for(i=0;i<ny;i++)
scanf("%d%d",&x[i],&y[i]);
j=0;
for(i=0;i<ny;i++)
{
pol[j]=x[i];
pol[j+1]=y[i];
j+=2;
}
initgraph(&d,&m,"");
settextstyle(3,0,3);
outtextxy(xwmin,ywmin-35,"Window");
rectangle(xwmin,ywmin,xwmax,ywmax);
setfillstyle(8,getmaxcolor());
fillpoly(ny,pol);
moveto(x[0],y[0]);
51
SEC
IT/VII
GM LAB MANUAL
lineto(x[0],y[0]);
getch();
viewport();
outtextxy(xymin,yymin-35,"Viewport");
rectangle(xymin,yymin,xymax,yymax);
setfillstyle(8,getmaxcolor());
fillpoly(ny,pol);
moveto(x[0],y[0]);
lineto(x[0],y[0]);
getch();
closegraph();
}
OUTPUT
Input:
Enter the window co ordinates: 120 50 350 140
Enter the view port co ordinates: 400 150 500 170
Enter the number of vertices
3
Enter the 6 values: 250 80 200 100 300 100
Output:
WINDOW
52
SEC
IT/VII
GM LAB MANUAL
VIEWPORT
RESULT:
The program to perform window – view port mapping has been executed and the result is
as shown above.
VIVA QUESTIONS:
1. What is viewport?
A world coordinate area selected for display is called a window. An area on a
display device to which a window is mapped is called a viewport.
2. Define Window.
A world-coordinate area selected for display is called a window.
3. What is oblique projection?
An oblique projection is obtained by projecting points along parallel lines that are
not perpendicular to the projection plane.
53
SEC
IT/VII
GM LAB MANUAL
4. What is viewing transformation?
The mapping of a part of a world-coordinate scene to device coordinates is
referred to as viewing transformation.
5. What is projection?
The process of displaying 3D objects on a 2D display is called as Projection
6. What are the types of projection?
• Perspective projection
• Parallel projection
7. What is parallel projection?
In a parallel projection, coordinate positions are transformed to the view plane
along parallel lines.
8. What is Perspective projection?
For a perspective projection object positions are transformed to the view plane
along lines that converge to a point called the projection reference point.
POSSIBLE SET QUESTIONS:
1. Implementation of Cohen-Sutherland line clipping.
2. Write a program to implement window-viewport mapping.
3. Implementation of line clipping algorithm.
54
SEC
EX NO: 4
IT/VII
GM LAB MANUAL
TO PERFORM 3D TRANSFORMATIONS SUCH AS TRANSLATION,
ROTATION AND SCALING.
DESCRIPTION ABOUT THE EXPERIMENT:
3DTransformaions are a fundamental part of computer graphics. Transformations
are used to position objects, to shape objects, to change viewing positions, and even to change
how something is viewed.
Syntaxes & keywords:
void initgraph()::switches to graphics mode.
Settextstyle function is used to change the way in which text appears, using it we can modify the
size of text, change direction of text and change the font of text.
Declaration :- void settextstyle( int font, int direction, int charsize);
outtextxy function display text or string at a specified point(x,y) on the screen.
Declaration :- void outtextxy(int x, int y, char *string);
rectangle function is used to draw a rectangle.
Declaration :- void rectangle(int left, int top, int right, int bottom);
setfillstyle function sets the current fill pattern and fill color.
Declaration :- void setfillstyle( int pattern, int color);
Fillpoly function draws and fills a polygon. It require same arguments as drawpoly.
Declaration :- void drawpoly( int num, int *polypoints );
moveto function changes the current position (CP) to (x, y)
55
SEC
IT/VII
GM LAB MANUAL
Declaration :- void moveto(int x, int y);
lineto function draws a line from current
HOW TO EXECUTE THE SOURCE CODE
REQUIREMENTS FOR EXECUTION
S.No.
Facilities required
Quantity
1
System
1
2
O/S
Windows 98
3
Compiler
Turbo C
EXPECTED OUTPUT AND ITS FORM
This program is used to perform the 3D transformation by rotation, translation,
reflection, shearing
ALGORITHM
Step 1 : Start.
Step 2 : Draw an image with default parameters.
Step 3 : Get the choice from user.
Step 4 : Get the parameters for transformation.
Step 5 : Perform the transformation.
Step 6 : Display the output.
Step 7 : Stop
SOURCE CODE
#include<stdio.h>
#include<conio.h>
56
SEC
IT/VII
GM LAB MANUAL
#include<graphics.h>
#include<math.h>
void main()
{
int n,poly[20],poly1[20],poly2[10],sx,poly3[10];
int tx,ty,xr,yr,a,sy,poly4[10],poly5[10],poly6[10],poly7[10];
int i;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
//STEP TO DRAW A POLYGAN
printf("\nEnter the number of vertices of the polygan.....\n");
scanf("%d",&n);
printf("\nEnter the X,Y co-ordinates of each vertex....\n");
for(i=0;i<2*n;i++)
{
scanf("%d",&poly[i]);
poly[i]=(poly[i])+40;
poly[i+1]=(poly[i+1])+40;
poly1[i]=(poly[i]+50)+40;
poly1[i+1]=(poly[i+1]+50)+40;
}
poly[2*n]=poly[0];
poly[2*n+1]=poly[1];
poly1[2*n]=poly1[0];
poly1[2*n+1]=poly1[1];
outtextxy(70,70,"ORIGINAL IMAGE");
drawpoly(n+1,poly);
drawpoly(n+1,poly1);
for(i=0;i<2*n;i+=2)
line(poly[i],poly[i+1],poly1[i],poly1[i+1]);
57
SEC
IT/VII
GM LAB MANUAL
getch();
cleardevice();
//TRANSLATION
outtextxy(30,30,"ORIGINAL IMAGE");
drawpoly(n+1,poly);
drawpoly(n+1,poly1);
for(i=0;i<2*n;i+=2)
line(poly[i],poly[i+1],poly1[i],poly1[i+1]);
getch();
outtextxy(10,10,"Enter the Translation factor:");
gotoxy(30,3);
scanf("%d%d",&tx,&ty);
for(i=0;i<2*n;i+=2)
{
poly2[i]=poly[i]+tx;
poly2[i+1]=poly[i+1]+ty;
poly3[i]=poly1[i]+tx;
poly3[i+1]=poly1[i+1]+ty;
}
poly2[2*n]=poly2[0];
poly2[2*n+1]=poly2[1];
poly3[2*n]=poly3[0];
poly3[2*n+1]=poly3[1];
drawpoly(n+1,poly2);
drawpoly(n+1,poly3);
for(i=0;i<2*n;i+=2)
line(poly2[i],poly2[i+1],poly3[i],poly3[i+1]);
getch();
cleardevice();
//SCALING
58
SEC
IT/VII
GM LAB MANUAL
printf("\n\n\t original image!");
drawpoly(n+1,poly);
drawpoly(n+1,poly1);
gotoxy(300,100);
for(i=0;i<2*n;i+=2)
line(poly[i],poly[i+1],poly1[i],poly1[i+1]);
getch();
outtextxy(10,10,"Enter the scaling factor:");
gotoxy(30,3);
scanf("%d",&sx);
for(i=0;i<2*n;i+=2)
{
poly4[i]=poly[i]*sx;
poly4[i+1]=poly[i+1]*sx;
poly5[i]=poly1[i]*sx;
poly5[i+1]=poly1[i+1]*sx;
}
poly4[2*n]=poly4[0];
poly4[2*n+1]=poly4[1];
poly5[2*n]=poly5[0];
poly5[2*n+1]=poly5[1];
drawpoly(n+1,poly4);
drawpoly(n+1,poly5);
for(i=0;i<2*n;i+=2)
line(poly4[i],poly4[i+1],poly5[i],poly5[i+1]);
getch();
cleardevice();
//ROTATION
printf("\n\n\t original image!");
drawpoly(n+1,poly);
59
SEC
IT/VII
GM LAB MANUAL
drawpoly(n+1,poly1);
for(i=0;i<2*n;i+=2)
line(poly[i],poly[i+1],poly1[i],poly1[i+1]);
getch();
outtextxy(10,10,"Enter the rotation factor");
gotoxy(30,3);
scanf("%d%d%d",&xr,&yr,&a);
for(i=0;i<2*n;i+=2)
{
poly6[i]=xr+((poly[i]-xr)*cos(a))-((poly[i+1]-yr)*sin(a))+70;
poly6[i+1]=yr+((poly[i+1]-yr)*cos(a))+((poly[i]-xr)*sin(a))+70;
poly7[i]=xr+((poly[i]-xr)*cos(a))-((poly1[i+1]-yr)*sin(a))+70;
poly7[i+1]=yr+((poly[i+1]-yr)*cos(a))+((poly1[i]-xr)*sin(a))+70;
}
poly6[2*n]=poly6[0];
poly6[2*n+1]=poly6[1];
poly7[2*n]=poly7[0];
poly7[2*n+1]=poly7[1];
drawpoly(n+1,poly6);
drawpoly(n+1,poly7);
for(i=0;i<2*n;i+=2)
line(poly6[i],poly6[i+1],poly7[i],poly7[i+1]);
getch();
cleardevice();
}
OUTPUT
Enter the number of vertices of the polygon:
4
Enter the(x,y) co-ordinates of the vertices:
100 100 150 100 150 150 100 150
60
SEC
IT/VII
GM LAB MANUAL
Output
Original image
Translation
Input:
Enter the Translation Factor
200 200
Output
Original image
Scaling
Input:
Enter the scaling Factor
2
Output
Original image
61
SEC
IT/VII
GM LAB MANUAL
Rotation
Input: Enter the Reflection Factor:
250 250
60
Output
Original image
RESULT
The program for 3D transformations has been executed and the result is as shown above.
VIVA QUESTIONS
1. Categorize the 3D representations?
Boundary representation (B-reps) and space-partitioning representations.
62
SEC
IT/VII
GM LAB MANUAL
2. What Boundary representation?
It describes a 3D object as a set of surfaces that separate the object interior from
the environment. e.g. polygon facets and spline patches.
3. What space-partitioning representation?
This is used to describe interior properties, by partitioning the spatial region
containing an object in to a set of small, non-overlapping, contiguous solids. e.g.octree.
4. Write the rotation procedure in 3D.
i) Translate the object so that the rotation axis coincides with the parallel
coordinate axis.
ii) Perform the specified rotation about the axis
iii) Translate the object so that the rotation axis is moved back to its original
position.
POSSIBLE SET QUESTIONS:
1. Implementation of Basic 3D Transformations.
2. Write a program to perform scaling and rotation using three dimensions.
3. Three Dimensional Transformation Using C programming.
4. Write a Program to implement set of Basic Transformations on Polygon i.e. Translation,Rotation
and Scaling.
63
SEC
IT/VII
EX NO: 5
GM LAB MANUAL
TO VISUALIZE PROJECTIONS OF 3D IMAGES
DESCRIPTION ABOUT THE EXPERIMENT:
3D projection is of mapping three-dimensional points to a two-dimensional plane. 3D
Mapping is the projection of media on to a surface such that the viewer perceives objects in
motion and space - which appear to be real - in three dimensions relative to the surface.
Objective:
The main Objective is to project the 3D image using the parallel line projection.
How it is being achieved?
It can be achieved by viewing the front, side and top elevation of the 3D image by projecting the
3D image using the parallel line projection.
Syntaxes & keywords commands for achieving the objective
void initgraph();
void bar3d(int left, int top, int right, int bottom, int depth, int topflag);
void line(int x1, int y1, int x2, int y2);
void rectangle(int left, int top, int right, int bottom);
void outtext(char *string);
void moveto(int x, int y);
void closegraph();
Description about the parts of the program with description about the language constructs
used for the same.
C graphics using graphics.h functions or WinBGIM (Windows 7 ) can be used to draw different
shapes, display text in different fonts, change colors and many more. Using functions of
graphics.h in turbo c compiler you can make graphics programs, animations, projects and games.
64
SEC
IT/VII
GM LAB MANUAL
initgraph function in c
A function in Borland's graphics library in TurboC; switches to graphics mode.
Declaration :- void initgraph();
bar3d function in c
Declaration :- void bar3d(int left, int top, int right, int bottom, int depth, int topflag);
bar3d function is used to draw a 2-dimensional, rectangular filled in bar
line function in c
line function is used to draw a line from a point(x1,y1) to point(x2,y2)
Declaration :- void line(int x1, int y1, int x2, int y2);
rectangle function in c
Declaration :- void rectangle(int left, int top, int right, int bottom);
rectangle function is used to draw a rectangle.
outtext function
outtext function displays text at current position.
Declaration :- void outtext(char *string);
moveto function in c
moveto function changes the current position (CP) to (x, y)
Declaration :- void moveto(int x, int y);
closegraph function in c
closegraph function closes the graphics mode, deallocates all memory allocated by graphics
system and restores the screen to the mode it was in before you called initgraph.
Declaration :- void closegraph();
65
SEC
IT/VII
GM LAB MANUAL
HOW TO EXECUTE THE PROGRAM
C program executes in following 4 (four steps).
REQUIREMENTS FOR EXECUTION :
S.No.
Facilities required
Quantity
1
System
1
2
O/S
Windows 98
3
Compiler
Turbo C
EXPECTED OUTPUT AND ITS FORM :
The bar3D can be viewed in top, front and side elevation aspects.
USE OF THIS OUTPUT :
Presenting a bar3d in top, front and side elevation manner.
ADVANTAGES AND LIMITATIONS:

Greater Reality

Greater Attention

Greater Productivity
APPLICATIONS:
The way 3D has impacted the world of cinema is clear, but there are other applications where 3D
breaks new boundaries.
EDUCATION:
Applications include Biology, Physics, Chemistry, Anatomy, Geography, Mathematics,
Engineering,
Architecture
and
the
Arts.
ENGINEERING
66
SEC
IT/VII
GM LAB MANUAL
3D is an excellent medium to make more representational models, visuals or movies in Design,
Engineering, CAD/CAM and Simulation applications
BLUE-RAY 3D STANDARD AND CONSUMER TV’S / PROJECTORS :
All major consumer electronic brands have announced big plans for 3D TV and projector
models. 3D consumer televisions and projectors are already broadly available.3D Blue-ray
players are becoming common place now with more and more 3D Blue-ray DVD titles being
shipped.
ALGORITHM
1. Draw the 3D bar using the inbuilt function bar3d.
2. Draw the front, side & top elevation of the 3D image by projecting the 3D image using
the parallel line projection.
3. Display the 3D image along with the front, side & top view.
PROGRAM
#include<graphics.h>
void top()
{
moveto(100,200);
outtext("TOP VIEW");
line(400,200,440,150);
line(400,200,300,150);
line(300,150,340,100);
line(340,100,440,150);
}
void side()
{
67
SEC
IT/VII
GM LAB MANUAL
moveto(100,200);
outtext("SIDE VIEW");
rectangle(500,100,600,200);
}
void front(int wid)
{
moveto(100,200);
outtext("FRONT VIEW");
rectangle(400,250,400+wid,350);
rectangle(300,250,400,350);
}
void main()
{
int x =DETECT,y,i,mx,my,wid=40;
initgraph(&x,&y,"");
mx=100;
my=100;
setfillstyle(USER_FILL,3);
moveto(100,250);
outtext("3D IMAGE");
bar3d(mx,my,mx+100,my+100,wid,1);
getch();
cleardevice();
top();
getch();
cleardevice();
side();
getch();
cleardevice();
front(wid);
getch();
68
SEC
IT/VII
GM LAB MANUAL
cleardevice();
bar3d(mx,my,mx+100,my+100,wid,1);
line(400,200,440,150);
line(400,200,300,150);
line(300,150,340,100);
line(340,100,440,150);
rectangle(500,100,600,200);
rectangle(400,250,400+wid,350);
rectangle(300,250,400,350);
getch();
closegraph();
}
OUTPUT
RESULT:
The program to visualize the projection of 3D images has been executed and the result is as
shown above.
69
SEC
IT/VII
GM LAB MANUAL
VIVA QUESTIONS:
1. Define projection?
The process of converting the objects from world coordinates to viewing coordinates is
known as projection
2. What you mean by parallel projection?
Parallel projection is one in which z coordinates is discarded and parallel lines from each
vertex on the object are extended until they intersect the view plane.
3. What do you mean by Perspective projection?
Perspective projection is one in which the lines of projection are not parallel. Instead, they all
converge at a single point.
POSSIBLE SET QUESTIONS:
1. Draw and project three dimensional objects.
2. Write a program to perform parallel projection on three dimensional objects.
70
SEC
EX NO: 6
IT/VII
GM LAB MANUAL
CONVERSION BETWEEN COLOR MODELS
DESCRIPTION ABOUT THE EXPERIMENT:
The purpose of a color model is to facilitate the specification of colors in some standard
generally accepted way. Color model is a method for explaining the properties or behavior of the
color within some context. In the RGB model, each color appears as a combination of red, green,
and blue. This model is called additive, and the colors are called primary colors. The primary
colors can be added to produce the secondary colors of light. In HSV hue represents color. In this
model, hue is an angle from 0 degrees to 360 degrees. Saturation indicates the range of grey in
the color space. It ranges from 0 to 100%. Value is the brightness of the color and varies with
color saturation. It ranges from 0 to 100%.
Objective:
The main Objective is to convert HSV color model to RGB color model and vice versa.
How it is being achieved?
The Objective can be achieved by transformed the parameters of HSV to the RGB settings
needed for the color monitor. Transformation from HSV parameters to RGB parameters by
determining the inverse of the equations in rgbToHsv procedure.
Syntaxes & keywords commands for achieving the objective
void hsvtorgb(float h,float s,float v,float *r,float *g,float *b)
void rgbtohsv(float r,float g,float b,float *h,float *s,float *v)
void hsvtorgb(float h,float s,float v,float *r,float *g,float *b)
Description about the parts of the program with description about the language constructs
used for the same.
Here passing pointers to (addresses of) r, g, and b - and the function is returning the r,g,b values.
hue in degrees (360.0)
saturation in percent (0.0 - 1.0)
value/brightness in percent (0.0-1.0)
71
SEC
IT/VII
GM LAB MANUAL
void rgbtohsv(float r,float g,float b,float *h,float *s,float *v)
Here passing pointers to (addresses of) h, s, and v - and the function is returning the h,s,v values.
HOW TO EXECUTE THE PROGRAM
C program executes in following 4 (four steps).
REQUIREMENTS FOR EXECUTION :
S.No.
Facilities required
Quantity
1
System
1
2
O/S
Windows 98
3
Compiler
Turbo C
EXPECTED OUTPUT AND ITS FORM :
This program converts one color model to another color i.e, RGB to HSV effectively.
USE OF THIS OUTPUT :

RGB (Red, Green, Blue) - uses the principle of emitted color

HSV (Hue, Saturation, Value) - uses the principle of reflected color.
ADVANTAGES AND LIMITATIONS:
The HSV color space is quite similar to the way in which humans perceive color. The other
models, except for HSL, define color in relation to the primary colors.
The colors used in HSV can be clearly defined by human perception, which is not always the
case with RGB or CMYK.
APPLICATIONS:
RGB is a convenient color model for computer graphics because the human visual system works
in a way that is similar — though not quite identical — to an RGB color space.
72
SEC
IT/VII
GM LAB MANUAL
The most commonly used RGB color spaces are RGB and Adobe RGB (which has a
significantly larger gamut).
Adobe has recently developed another color space called Adobe Wide Gamut RGB, which is
even larger, in detriment to gamut density.
The HSV color space is widely used to generate high quality computer graphics. In simple terms,
it is used to select various different colors needed for a particular picture.
An HSV color wheel is used to select the desired color. A user can select the particular color
needed for the picture from the color wheel. It gives the color according to human perception.
ALGORITHM
HSV to RGB
1. Read the H, S, V values in the range 0 to 1.
2. If the value of s is 0 then it is gray scale and the R, G, B becomes the value of
V.
3. If the value of h is 1.0 then assign h=0 else h=h*6.0 and perform the following
i= floor(h);
aa=v*(1-s);
f=h-i;
bb=v*(1-s*f); cc=v*(1-s*(1f)));
4. Based on the i value assign v, aa, bb ,cc to RGB and display the RGB values.
RGB to HSV
1. Read the R, G, B values.
2.
Find the min,max value among the RGB values
3. Assign the maximum value to V.
4. S value is calculated by (max-min)/max.
5. H value is calculated by comparing R, G, and B values to max value.
6. Display the H, S and V values.
73
SEC
IT/VII
GM LAB MANUAL
SOURCE CODE
To convert HSV TO RGB
#include<stdio.h>
#include<math.h>
#include<conio.h>
void hsvtorgb(float h,float s,float v,float *r,float *g,float *b)
{
int i;
float aa,bb,cc,f;
if(s==0)
*r=*g=*b=v;
else
{
if(h==1.0) h=0;
h*=6.0;
i=floor(h);
f=h-i;
aa=v*(1-s);
bb=v*(1-(s*f));
cc=v*(1-(s*(1-f)));
switch(i)
{
case 0: *r=v; *g=cc; *b=aa; break;
case 1: *r=bb; *g=v; *b=aa; break;
74
SEC
IT/VII
GM LAB MANUAL
case 2: *r=aa; *g=v; *b=cc; break;
case 3: *r=aa; *g=bb; *b=v; break;
case 4: *r=cc; *g=aa; *b=v; break;
case 5: *r=v; *g=aa; *b=bb; break;
}
}
}
void main()
{
float h,s,v,r=0,g=0,b=0;
clrscr();
printf("Enter the H,S,V values:\n");
scanf("%f%f%f",&h,&s,&v);
hsvtorgb(h,s,v,&r,&g,&b);
printf("The R,G,B values:\n%f %f %f\n",r,g,b);
getch();
}
INPUT:
Enter the H, S, V values: 0.1 0.2 0.3
OUTPUT
The R, G, B values:
0.300000
0.276000
0.240000
Program 2: //To Convert RGB to HSV
#include<math.h>
75
SEC
IT/VII
GM LAB MANUAL
#include<stdio.h>
#include<conio.h>
#define MAX(a,b)(a>b?a:b)
#define MIN(a,b)(a<b?a:b)
void rgbtohsv(float r,float g,float b,float *h,float *s,float *v)
{
float max = MAX(r,MAX(g,b));
float min = MIN(r,MIN(g,b));
float delta=max-min;
*v=max;
if(max!=0.0)
{
*s=delta/max;
if(r==max)
*h=(g-b)/delta;
else if(g==max)
*h=2+(b-r)/delta;
else if(b==max)
*h=4+(b-r)/delta;
*h*=60.0;
if(*h<0)
*h+=360.0;
*h/=360.0;
}
}
76
SEC
IT/VII
GM LAB MANUAL
void main()
{
float r,g,b,h=0,s=0,v=0;
clrscr();
printf("Enter the value of R,G,B\n:");
scanf("%f%f%f",&r,&g,&b);
rgbtohsv(r,g,b,&h,&s,&v);
printf("H=%f , S=%f ,V=%f",h,s,v);
getch();
}
INPUT:
Enter the R, G, B values:
0.3
0.276
0.24
OUTPUT:
The H, S, V values:
0.100000
0.200000
0.300000
RESULT:
Thus the program to convert HSV color to RGB color models and vice versa was executed
successfully and verified.
VIVA QUESTIONS:
1. Define Color model.
A Color model is a method for explaining the properties or behavior of color
within some particular context.
2. What is HSV model?
The HSV (Hue,Saturation,Value) model is a color model which uses color
77
SEC
IT/VII
GM LAB MANUAL
that have a more intuitive appeal to a user. To give a color specification, a user selects a spectral
color and the amounts of white and black that are to be added to obtain different shades, tint, and
tones.
3. What for CMY color model used?
A color model defined with the primary colors cyan, magenta, and yellow is
useful for describing color output to hard-copy devices.
4. What are the parameters in the HLS color model?
Hue, Lightness and Saturation.
POSSIBLE SET QUESTIONS:
1. Implementation of different color models and their conversion.
2. Write a program to Convert RGB color model to HSV color model.
78
SEC
IT/VII
GM LAB MANUAL
TO IMPLEMENT TEXT COMPRESSION ALGORITHM
EX NO: 7
DESCRIPTION ABOUT THE EXPERIMENT:
Run Length Encoding (RLE) is a simple and popular data compression algorithm. It is based on
the idea to replace a long sequence of the same symbol by a shorter sequence and is a good
introduction into the data compression field. For instance, text files with large runs of spaces or
tabs may compress well with this algorithm.
Objective:
The main Objective is to compress the data without any loss using text compression algorithm.
How it is being achieved?
It can be achieved by replace a long sequence of the same symbol by a shorter sequence of a
symbol.
Description about the parts of the program with description about the language constructs
used for the same.
gets(str); used to get the string from the user.
HOW TO EXECUTE THE PROGRAM
C program executes in following 4 (four steps).
REQUIREMENTS FOR EXECUTION :
S.No.
Facilities required
Quantity
1
System
1
2
O/S
Windows 98
3
Compiler
Turbo C
79
SEC
IT/VII
GM LAB MANUAL
EXPECTED OUTPUT AND ITS FORM :
This program compress the string using lossless data compression
USE OF THIS OUTPUT :
It effectively compress the string.
ADVANTAGES AND LIMITATIONS:
This scheme does not span across multiple of scanlines and it is one dimensional scheme.
In a busy image adjacent pixels or group of adjacent pixels change rapidly and these leads to
shorter run lengths of back pixels o white pixels , so it take more bits for the code to represent
the length.
APPLICATIONS:
Run-length encoding performs lossless data compression and is well suited to palette-based
iconic images. It does not work well at all on continuous-tone images such as photographs,
although JPEG uses it quite effectively on the coefficients that remain after transforming and
quantizing image blocks.
Run-length encoding is used in fax machines (combined with other techniques into Modified
Huffman coding). It is relatively efficient because most faxed documents are mostly white space,
with occasional interruptions of black.
ALGORITHM
1. Read the message.
2. Check the first character with the next character.
3. If it is same, then increment the count and check the next character.
4. Repeat the step 2 & 3 till reads the null character.
5. Display the encoded message
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
80
SEC
IT/VII
GM LAB MANUAL
void main()
{
int i,t=1;
char str[15],c;
clrscr();
printf("Enter the string");
gets(str);
for(i=0;str[i]!=NULL;i++)
{
c=str[i];
if(str[i]==str[i+1])
{
t+=1;
continue;
}
else
{
printf("%c%d\n",c,t);
t=1;
}
}
getch();
}
81
SEC
IT/VII
GM LAB MANUAL
OUTPUT
Enter the string apple
a1
p2
l1
e1
RESULT:
Thus the program to implement text compression was executed successfully and verified.
VIVA QUESTIONS:
1. Say some loss less compression standards?
Pack bits encoding, CCITT Group3 1D, CCITT Group3 2D, CCITT
Group4,Lembel-Ziv and Welch algorithm LZW.
2. Say some lossy compression standards?
JPEG(Joint photographic Experts Group),MPEG(Moving Picture Experts
Group),Intel DVI,CCITT H.261 video coding algorithm, Fractals.
3. What are the advantages of CCITT Group 3 1D?
•
It is simple to implement in both h/w and s/w.
•
It is a world wide standard for facsimile, which is accepted for document
imaging application. This allows document-imaging applications to incorporate fax
documents easily.
4. What is the disadvantage of CCITT Group 3 2D Scheme?
It is complex and relatively difficult to implement in software.
POSSIBLE SET QUESTIONS:
1. Write a program to perform run length encoding and decoding
2.Write a program to perform string compression
82
SEC
IT/VII
GM LAB MANUAL
EX NO: 8
IMAGE COMPRESSION
DESCRIPTION ABOUT THE EXPERIMENT:
The basic idea behind this method of compression is to treat a digital image as an array of
numbers i.e., a matrix. Each image consists of a fairly large number of little squares called
pixels.
Objective:
The main Objective is to reduce irrelevance and redundancy of the image data in order to be able
to store or transmit data in an efficient form.
How it is being achieved?
It can be achieved by using image compression techniques.
Syntaxes & keywords commands for achieving the objective
import java.util.zip.*;
FileInputStream()
DeflaterOutputStream
Description about the parts of the program with description about the language constructs
used for the same.
import java.util.zip.*; - Provides classes for reading and writing the standard ZIP and GZIP file
formats.
FileInputStream() - FileInputStream is meant for reading streams of raw bytes such as image
data. For reading streams of characters, consider using FileReader.
DeflaterOutputStream - This class implements an output stream filter for compressing data in the
"deflate" compression format.
83
SEC
IT/VII
GM LAB MANUAL
HOW TO EXECUTE THE PROGRAM:
Running a Java Program from Command Prompt

Create a temporary folder C:\mywork. Using Notepad or another text editorSave your
file as HelloWorld.java in C:\mywork.


To make sure your file name is file name.java,
Run Command Prompt (found under All Programs/Accessories in the Start menu). Type
C:\> cd \mywork
This makes C:\mywork the current directory.
C:\mywork> dir
This displays the directory contents. You should see file name.java among the files.
C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin
This tells the system where to find JDK programs.
C:\mywork> javac file name.java
This runs javac.exe, the compiler. You should see nothing but the next system prompt...
C:\mywork> dir
javac has created the file name.class file. You should see file name.java and file
name.class among the files.
C:\mywork> java file name
This runs the Java interpreter. It will show the program output
84
SEC
IT/VII
GM LAB MANUAL
REQUIREMENTS FOR EXECUTION :
S.No.
Facilities required
Quantity
1
System
1
2
O/S
Windows 98
3
S/W Package
Jdk 1.5
EXPECTED OUTPUT AND ITS FORM :
This program gives the compressed image using image compression techniques
ADVANTAGES:
Efficient utilization of time,
Memory and
Bandwidth
APPLICATIONS:
Image compression not only helps in saving storage space but also enables easy sharing of files.
Image compression applications reduce the size of an image file without causing major
degradation to the quality of the image.
ALGORITHM
1. File input stream class is used to access the input file
2. Read the content of the image file and assign to a variable
3. write the value to an object
4. Repeat the step 3 until end of file.
5. Print the size of the compressed image .
SOURCE CODE
import java.io.*;
import java.net.*;
import java.util.zip.*;
85
SEC
IT/VII
GM LAB MANUAL
class dzip
{
public static void main(String args[])throws Exception
{
FileInputStream Fin=new FileInputStream("Sample.jpg");
DeflaterOutputStream dout=new DeflaterOutputStream(new
FileOutputStream("Sample.zip"));
int b;
while ((b=Fin.read())!=-1)
dout.write(b);
Fin.close();
dout.close();
File f1=new File("Sample.jpg");
File f2=new File("Sample.zip");
System.out.println("Before:"+f1.length());
System.out.println("After:"+f2.length());
}
}
86
SEC
IT/VII
GM LAB MANUAL
OUTPUT
E:\jdk1.5.0\bin>javac dzip.java
E:\jdk1.5.0\bin>java dzip
Before: 9894
After: 9887
RESULT:
The program for image compression has been executed and the result is as shown above.
VIVA QUESTIONS:
1. What are complex image enhancement capabilities?
Image calibration, Real-time alignment, Gray-scale normalization, RGB hue
intensity adjustment, Color separation, Frame averaging.
2. What is hypermedia documents?
In hypermedia documents in addition to text, embedded or linked multimedia
objects such as image, audio, hologram, or full -motion video.
3. What are the types of images based on multimedia?
Visible images, non-visible images, abstract images.
4. What does non-visible images refer?
Non-visible images are those that are not stored as images but are displayed as
images e.g. pressure gauges, temperature gauges
POSSIBLE SET QUESTIONS:
1. Write a program to perform image compression using java.
2. Implementation of Image compression techniques
87
SEC
IT/VII
EX NO: 9
GM LAB MANUAL
TO PERFORM ANIMATION USING ANY ANIMATION SOFTWARE.
DESCRIPTION ABOUT THE EXPERIMENT:
Animation is any thing that moves on your screen like a cartoon character.
Time sequence of visual images on a scene
How it is being achieved?
It can be achieved by using animation software like swiss, flash
ADVANTAGES AND LIMITATIONS:
Advantages:
Skill and ability Improvement
Animation can be used to visualize a dynamic phenomenon or process which cannot be
readily seen by the eye or science setting (e.g. meiosis
Flexibility :animations are ideal for many applications.
Limitations:
The main flexible issue of the animation is to show the non-possible matters in the reallife learning.
APPLICATIONS:
2D Animation
3D Animation
Gaming
ALGORITHM
MOTION TWEENING
Step 1: Create an object in the first layer of first key frame.
Step 2: Create the last key frame and move the object to it.
Step 3: Right click on the first key frame and select create motion tween.
Step 4: Play the picture.
SHAPE TWEENING
88
SEC
IT/VII
GM LAB MANUAL
Step 1: Create an object in the first layer of first key frame.
Step 2: Create the last key frame.
Step 3: In first key frame’s properties and select shape tween.
Step 4: Change the shape of the object at the last frame.
Step 5: Play the picture.
GUIDE LAYER
Step 1: Create an object in the first layer of first key frame.
Step 2: Create the last key frame and move the object to it.
Step 3: Right click on the first key frame and select create motion tween.
Step 4: Right click on the object’s layer select add motion guide.
Step 5: In motion guide draw your guide line.
Step 6: Play the picture.
MASKING
Step 1: Create an object in the first layer of first key frame
Step 2: Add new layer and draw the shape of the view.
Step 3: Add the motion guide to the view tool.
Step 4: Right click on the second layer (view layer) and select mask.
Step 5: Play the picture.
OUTPUT
SHAPE TWEENING
89
SEC
IT/VII
GM LAB MANUAL
MOTION TWEENING:
GUIDE LAYER
90
SEC
IT/VII
GM LAB MANUAL
MASKING
RESULT:
The animation was done using flash and the the result is as shown above.
VIVA QUESTIONS
1. Define Computer animation.
Computer animation refers to any time sequence of visual changes in a scene. In
addition to changing object position with translations or rotations, a computer generated
animation could display time variations in object size, color, transparency, or surface
texture.
2. What are the steps in animation sequence?
• Story board layout
• Object definition
• Key-frame specifications
91
SEC
IT/VII
GM LAB MANUAL
3. How frame-by-frame animation works?
Here each frame of the scene is separately generated and stored. Later the frames
can be recorded on film or they can be consecutively displayed in \"real-time playback\"
mode.
4. What is morphing?
Transformation of object shapes from one form to another is called morphing.
5. What are the methods of motion specifications?
• Direct motion specification
• Goal-directed Systems
• Kinematics and Dynamics.
POSSIBLE SET QUESTIONS:
1. Write a program to perform Frame By Frame Animation Using Flash
2. Write a program to perform Motion Tweening Using Flash
3. Write a program to perform Shape Tweening Using Flash
92
SEC
IT/VII
GM LAB MANUAL
TO PERFORM BASIC OPERATIONS ON IMAGE USING ANY
EX NO: 10
IMAGE EDITING SOFTWARE
DESCRIPTION ABOUT THE EXPERIMENT:
Adobe Photoshop is a graphics editing program developed and published by Adobe Systems.
Photoshop is a tool that helps design sequences for videos and films by removing the guesswork
for film and video professionals.
Objective:
The main Objective is to use various image painting tools in Photoshop.
How it is being achieved?
It can be achieved by using image editing software (Photoshop)
ADVANTAGES AND LIMITATIONS:
Advantages:
Photoshop is wonderful. The advantages can range anywhere from helping someone improve the
quality of a photograph, The more you learn how to use photoshop, the more it can improve your
skills.
Disadvantages:
There are a lot of different tools that do very different things, so it takes time and patience in
order to learn how to use each one correctly. Photoshop also takes up a large amount of room on
your computer,
APPLICATIONS:
To color correct your digital images, prepare them for printing or web, design web pages, slice
pages (make hyperlinks), , work with video, 3D content (Extended version),also make brand new
images painting or drawing them with drawing tools, also in Photoshop one can make real and
unreal compositions using masking tools and many, many other things.
93
SEC
IT/VII
GM LAB MANUAL
PROCEDURE:
The Brush Popup Palette
Allow quick, convenient access to a range of standard, preset brushes.
The Brushes Palette
Provides access to a wide variety of options for controlling the appearance and
characteristics of brush.
The Pencil Tool
Used to draw free form lines. These draws with the foreground color.
The Gradient Tool
Used to color pixels with the foreground color based on tolerance setting.
The Paint Bucket Tool
Used to color pixels with the foreground color on the tolerance setting.
Cropping An Image
Digital editors are used to crop images. Cropping creates a new image by selecting a
desired rectangular portion from the image being cropped. The unwanted part of the image is
discarded. Image cropping does not reduce the resolution of the area cropped. A primary reason
for cropping is to improve the image composition in the new image.
Removal Of Unwanted Elements
Most image editors can be used to remove unwanted branches, etc., using a "clone" tool.
Image Orientation
Image orientation (from left to right): original, -30° CCW rotation, and flipped.
Sharpening And Softening Images
Graphics programs can be used to both sharpen and blur images in a number of ways,
such as unsharp masking or deconvolution.
94
SEC
IT/VII
GM LAB MANUAL
Editing
Open your project file and create a duplicate.
Crop the image using crop tool.
Change the image size using canvas technique.
Back Ground Changing
Select the area to change the back ground using magic wand tool.
Select the back ground image for your image.
Move the shape of the back ground using marquee tool.
Using selection tool, move the back ground.
Changing Color
Select the area using Lasso tool .
Go to image tab and adjustments and select the Hue / saturation option.
Change the color using RGB mode.
OUTPUT
95
SEC
IT/VII
GM LAB MANUAL
Cropping
Uncropped image from camera
Lily cropped from larger image
Removal of unwanted elements
Image orientation
Contrast change and brightening
96
SEC
IT/VII
GM LAB MANUAL
Color adjustments
RESULT:
The image editing was done using Photoshop and the result is as shown above
VIVA QUESTIONS:
1. What is a clone tools?
The clone tool, as it is known in Adobe Photoshop, GIMP, and Corel PhotoPaint, is used
in digital image editing to replace information for one part of a picture with information
from another part.
2. What is a heal tool?
The Healing Brush Tool also does an excellent job of matching together all of the
relevant shades and textures to keep your fixes as seamless as possible. This tool is far
more effective than slaving away with the Clone Stamp Tool as it will take a lot of the
effort out of accurate blending, however it still requires you to be responsive with your
Alt-key selection
3. How to we crop a image using Photoshop?
Cropping an image allows to cut any portion of the image that the user dint like or mak
an image smaller.
97
SEC
IT/VII
GM LAB MANUAL
CHAPTER 6
EXPERIMENTS BEYOND THE SYLLABUS
HUFFMAN ENCODING
EX NO: 1
AIM:
To write the program to perform HUFFMAN coding.
ALGORITHM:
1. Read the string to compress.
2. Find the length of the string.
3. Create the linked list and find the number of occurrences of each character and add
it to the linked list.
4. Arrange the alphabet with the maximum occurrences.
5. Encode the string using:
If the first character of string match with alphabet stored in the
linked
list, then assign 0 else assign 1.
6. Repeat the step 5 for all the character and display the code.
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<stdio.h>
char cod[50][50];
struct element
{
char c;
int count;
struct element *left;
struct element *right;
98
SEC
IT/VII
GM LAB MANUAL
};
typedef struct element NODE;
NODE *search(NODE *p,char c1)
{
while(p!=NULL)
{
if(p->c==c1)
return(p);
else
p=p->right;
}
return(NULL);
}
add(NODE *f,char c2)
{
NODE *t;
while(f->right!=NULL)
f=f->right;
t=(NODE*)malloc(sizeof(NODE));
t->c=c2;
t->count=1;
t->left=f;
t->right=NULL;
f->right=t;
return(0);
99
SEC
IT/VII
GM LAB MANUAL
}
arrange(NODE *p,int n)
{
char c3;
int i,j,cnt,cmp;
struct element *f,*s;
for(i=0,cmp=n;i<n;i++,cmp--)
{
f=p;
s=f->right;
for(j=0;j<cmp;j++)
{
if(f->count<=s->count)
{
c3=f->c;
cnt = f->count;
f->c =s->c;
f->count=s->count;
s->c=c3;
f=f->right;
s->count=cnt;
s=s->right;
}
}
}
100
SEC
IT/VII
GM LAB MANUAL
return;
}
encode(NODE *t,char c1, int i)
{
int found=0;
NODE *p1;
p1 =t;
if(found)
{
strcat(cod[i],'\0');
return;
}
else
{
if(p1->c==c1)
{
strcat(cod[i],"0");
found=1;
}
else
{
p1=p1->right;
strcat(cod[i],"1");
encode(p1,c1,i);
}
101
SEC
IT/VII
GM LAB MANUAL
}
return;
}
char decode(NODE *p,char *key)
{
while(*key)
{
if(*key == '1')
p=p->right;
key++;
}
return(p->c);
}
void main(void)
{
char name[50],d;
int i,j,len=0,nodes=1;
NODE *first,*tag,*p1,*p2;
clrscr();
printf("Enter the string to compress\n");
scanf("%s",name);
printf("The string is......... %s",name);
for(len=0;name[len]!='\0';len++);
first=(NODE *)malloc(sizeof(NODE));
first->c=name[0];
102
SEC
IT/VII
GM LAB MANUAL
first->count=1;
first->left=NULL;
first->right=NULL;
for(i=1;i<len;i++)
{
tag=search(first,name[i]);
if(tag==NULL)
{
add(first,name[i]);
nodes++;
}
else
tag->count++;
}
getch();
arrange(first,nodes);
p1=first;
p2=p1->right;
while(p2->right!=NULL)
{
p2=p2->right;
p1=p1->right;
}
printf("\nEncoded message:\n");
for(i=0;i<len;i++)
103
SEC
IT/VII
GM LAB MANUAL
{
cod[i][0]='\0';
encode(first,name[i],i);
printf("\ncode for %c =%s",name[i],cod[i]);
}
printf("\nDecoding");
for(i=0;i<len;i++)
{
d=decode(first,cod[i]);
printf("\nCharacter for %s =%c",cod[i],d);
}
getch();
}
INPUT:
Enter the string to compress: liril
OUTPUT:
Encoded message:
Code for l = 10
Code for i = 0
Code for r = 110
Code for i = 0
Code for l = 10
104
SEC
IT/VII
GM LAB MANUAL
Decoded message
Character for 10 ==> l
Character for 0 ==> i
Character for 110 ==> r
Character for 0 ==> i
Character for 10 ==> l
RESULT:
The program for Huffman encoding has been executed and the result is as shown above.
105
SEC
IT/VII
GM LAB MANUAL
GRAPHICAL ANIMATION
EX NO: 2
AIM:
To write a program for performing graphical animation
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,i,j;
initgraph(&gd,&gm," ");
setbkcolor(5);
for(i=0;i<10;i++)
{
delay(1000);
cleardevice();
if(i%2==0)
{
circle(300,300,150);
ellipse(250,250,0,360,15,30);
ellipse(350,250,0,360,15,30);
fillellipse(250,265,14,14);
fillellipse(350,265,14,14);
line(300,725,300,325);
line(301,275,301,325);
arc(300,320,220,330,70);
line(300,150,300,50);
line(265,155,245,90);
line(325,155,345,90);
106
SEC
IT/VII
GM LAB MANUAL
}
else
{
circle(300,300,150);
ellipse(250,250,0,360,15,30);
ellipse(350,250,0,360,15,30);
fillellipse(250,265,14,14);
fillellipse(350,265,14,14);
line(300,275,300,325);
line(301,275,301,325);
arc(300,320,220,330,70);
line(300,150,300,50);
line(265,155,245,90);
line(325,155,345,90);
}
}
for(i=0;i<10;i++)
{
delay(1000);
cleardevice();
if(i%2==0)
{
circle(300,300,150);
ellipse(250,250,0,360,15,30);
ellipse(350,250,0,360,15,30);
fillellipse(250,265,14,14);
fillellipse(350,250,14,14);
line(300,275,300,325);
line(301,275,301,325);
arc(300,320,220,330,70);
}
107
SEC
IT/VII
GM LAB MANUAL
else
{
circle(300,300,150);
ellipse(250,250,0,360,15,30);
ellipse(350,250,0,360,15,30);
fillellipse(250,265,14,14);
fillellipse(350,250,14,14);
line(300,275,300,325);
line(301,275,301,325);
arc(300,320,220,330,70);
}
}
getch();
closegraph();
OUTPUT FOR GRAPHICAL ANIMATION
RESULT:
The program for performing graphics animation has been executed and the result is as
shown above.
108
SEC
IT/VII
EX NO: 3
GM LAB MANUAL
IMAGE DECOMPRESSION
AIM:
To write a program to perform image decompression
SOURCE CODE:
import java.io.*;
import java.util.zip.*;
class jdcomp
{
public static void main(String[]a)throws Exception
{
InflaterInputStream fin=new InflaterInputStream(new FileInputStream("jpgIcon.jpg");
FileOutputStream out=new FileOutputStream("jpgIcon.zip");
int b;
while((b=fin.read())!=-1)
out.write(b);
fin.close();
out.close();
File f1=new File("jpgIcon.jpg");
File f2=new File("jpgIcon.zip");
System.out.println("before:"+f1.length());
System.out.println("after:"+f2.length());
}
}
OUTPUT:
D:\>cd jdk1.5.0
D:\jdk1.5.0>cd bin
D:\jdk1.5.0\bin>javac jdcom.java
D:\jdk1.5.0\bin>java jdcom
Before:104067
After:105542
RESULT:
The program for image decompression has been executed and the result is as shown
above.
109
SEC
IT/VII
GM LAB MANUAL
CHAPTER 7
FUTURE DEVELOPMENTS
It focuses in the scientific developments in the domains of 3D computer graphics, virtual and
augmented reality, imaging and computer supported cooperative work, with especial emphasis in
industrial applications in areas, such as Textile, Fashion and Apparel, Architecture, Plastic
Moulds, Entertainment and Spatial Industries .These applications are used to create multimedia
content generally meant to represent something in visual form for public broad casting.
Enhances the user experience in any form of entertainment, by making the content more
interactive and graphical.
110
SEC
IT/VII
GM LAB MANUAL
REFERENCES
Donald Hearn and M. Pauline Baker, ―Computer Graphics C Version‖,
Pearson Education, 2003.
111