Tuesday, May 27, 2008

Assignment # 5

Problem #1

A=zeros(256);
for x=1:256;
for y=1:256;
if (x-128)^2+(y-128)^2<=2500 A(x,y)=1;
endif
endfor
endfor
imshow(A)

















Problem # 2

A1=zeros(256);
for x=1:256;
for y=1:256;
if (x-95.3)^2+(y-128)^2<=2500
A1(x,y)=1;
endif
endfor
endfor;
A2=zeros(256);
for x=1:256; for y=1:256;
if (x-142.6)^2+(y-104)^2<=2500
A2(x,y)=1;
endif
endfor
endfor;
A3=zeros(256);
for x=1:256; for y=1:256;
if (x-142.6)^2+(y-170)^2<=2500
A3(x,y)=1;
endif
endfor
endfor;
B(:,:,2)=255*A1;
B(:,:,1)=255*A2;
B(:,:,3)=255*A3;
imshow(B)






















Problem # 3

Big T skewed by s =2

bigT=255*ones(256);
bigT(30:79,64:191)=zeros(50,128);
bigT(50:199,111:146)=zeros(150,36);
for x =1:256;
for y =1:256;
y1=rem(2*x+y,256)+1;
bigT1(x,y)=bigT(x,y1);
endfor;
endfor;
imshow(bigT1)


















Big T skewed by s = 2, and turned by 3*pi/4

bigT=255*ones(256);
bigT(30:79,64:191)=zeros(50,128);
bigT(50:199,111:146)=zeros(150,36);
for x =1:256
for y =1:256
y1=mod(2*x+y,256)+1;
bigT1(x,y) = bigT(x,y1);
endfor
endfor;
for x =1:256
for y =1:256
x2=x*cos(3*pi/4)-y*sin(3*pi/4);
y2=x*sin(3*pi/4)+y*cos(3*pi/4);
x3 = round(x2);
y3 = round(y2);
bigT2(mod(x3,256)+1,mod(y3,256)+1)=bigT1(x,y);
endfor
endfor
imshow(bigT2)






Saturday, May 24, 2008

Assignment # 4

1. ones(256)

2. [0:1:255]

3. [0:1:255]'

4. ones(256,1)*[0:1:255]

5. [0:1:255]'*ones(1,256)

6. zeros(256)

7. ones(256)

8. 128*ones(256)

9. zeros(256)

10. imshow(ones(256,1)*[0:1:255]/255)
















11. Display the RB face of the colour cube

x(:,:,1)= [ones(256,1)*[0:1:255]/255]';

x(:,:,2)= zeros(256);

x(:,:,3)= [ones(256,1)*[0:1:255]/255];

imshow(x)

















12. Display the RG face of the colour cube:

x(:,:,1)=[ones(256,1)*[0:1:255]/255]’;
x(:,:,2)=[ones(256,1)*[0:1:255]/255];
x(:,:,3)=zeros(256);
imshow(x)















13. Display the GB face of the colour cube:
x(:,:,1)=zeros(256);
x(:,:,2)=[ones(256,1)*[0:1:255]/255]’;
x(:,:,3)=[ones(256,1)*[0:1:255]/255];
imshow(x)

















14, 15, 16. Display the CM, MY, and YC (according to Mike's answer from the facebook) faces of the colour cube:
CM face
x(:,:,1)=[ones(256,1)*[0:1:255]/255];
x(:,:,2)=[ones(256,1)*[0:1:255]/255]’;
x(:,:,3)=ones(256);
imshow(x)

















MY
x(:,:,1)=ones(256);
x(:,:,2)=[ones(256,1)*[0:1:255]/255];
x(:,:,3)=[ones(256,1)*[0:1:255]/255]’;
imshow(x)



















YC
x(:,:,1)=[ones(256,1)*[0:1:255]/255]’;
x(:,:,2)=ones(256);
x(:,:,3)=[ones(256,1)*[0:1:255]/255];
imshow(x)



















19. A=[1 2 3;4 5 6;7 8 ];
B=[0 0 1;1 0 0;0 1 0]
x=A*B
x=

2 3 1

5 6 4

8 9 7

20.

A=[1 2 3;4 5 6;7 8 9];
B=[0 0 1;1 0 0;0 1 0];
x=B*A
x=
7 8 9
1 2 3
4 5 6

22.

A=[1 2 3;4 5 6;7 8 9];
B=[0 0 0;1 0 0;0 1 0];
x=B*A
x=
0 0 0
1 2 3
4 5 6
21.
















#23
W(:,:,1)=ones(256);
W(:,:,2)=ones(256);
W(:,:,3)=ones(256);
CM(:,:,1)=[ones(256,1)*[0:1:255]/255];
CM(:,:,2)=[ones(256,1)*[0:1:255]/255]’;
CM(:,:,3)=ones(256);
CM=rotdim(CM,-1);
BR(:,:,1)= [ones(256,1)*[0:1:255]/255];
BR(:,:,2)= zeros(256);
BR(:,:,3)= [ones(256,1)*[0:1:255]/255]’;
BG(:,:,1)= zeros(256);
BG(:,:,2)= [ones(256,1)*[0:1:255]/255]’;
BG(:,:,3)= [ones(256,1)*[0:1:255]/255];
BG=rotdim(BG,-1);
YC(:,:,1)= [ones(256,1)*[0:1:255]/255]’;
YC(:,:,2)=ones(256);
YC(:,:,3)= [ones(256,1)*[0:1:255]/255];
YC=rotdim(YC,-1);
RG(:,:,1)= [ones(256,1)*[0:1:255]/255]’;
RG(:,:,2)= [ones(256,1)*[0:1:255]/255];
RG(:,:,3)= zeros(256);
RG=rotdim(RG,2);
MY(:,:,1)= ones(256);
MY(:,:,2)= [ones(256,1)*[0:1:255]/255];
MY(:,:,3)= [ones(256,1)*[0:1:255]/255]’;
imshow([W,W,RG,W;MY,YC,BG,BR;W,W,CM,W])
24.imshow([MY,YC,BG,BR])

Tuesday, May 20, 2008

ASSIGNMENT # 3































First graph (wl vs. y ) shows the levels of green depending on wavelengths. Graph (wl vs. x/y) will represent ratio of red to green depending on the wavelength. The third graph wl vs. z/y - ratio of blue to green.


Problem # 4

a) To obtain the CYM components, we need to subtract the RBG components from 1.
We will get the following table:
For the given image, the maximum intensity and saturation requirements mean that the RGB components are 0 to 1. Since the CYM values are 1-RGB, they are also from 0 to 1.


















Images in OCTAVE





b) If we fed the CYN components to the RGB inputs of a colour monitor we will get the following image ( refer to the "grey" part of the table): WHITE, CYAN, BLUE, MAGENTA,RED,YELLOW,GREEN, and BLACK. The grey border will remain Grey


Problem # 6

a) This transformation changes only hue (Theta) coordinate of the HSI coordinates
While switching Red and Blue we are remaining in the same plane perpendicular to the vertical intensity axis. We are performing the reflection about Green-Magenta line of symmetry. We are sending red-green angle (0-120) to (120-240), and green-blue (120-240) into (0-120). Nothing is moving along intensity axis. ( From the equation itself I = 1/3 ( R+G+B) it is clear that to change the intensity at least one of the values of RGB has to be changed).

Saturation (the distance from the vertical axes) is the length of the vector from the origin to the point. Reflection will preserve the distance, so for the example, the saturation of Blue will be as saturation of Red was before the transformation.
b)Image 6.5 with exchanged red and blue colour channels of the image.





















Problem # 2

Let c be the given colour with its coordinates (x,y), which is known to lie on the straight line joining any two valid colours c1 and c2. The relative percentages of colours c1 and c2 composing of the given colour can be expressed as the ratios between the line segments cc1 to c1c2, and cc2 to c_1c_2.

distance between c and c_1
d_1= [(x- x_1)^2 + (y-y_1)^2]^1/2
distance between c1 and c2
d_2 = [(x_1-x_2)^2+(y_1-y_2)^2]^1/2
So the percentage of c1 in c can be expressed:
p1= [(d_2-d_1)/d_2]*100.

The percentage of c_2 will be equal to 100-p_1

Problem # 5

Transformation which will change white to black will be : 1-[1,1,1], which will result in [0,0,0];
The same transformation 1 - [R G B] will result in changing blue into yellow (no blue), and red into cyan (no red). So it is the same transformation we look at in the question #4 RGB into CYM.
By looking at the formulas for computing HSI components we may derive the conclusion that this transformation will effect the hue component of HSI.Our textbook, however says that " the RGB complement transformation functions do not have a straightforward HSI space equivalent(...) saturation component of the complement cannot be computed from the saturation component of the input image alone."
HSI components of the complements {yellow, cyan, black) may be expressed by the following equations:















Problem # 3

Let's consider any three valid colours c_1, c_2. and c_3 with coordinates (x_1,y_1), (x_2, y_2), and (x_3,y_3) in the chromacity diagram. Denote by c the given colour with coordinates (x,y).
To find the relative percentages of c_1,c_2, and c_3 in c let start by finding the relative percentage p_1+p_2 of c_1 and c_2 in c. The relative percentage of c_3 in c will be given by p_3=1-(p_1+p_2)

