You are on page 1of 5

Emrah BAARAN

504111543
Computer Vision Homework - 2

1)
function [ g ] = p( x, y )
% Calculate p or p_s from dz/dx.
g = (110-x)/sqrt(10^4-((x-110)^2+(y-110)^2));
end

--------------------------------------------------------------------------function [ g ] = q( x, y )
% Calculate q or q_s from dz/dy.
g = (110-y)/sqrt(10^4-((x-110)^2+(y-110)^2));
end

--------------------------------------------------------------------------function [ g ] = my_gray( p, q, p_s, q_s )


% Calculate intensity value.
g = (p*p_s+q*q_s+1)/(sqrt(1+p^2+q^2)*sqrt(1+p_s^2+q_s^2));
end

--------------------------------------------------------------------------function [ y ] = kok( x, t )
if t == 1
y = (sqrt(100*100-(x-110)*(x-110))+110);
else
y = (110-sqrt(100*100-(x-110)*(x-110)));
end
end

--------------------------------------------------------------------------% Calculate p_s and q_s values.


s_x = 170; s_y = 60;
p_s = p(s_x,s_y);
q_s = q(s_x,s_y);
% Create 220x220 image.
fullimage = floor(rand(220,220)*0);
% For all x and y values inside the circle with radius 100,
calculate intensity values.
for x = 1:220
for y = ceil(kok(x,0))+1:kok(x,1)
fullimage(y,x) = ceil(my_gray(p(x,y), q(x,y), p_s, q_s)*256);
end
end
figure;
imshow(fullimage,[1 256]);

The images of sphere that illuminated from different locations. The center of the circle is (110,110).

Light Source at (40,40)

Light Source at (40,110)

Light Source at (80,50)

Light Source at (80,110)

Light Source at (90,130)

Light Source at (90,200)

Light Source at (110,110)

Light Source at (170,60)

Light Source at (170,150)

Light Source at (110,20)

2)
a)



   =
0

0

b)

1
0
 0 cos
 0 0 sin
0
1 0 0


*=

0 5
&
sin 10
$ % ' )
(
cos 0
1
0
0



+
=




c)
function [ u, v] = get_x_y( U, V, W, f, s_x, s_y, o_x, o_y )
d = 45*pi/180;
r_t = [1
0
0
0 cos(d) -sin(d)
0 sin(d) cos(d)
0
0
0

5;
10;
0;
1];

i = [U V W 1]';
p_p = [f/s_x
0
0

0
o_x 0;
f/s_y o_y 0;
0
1
0];

r = r_t*i;
r = p_p*r;
u = r(1)/r(3);
v = r(2)/r(3);
end

--------------------------------------------------------------------------%
U
V
W

Coordinates
= [5 15 15
= [0 0 0
= [20 20 30

of
5
0
30

Cube
5 5 15 15];
10 10 10 10];
30 20 20 30];

figure;
%Parameters
f = 15; s_x = 2; s_y = 2; o_x = 0; o_y = 10;
axis([0 20 0 20]);
hold on
for i=1:8

%Calculate x and y points in 2D.


[x(i), y(i)] = get_x_y(U(i), V(i), W(i), f, s_x, s_y, o_x, o_y);
%plot(x(i),y(i),'g*');
end
%Draw cube.
line([x(1),
line([x(1),
line([x(1),
line([x(2),
line([x(2),
line([x(3),
line([x(3),
line([x(4),
line([x(5),
line([x(5),
line([x(6),
line([x(7),
hold off

x(2)],
x(4)],
x(6)],
x(3)],
x(7)],
x(4)],
x(8)],
x(5)],
x(6)],
x(8)],
x(7)],
x(8)],

[y(1),
[y(1),
[y(1),
[y(2),
[y(2),
[y(3),
[y(3),
[y(4),
[y(5),
[y(5),
[y(6),
[y(7),

y(2)]);
y(4)]);
y(6)]);
y(3)]);
y(7)]);
y(4)]);
y(8)]);
y(5)]);
y(6)]);
y(8)]);
y(7)]);
y(8)]);

f = 10, s_x = 1, s_y = 1, o_x = 5, o_y = 10

f = 15, s_x = 2, s_y = 2, o_x = 0, o_y = 10

f = 15, s_x = 1, s_y = 1, o_x = 0, o_y = 10

You might also like