Monday, May 26, 2008

Assignment #4, Q22

For this question we are asked to shift a matrix 'a' down, one place, and have values dropping off the bottom edge.

I took this as...'as we shift the entries down, the bottom row values go to zero and then are placed at the top of matrix 'a'.

Here are the octave commands. Again...for illustrative purposes I have used a generic 3x3 matrix to show (used for questions 19 and 20 also).

octave:22> a
a =

1 3 0
2 3 6
4 7 8

octave:23> c=[0,0,0;1,0,0;0,1,0]
c =

0 0 0
1 0 0
0 1 0

octave:24> c*a
ans =

0 0 0
1 3 0
2 3 6

Assignment #4, Q 19

The following is an example of what you will see in octave if you enter the 'octave' commands. These commands show you how to shift entries of a matrix 'a' on place left (wrapping around left -> right).

octave:16> a=[1,3,0;2,3,6;4,7,8]
a =

1 3 0
2 3 6
4 7 8

octave:17> b=[0,0,1;1,0,0;0,1,0]
b =

0 0 1
1 0 0
0 1 0

octave:18> a*b
ans =

3 0 1
3 6 2
7 8 4

Assignment #4, Q 20

Octave command:

octave:14> a=[1,3,0;2,3,6;4,7,8]
a =

1 3 0
2 3 6
4 7 8

octave:15> shift(a,1)
ans =

4 7 8
1 3 0
2 3 6

Details: create a generic nxn matrix (I chose a 3x3 for illustration purposes) and use the 'shift' function in octave to have the matrix wrap around bottom -> top.

Assignment #4, Q 17

To do this question...imagine that you have a sheet of paper divided into 12 squares...

You want to make a 'net' of a colour cube which looks like a 'cross' on your sheet of paper.

If your paper is facing you so that its height is 3 squares and its width is 4 squares, then you need to have the following colours looking back at you 'going 'left to right' and 'top to bottom': (white, CM, white, white), (RB, YM, CY, GB), (white, RG, white, white).

To make the colour 'white' you need to 'turn on the R, G, and B channels'. I have indicated the 'white' regions as WA, WB, ... , WF.

Starting from scratch...the octave commands are:

RB(:,:,1)=[ones(256,1)*[0:1:255]/255];
RB(:,:,2)=[zeros(256)];
RB(:,:,3)=[ones(256,1)*[0:1:255]/255]';
RB=rotdim(RB, 270);

RG(:,:,1)=[ones(256,1)*[0:1:255]/255]';
RG(:,:,2)=[ones(256,1)*[0:1:255]/255];
RG(:,:,3)=zeros(256);

GB(:,:,1)=zeros(256);
GB(:,:,2)=[ones(256,1)*[0:1:255]/255];
GB(:,:,3)=[ones(256,1)*[255:1:0]/255]';
GB=rotdim(GB, 270);

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

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

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

WA(:,:,1)=ones(256);
WA(:,:,2)=ones(256);
WA(:,:,3)=ones(256);

WB(:,:,1)=ones(256);
WB(:,:,2)=ones(256);
WB(:,:,3)=ones(256);

WC(:,:,1)=ones(256);
WC(:,:,2)=ones(256);
WC(:,:,3)=ones(256);

WD(:,:,1)=ones(256);
WD(:,:,2)=ones(256);
WD(:,:,3)=ones(256);

WE(:,:,1)=ones(256);
WE(:,:,2)=ones(256);
WE(:,:,3)=ones(256);

WF(:,:,1)=ones(256);
WF(:,:,2)=ones(256);
WF(:,:,3)=ones(256);

Net=[WA,CM,WB,WC;RB,YM,CY,GB;WD,RG,WE,WF];

imshow(Net)

Assignment #4, Q 16

Question changed from display GM face to display CM face.

CM(:,:,1)=[ones(256,1)*[0:1:255]/255]';
CM(:,:,2)=[ones(256,1)*[0:1:255]/255];
CM(:,:,3)=ones(256);
imshow(CM)

Assignment #4, Q15

Question has been changed from display RC to display YM.

Octave command:

YM(:,:,1)=ones(256);
YM(:,:,2)=[ones(256,1)*[0:1:255]/255]';
YM(:,:,3)=[ones(256,1)*[0:1:255]/255];
imshow(YM)

Assignment #4, Q 14

This question has been changed from: show YB to show YC.

Octave command:

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

Assignment #4, Q13

Octave command:

GB(:,:,1)=zeros(256);
GB(:,:,2)=[ones(256,1)*[0:1:255]/255];
GB(:,:,3)=[ones(256,1)*[255:1:0]/255]';
GB=rotdim(GB, 270);
imshow(GB)



The rotdim function allows you to rotate the image so that the orientation of the GB face of the colour cube is the same as it appears in the textbook.

Assignment #4, Q 12

Octave command:

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


Sunday, May 25, 2008

Assignment #4, Question 11

To make an exact copy of the RB face of the colour cube on p. 404, you will need to enter the following octave command.

Octave command:

RB(:,:,1)=[ones(256,1)*[0:1:255]/255];
RB(:,:,2)=zeros(256);
RB(:,:,3)=[ones(256,1)*[0:1:255]/255]';
RB =rotdim(RB,270);

imshow(RB)



The rotdim function allows you to rotate the image so that the orientation of the RB face of the colour cube is the same as it appears in the textbook.

Assignment #4, Question 10

Octave command: imshow(ones(256,1)*(0:1:255)/255)

Assignment 4, Question 9

Same as question 6...?

Assignment #4, Question 8

Octave: 128*ones(256)

Assignment #4, Question 7

Octave command: ones(256)

Assignment #4, Question 6

Octave command: zeros(256)

Assignment #4, Question 5

Octave command: [ones(256,1)*(0:1:255)]'

Assignment #4, Question 4

Octave command: [ones(256,1)*(0:1:255)]



Using matrix multiplication to get desired 256x256 matrix.

Assignment #4, Question 3

Octave command: [0:1:255]'



Picture above shows a 1x256 matrix, which really is a transpose of question2.

Assignment #4, Question 2

Octave command: [0:1:255]



Picture shows a 1x256 matrix which starts at 0 and goes to 255, increasing by 1s.

Assignment #4, Question 1

Octave command: ones(256,1)



Picture above shows a 256x1 matrix, consisting entirely of 1s.