To find the distance of point c from the line segment c_1c_2 we may use the following formula
d_1=abs value(y_2*x-y_1*x-x_2*y+x_1*y-y_2*x_1+y_1*x_2)/[(y_2-y_1)^2+(x_2-x_1^2]^1/2
We want to find the distance d_2 of c_3 from the line segment c_1c_2.

d_2=abs.value (y_2*x_3-y_1*x_3-x_2*y-3+x_1*y_3-y_2*x_1+y_1*x_2)/[(y_2-y_1)^2+(x_2-x_1)^2]^1/2

so the relative percentage of c_1and c_2 in c, p_2+p_1=[( d_2-d_1)/d_2]*100

So the relative percentage p_3 of c_3 in c will be 1-(p_1+p_2)

Tuesday, May 13, 2008

Assignment # 2

The first 4 digits of my student number are 2087. For question 2 I have assigned part h, for question # 3 – part c, for question # 6 – part b.

Question # 1

Show that every binary function can be expressed as a composition of the binary operations AND/OR and NOT.
1111 x OR NOT y
1110 x OR y
1101 (x AND y) OR NOT (x AND y)
1100 (x AND y) OR (x AND NOT y)
1011 y OR (NOT x)
1010 y AND y
1001 (x AND y) OR [(NOT x )AND (NOT y)]
1000 x AND y
0111 NOT(x AND y)
0110 x AND (NOT y) OR [(y AND (NOT x)]
0101 NOT y
0100 x AND (NOT y)
0011 NOT x
0010 y AND (NOT x)
0001 NOT (x OR y)
0000 y AND (NOT Y), (x AND NOT x ) AND (y AND NOT y)

Question # 2

Which of the 16 possible binary functions cannot be represented using only compositions of {NOT, IMPL}

Since NOT y IMPL [(NOT x IMPL y) IMPL NOT(x IMPL y) can be represented as x OR y or NOT (x OR y) = x AND y, all of the possible 16 binary functions can be represented using only compositions of {NOT,IMPL}.

Question # 3

Which of the 16 binary operators are idempotent?
A binary operation is called idempotent if, whenever it is applied to two equal values, it gives that value as the result. Based on this definition ( if I understood it correctly?) AND , OR are idempotent functions (1 AND 1 = 1, 0 AND 0 = 0), (1 OR 1 = 1, 0 OR 0 = 0)

Question # 4

Since we are creating 9-tuples (3 choices for the first position and 3 choices for the second position 3x3 = 9) using 3 possible inputs, the number of possible functions will be 3 ^ 9 = 19683.

Question # 5

How many binary operations are necessary to express every possible 2 argument function for ternary inputs?
Based on the following source: www.fw.uri.br/~arpasi/artigos/ternary.pdf
there are four binary operations which can be use to express every possible 2 argument function for ternary inputs: NOT,OR, AND, and IMPLY.


Question # 6











The images are displayed in the following order:
pic1 AND pic 2
pic1 IMPL pic2
pic1 OR pic2

Question # 7


P - Poison caused the victim's death.
B - There was a change in his blood chemistry.
S - There was a residue of poison in the stomach.

Sentence 1: Poison caused the victim's death if and only if there was a change in his blood chemistry or residue of poison in the stomach.

P IFF B OR S

G - There were puncture marks on the body.

Sentence 2: There was neither a change in blood chemistry nor a residue of poison in the stomach, but there were puncture marks on the body.

(NOT B AND NOT S) AND G

N - Poison was injected by a needle only.

Sentence 3: Poison was injected by a needle only if there were puncture marks on the body.

N IMPL G

Sentence 4: Either poison was the cause of the victim's death, or there are no puncture marks on the body.

P OR NOT G

If we assume that all statements are true we may conclude that P is true; poison caused the victim's death.

Orders of Magnitude

(1) 1024^3 /64 x1024 = 16384


(2) 4.7x1024^3/800x1024= 6160.384= approximately 6160

(3) First commercial PC Altair 8800 had a clock rate of 2 MHz (2 million cycles/sec.)
The original IBM PC (c. 1981) - 4.77 MHz.
In 2002 - 3GHz ( 3 billion cycles/sec.)
Source: http://en.wikipedia.org/wiki/Clock_rate


(3)

Sunday, May 11, 2008

Comuters in 20- 25 years from now

COMPUTERS 20 YEARS FROM NOW

When I was in elementary school we were asked to describe what the world will be like 25 years from then. None of our predictions came true. Extrapolating from the observations about what computers are capable of doing today I can make the following predictions:
  • Computers will be much smaller and lightweight. Imagine laptops the size of an iPOD with "virtual" inputs and outputs.
  • User input will be much more efficient, we will not use mouse, rather our hands, or we will tell computer what to do ( already done to some degree).
  • Many moving parts will be replaced with faster and cooler forms of communication and storage ( flash hard drives vs. hard disc; fiber optics or just simply light vs. traditional ways used for computation.)
  • Output will change to higher resolution monitors, or rudimentary "holograms" and 3D displays; even paper thin monitors.
  • Whatever still have wires will probably go wireless.
  • A.I. will be able to interpret simple vocal commands and carry out simple conversations.
  • Computers will find many more real - life applications: health care, inventing new drags, performing surgeries, flying planes, fighting wars (they already do it to some degree),teaching, cooking and cleaning(let's hope), paying complements, cheering up...

Jagoda