Monday, June 2, 2008

Assignment # 4 Q 15, 16, 17, 19, 20, 21, 22

Q(15)
Display the CY face of the color cube(cyan and yellow)

Ans.
Cyan= Green + Blue
Yellow =Red + Green
Code is as follows:
CY(:,:,1)=[ones(256,1)*[0:1:255]/255];
CY(:,:,2)=ones(256);
CY(:,:,3)=[ones(256,1)*[0:1:255]/255]';
imshow(CY)

Q(16) Display the GM face of the color cube.

Ans.
Green & Magenta( Magenta = Red + Blue)
Here is the code:
CM(:,:,1)=[ones(256,1)*[0:1:255]/255]';
CM(:,:,2)=[ones(256,1)*[0:1:255]/255];
CM(:,:,3)=ones(256);
imshow(CM)








Q(17)Display the whole color cube in a cross with white regions where there doesn't need to be anything.
Ans.

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);

Square=[WA,CM,WB,WC;RB,YM,CY,GB;WD,RG,WE,WF];
imshow(Square)


Q (19)
Shift the entries of a matrix A one place left(wrapping around left --> right)
Ans.


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

1 3 0
2 3 6
4 7 8

octave:11> B=[0,0,1;1,0,0;0,1,0]
B =

0 0 1
1 0 0
0 1 0

octave:12> A*B
ans =

3 0 1
3 6 2
7 8 4
2nd column takes the place of the 1st , 3rd takes the place of 2nd and 1st takes the place of 3rd. So one step wrapping takes place from left to right.
--------------------------------------------------------------------------------------------------

Q( 20)

Shift the entries of a matrix A one pixel down(wrapping around bottom to top)
Ans.
After defining the matrix A, use the same command sequence as for Q( 19) above, but in the last step multiply B*A.

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

1 3 0
2 3 6
4 7 8

octave:11> B=[0,0,1;1,0,0;0,1,0]
B =

0 0 1
1 0 0
0 1 0

octave:12> B*A
ans =

4 7 8
1 3 0
2 3 6
--------------------------------------------------------------------------------------------------

Q (21)
Shift the entries of a matrix A one place left(dropping values on the left edge)
Ans.
Multiply the given matrix, say, A on the right side by a matrix consisting of 1's on the 1st sub-diagonal and 0's everywhere else.
A*B
------------------------------------------------------------------------------------------------
Q(22)
Shift the entries of a matrix A one place down(dropping values on the bottom edge)

Same as s for Q( 21) above, but this time multiply B*A.

No comments: