Sunday, July 27, 2014

OpenGl - Displays a BARN shape on the XY plane.



Source Code:
1:  #include <windows.h>  
2:  #include <gl/Gl.h>  
3:  #include <gl/glut.h>  
4:  #include <cmath>   
5:    
6:  int WinWidth = 500, WinHeight = 500;  
7:    
8:  typedef struct{float x;float y;}Point2D;  
9:  typedef struct{float x;float y;float z;}Point3D;  
10:    
11:    
12:  Point3D COP = {100,100,-200};  
13:    
14:  Point3D A,B,C,D,E,F,G,H,I,J;     // Vertices of the BARN  
15:    
16:  void InitBarn(){  
17:       A.x = 200; A.y = 100; A.z = 200;  
18:       B.x = 200; B.y = 00; B.z = 200;  
19:       C.x = 400; C.y = 00; C.z = 200;  
20:       D.x = 400; D.y = 100; D.z = 200;  
21:       E.x = 300; E.y = 200; E.z = 200;  
22:    
23:       F.x = 200; F.y = 100; F.z = 400;  
24:       G.x = 200; G.y = 00; G.z = 400;  
25:       H.x = 400; H.y = 00; H.z = 400;  
26:       I.x = 400; I.y = 100; I.z = 400;  
27:       J.x = 300; J.y = 200; J.z = 400;  
28:  }  
29:    
30:  void constructBarn(Point2D A, Point2D B, Point2D C, Point2D D, Point2D E, Point2D F, Point2D G, Point2D H,Point2D I,Point2D J){  
31:       glPointSize(1.0);  
32:    
33:       glBegin(GL_LINE_LOOP);       
34:       //DRAWING FRONT FACE  
35:       glVertex2i(A.x, A.y);  
36:       glVertex2i(B.x, B.y);  
37:       glVertex2i(C.x, C.y);  
38:       glVertex2i(D.x, D.y);  
39:       glVertex2i(E.x, E.y);  
40:    
41:       glEnd();  
42:    
43:       glBegin(GL_LINE_LOOP);  
44:       //DRAWING BACK FACE  
45:       glVertex2i(F.x, F.y);  
46:       glVertex2i(G.x, G.y);  
47:       glVertex2i(H.x, H.y);  
48:       glVertex2i(I.x, I.y);  
49:       glVertex2i(J.x, J.y);  
50:    
51:       glEnd();  
52:         
53:       glBegin(GL_LINES);  
54:    
55:       //DRAWING OTHER LINES  
56:       glVertex2i(A.x, A.y);  
57:       glVertex2i(F.x, F.y);  
58:    
59:       glVertex2i(B.x, B.y);  
60:       glVertex2i(G.x, G.y);  
61:    
62:       glVertex2i(C.x, C.y);  
63:       glVertex2i(H.x, H.y);  
64:    
65:       glVertex2i(D.x, D.y);  
66:       glVertex2i(I.x, I.y);  
67:    
68:       glVertex2i(E.x, E.y);  
69:       glVertex2i(J.x, J.y);  
70:    
71:       glEnd();  
72:    
73:       glFlush();  
74:    
75:  }  
76:    
77:  Point2D Project_Perspective(Point3D p, Point3D CoP){  
78:       Point2D p2;  
79:       float d = abs(CoP.z);     // The distance between the COP and orign  
80:         
81:        p2.x=(d*p.x)/(p.z+d);   
82:     p2.y=(d*p.y)/(p.z+d);  
83:         
84:       return p2;  
85:  }  
86:    
87:  Point2D translate2D(Point2D p, float tx, float ty){  
88:    Point2D tp2;  
89:       tp2.x=p.x+tx;  
90:       tp2.y=p.y+ty;  
91:         
92:       return tp2;  
93:  }   
94:    
95:  Point3D translate3D(Point3D p, float tx, float ty, float tz){  
96:    Point3D tp3;  
97:       tp3.x=p.x+tx;  
98:       tp3.y=p.y+ty;  
99:       tp3.z=p.z+tz;  
100:    
101:       return tp3;  
102:  }   
103:    
104:  void keyboard(unsigned char key, int x, int y)  
105:  {  
106:    if (key == 'q' || key == 'Q')  
107:      exit(EXIT_SUCCESS);  
108:  }  
109:    
110:  void myMouse(int button, int state, int x, int y) {  
111:       if(state == GLUT_DOWN)   
112:       {  
113:            if(button == GLUT_LEFT_BUTTON)   
114:            {  
115:                    
116:            }  
117:            else if (button == GLUT_RIGHT_BUTTON)   
118:            {  
119:                    
120:            }  
121:       }  
122:  }  
123:    
124:  void myDisplay()  
125:  {  
126:       glClearColor(0.2f, 0.3f, 0.1f, 0.0f);   
127:       glClear(GL_COLOR_BUFFER_BIT);  
128:       glColor3f(1.0f, 0.5f, 0.8f);  
129:    
130:             Point2D Projected_A=Project_Perspective(A,COP);       
131:            Point2D Projected_B=Project_Perspective(B,COP);  
132:            Point2D Projected_C=Project_Perspective(C,COP);  
133:            Point2D Projected_D=Project_Perspective(D,COP);  
134:            Point2D Projected_E=Project_Perspective(E,COP);  
135:            Point2D Projected_F=Project_Perspective(F,COP);  
136:            Point2D Projected_G=Project_Perspective(G,COP);  
137:            Point2D Projected_H=Project_Perspective(H,COP);  
138:            Point2D Projected_I=Project_Perspective(I,COP);  
139:            Point2D Projected_J=Project_Perspective(J,COP);  
140:         
141:       constructBarn(  
142:            Projected_A,  
143:            Projected_B,  
144:            Projected_C,  
145:            Projected_D,  
146:            Projected_E,  
147:            Projected_F,  
148:            Projected_G,  
149:            Projected_H,  
150:            Projected_I,  
151:            Projected_J  
152:       );  
153:  }  
154:    
155:    
156:  int main( int argc, char ** argv ) {  
157:       glutInit( &argc, argv );  
158:       glutInitWindowPosition( 0, 0 );  
159:       glutInitWindowSize( WinWidth, WinHeight );  
160:       glutCreateWindow( "Projection of a BARN" );  
161:    
162:       glMatrixMode( GL_PROJECTION );   
163:       glLoadIdentity();  
164:       gluOrtho2D( 0, WinWidth, 0, WinHeight );  
165:       glViewport(0, 0, WinWidth, WinHeight);  
166:    
167:       InitBarn();  
168:    
169:       glutKeyboardFunc(keyboard);   
170:       glutMouseFunc( myMouse );  
171:       glutDisplayFunc( myDisplay );  
172:       glutMainLoop();  
173:    
174:       return( 0 );  
175:  }  

Monday, July 21, 2014

Alpha Blending Matlab Code


Ibg=imread('E:\IP\codes\flower.jpg');
Ifg=imread('E:\IP\codes\beetle.jpg');

if length(size(Ibg))==3
        Ibg=rgb2gray(Ibg);
end
if length(size(Ifg))==3
        Ifg=rgb2gray(Ifg);
end

alpha = 0.2;

[row,col] = size(Ibg);
I = zeros(row,col);
I = uint8(I);
for i = 1:row
    for j = 1:col
        I(i,j) = alpha * Ibg(i,j) + (1 - alpha) * Ifg(i,j);
    end
end

subplot(1,3,1); imshow(Ibg);
subplot(1,3,2); imshow(Ifg);
subplot(1,3,3); imshow(I);

Auto Contrast Matlab Code


I=imread('E:\IP\imgs\lena.jpg');
amin = 0;
amax = 255;
if length(size(I))==3
        I=rgb2gray(I);
end
alow = min(min(I));
ahigh = max(max(I));

[r,c] = size(I);
J = zeros(r,c);

for m=1:r
    for n=1:c
        a = I(m,n);
        a1 = amin +((a - alow) * ((amax - amin) / (ahigh - alow)));
        J(m,n) = a1;
    end
end
J = uint8(J);
subplot(1,2,1); imshow(I);
subplot(1,2,2); imshow(J);

Sunday, July 20, 2014

Filters


  • Difference between Point Operation and Filters       
  1. Filters generally used   more than one pixel from the source image for computing each new pixel values.
  2. The capability of Point operation is limited. For example, In Point operation can't blur or sharpen an image.        

Wednesday, July 16, 2014

Definitions


Digital Image Processing: Manipulate a digitalized image using a computer.
Digital Image Editing: Manipulation of digital images using an existing software application such as Adobe Photoshop or Corel Paint
Pixel: The smallest addressable unit of an image.
Histogram: Frequency distribution of image intensities.

Thursday, July 10, 2014

AI Techniques


AI technique is a method of exploit knowledge. programs which are using AI technique are have disadvantages and advantages

         Disadvantage

  • AI technique programs are slower to execute 


         Advantages

  • They are much less fragile
  • People can easily understand what the program knowledge is
  • They can work for large problems where more direct methods break down
AI Techniques
  • Search
  • Use of Knowledge
  • Abstraction

Characteristics of AI technique



  • The knowledge capture generalization.
  • It can be understood by people who must provide it.
  • It can easily modified to correct errors and reflect changes in the world.
  • It can be used a great many situations.

AI PROBLEMS

           
         

                        Mundane Tasks

  • Perception
         -vision
         -speech

  • Natural language problem

          -Understanding
          -Generation
          -Translation

  • Commonsense reasoning
  • Robot Control


                      Formal Tasks

  • Games

         -Chess
         -Backgammon
         -Checkers-Go

  • Mathematics

         -Geometry
         -Logic
         -Integral calculus
         -Proving properties of programs

                      Expert Tasks

  • Engineering

        -Design
        -Fault finding
        -Manufacturing planning

  • Scientific analysis
  • Medical diagnosis
  • Financial analysis




Monday, July 7, 2014

Deffinitions


AI: Artificial intelligence(AI) is the study of how to make computer do things which, at the                   moment, people do better.

AI TECHNIQUE: AI technique is a method that exploits the knowledge

STATE SPACE: It contains all the possible configurations of the relevant object.

STATE SPACE SEARCH: Define a problem as states and search the solutions by starting with a initial state, using set of rules moving one state to another and attempting to end up in one of a set of final states

INITIAL STATES : Specify one or more states within the state space that describe possible situations to start problem-solving process

GOAL STATES : Specify one or more states that would be acceptable as solution to the problem