Cglab Pgms
Cglab Pgms
*/
#include<math.h>
#include<stdio.h>
#include<GL/glut.h>
}
void plotline(int x, int y)
{
glPointSize(2);
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
}
void bresenhams(int x1, int y11, int x2, int y2)
{
int dx, dy,pk,xinc,yinc,x,y;
dx = x2 - x1;
dy = y2 - y11;
x = x1, y = y11;
plotline(x, y);
if (dx > 0)
xinc = 1;
else
xinc = -1;
if (dy > 0)
yinc = 1;
else
yinc = -1;
if (fabs(dx) > fabs(dy))
{
pk = 2 * fabs(dy) - fabs(dx);
for (int i = 0; i <= fabs(dx) - 1; i++)
{
if (pk > 0)
{
pk = pk + 2 * fabs(dy) - 2 * fabs(dx);
y = y+yinc;
}
else
{
pk = pk + 2 * fabs(dy);
y = y;
}
x = x + xinc;
plotline(x, y);
}
}
else
{
pk = 2 * fabs(dx) - fabs(dy);
for (int i = 0; i <= fabs(dy) - 1; i++)
{
if (pk > 0)
{
pk = pk + 2 * fabs(dx) - 2 * fabs(dy);
x = x + xinc;
}
else
{
pk = pk + 2 * fabs(dx);
x = x;
}
y = y + yinc;
plotline(x, y);
}
}
}
/*2. Write a program in OpenGL that demonstrates basic 2D geometric transformations such as
transalation, rotation and scaling. Allow the user to interactively apply these transformations to a 2D
object */
#include<stdio.h>
#include<math.h>
#include<GL/glut.h>
void init()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-500, 500, -500, 500);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display()
{
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,1,0);
glBegin(GL_TRIANGLES);
glVertex2f(-100,-100);
glVertex2f(0,200);
glVertex2f(100,-100);
glVertex2f(-100,100);
glVertex2f(0,-200);
glVertex2f(100,100);
glEnd();
glFlush();
}
void menu(int id)
{
if (id == 1)
glTranslatef(-10,0,0);
if (id == 2)
glTranslatef(10,0,0);
if (id == 3)
glTranslatef(0,10,0);
if (id == 4)
glTranslatef(0,-10,0);
if (id==5)
glRotatef(10,0,0,1);
if (id==6)
glRotatef(-10,0,0,1);
if (id==7)
glScalef(0.5,0.5,0);
if (id==8)
glScalef(1.5,1.5,0);
glutPostRedisplay();
void init()
{
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-500,500,-500,500,-500,2000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//glLoadIdentity();
glRotatef(0.01,1.0,0.0,1.0);
glColor3f(1.0,0.6,0.3);
drawcube(v[0],v[1],v[2],v[3]);
glColor3f(1.0,0.7,0.3);
drawcube(v[1],v[5],v[6],v[2]);
glColor3f(1.0,0.0,0.0);
drawcube(v[3],v[2],v[6],v[7]);
glColor3f(0.0,1.0,0.0);
drawcube(v[4],v[5],v[1],v[0]);
glColor3f(0.0,0.0,1.0);
drawcube(v[7],v[6],v[5],v[4]);
glColor3f(1.0,1.0,0.3);
drawcube(v[3],v[7],v[4],v[0]);
glFlush();
}
void drawcube(GLfloat *a,GLfloat *b,GLfloat *c,GLfloat *d)
{
glBegin(GL_POLYGON);
glVertex3fv(a);
glVertex3fv(b);
glVertex3fv(c);
glVertex3fv(d);
glEnd();
}
void keys(unsigned char k,int x,int y)
{
if(k=='s')
glScalef(0.5,0.5,0.5);
if(k=='S')
glScalef(1.5,1.5,1.5);
if(k=='t')
glTranslatef(10,10,10);
if(k=='T')
glTranslatef(-10,-10,-10);
glutPostRedisplay();
}
void spincube()
{
glutPostRedisplay();
}
void main(int argc, char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowPosition(10,10);
glutInitWindowSize(500,500);
glutCreateWindow("3D Transformation");
init();
glutDisplayFunc(display);
glutKeyboardFunc(keys);
glutIdleFunc(spincube);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
}
/*4. Write a program that takes an RGB color as input and converts it to its corresponding CMY
values*/
#include <stdio.h>
int main()
{
float R,G,B;
float C,M,Y,K,W,Rf,Gf,Bf,max;
printf("Enter the values of R,G & B: ");
scanf("%f%f%f",&R,&G,&B);
if (R<0||R>255)
{
printf("Enter R within limit\n");
scanf("%f",&R);
}
if (G<0||G>255)
{
printf("Enter G within limits\n");
scanf("%f",&G);
}
if (B<0||B>255)
{
printf("Enter B within limits\n");
scanf("%f",&B);
}
printf("\nR,G,B: %f,%f,%f\n",R,G,B);
Rf = R/255;
Gf = G/255;
Bf = B/255;
printf("***********************************\n");
printf("RGB to CMY Values\n");
W = 1;
printf("White: %f\n", W);
C = W-Rf;
M = W-Gf;
Y = W-Bf;
printf("The value of Cyan: %f\n", C);
printf("The value of Magenta: %f\n", M);
printf("The value of Yellow: %f\n", Y);
printf("***********************************\n");
# Create a window
cv2.namedWindow("Shape Properties")
image = np.zeros((550,550,3), np.uint8)
# Initial values
initial_width = 200
initial_height = 100
initial_color = (0, 255, 0) # Green
choice=1
# Create trackbars
cv2.createTrackbar("Width", "Shape Properties", initial_width, 500, on_change)
cv2.createTrackbar("Height", "Shape Properties", initial_height, 500, on_change)
cv2.createTrackbar("Red", "Shape Properties", initial_color[0], 255, on_change)
cv2.createTrackbar("Green", "Shape Properties", initial_color[1], 255, on_change)
cv2.createTrackbar("Blue", "Shape Properties", initial_color[2], 255, on_change)
while True:
# Get current trackbar values
width = cv2.getTrackbarPos("Width", "Shape Properties")
height = cv2.getTrackbarPos("Height", "Shape Properties")
red = cv2.getTrackbarPos("Red", "Shape Properties")
green = cv2.getTrackbarPos("Green", "Shape Properties")
blue = cv2.getTrackbarPos("Blue", "Shape Properties")
img = cv2.imread('images.jpeg')
half1 = w//2
half2 = h//2
# 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
# Average Blur
average_blur = cv2.blur(image, (5, 5))
# 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)