Friday, June 27, 2008
Photo mosaic project
http://www.andreaplanet.com/andreamosaic/
It is a free software download and use
What we actually have to do to create a photo mosaic is as follows:
(1)Select a picture first(as a background picture)
(2)shrink it down to a 31 by 31 (or suitable size)image
(3) Reduce it with only 27 color values,
(4)Enlarge the image using the nearest neighbor approach
(5)Find at least one picture whose average color is one of the 27 possible colors
that appear in the picture
(6)Shrink those images so that they are the size of the 'pixels' in the enlarged picture
(7)Calculate the average colors of the smaller images,
(8) Sort them in an array so that for each color there is one image,
(9)Replace the 'pixels' in the big image with the smaller images.
Step (1)
Picture(from Google search), saved on the disk and read with the following code.
Code in MATLAB
cd c:\users\admin\pictures
pic=imread('catmosaic.jpg');
pic=double(pic)/255;
imshow(pic)
size (pic)
ans =
124 124 3
Step2
shrink it down to a 31 by 31 image
Octave Code(I am trying to write it in MATLAB too)
octave-3.0.1.exe:1>
octave-3.0.1.exe:1> function Z=zoom2(limg,scale)
> rows=floor(size(limg,1)*scale);
> cols=floor(size(limg,2)*scale);
> for i=1:rows;
> for j=1:cols;
> a=round(i/scale);
> b=round(j/scale);
> Z(i,j,:)=limg(a,b,:);
> end;
> end;
> endfunction
octave-3.0.1.exe:2> cd c:\users\admin\pictures
octave-3.0.1.exe:3> pic=imread('catmosaic.jpg');
octave-3.0.1.exe:4> pic=double(pic)/255;
octave-3.0.1.exe:5> pic=zoom2(pic,1/4);
octave-3.0.1.exe:6> imshow(pic)
octave-3.0.1.exe:7> size(pic)
ans =
31 31 3
Step 3
Reduce it with only 27 color values.
Octave code is as follows( I will try to write in MATLAB too)
octave-3.0.1.exe:8> function B=draw27(A)
> A=double(A);
> for i=1:size(A,1)
> for j=1:size(A,2)
> for k=1:3
> B(i,j,k)=floor(A(i,j,k)/86)*86+42;
> endfor
> endfor
> endfor
> endfunction
octave-3.0.1.exe:9> cd c:\users\admin\pictures
octave-3.0.1.exe:10> pic=imread('catmosaic.jpg')
octave-3.0.1.exe:11> pic27=draw27(pic);
octave-3.0.1.exe:12> imshow(double(pic27)/255)
Step 4
Enlarge(20 times) the image using the nearest neighbor approach.
Size of the image will be 620 x 620
Octave code is like this:
cols=floor(size(simg,2)*scale);
for i=0:(rows-1);
for j=0:(cols-1);
a=floor((i/scale)+1);
b=floor((j/scale)+1);
if (a>0) & (a<=original_rows) & (b>0) & (b<=original_cols)
Z(i+1,j+1,:)=simg(a,b,:);
end;
end;
end;
endfunction
cd c:\Users\admin\pictures
A=imread("pic27.jpg");
picstep3=stretch2(A,20);
size(picstep3);
B=double(picstep3)/255;
imwrite("strechedpic.jpg",B(:,:,1),B(:,:,2),B(:,:,3))
Step 5
Find at least one picture whose average color is one of the 27 possible colors that appear in the picture.
Tuesday, June 24, 2008
Assign 10 pic 2
For the above black and white (2-D) picture:
Radius = 150 pixels and
Rotated =540 degrees counterclockwise (anticlockwise)
Code will be like this:
A=imread("celebrity2.jpg");
function [outpic]=swirl(A,r,gamma);
A=double(A);
Cx=size(A,1)/2;
Cy=size(A,2)/2;
for x=1:size(A,1);
for y=1:size(A,2);
d=sqrt((x-Cx)^2+(y-Cy)^2);
if (d>r)||(d<1);
outpic(x,y)=A(x,y);
else;
if (y>Cy);
theta=acos((x-Cx)/d);
else;
theta=-acos((x-Cx)/d);
end;
fr=(d/r)^2*(1-(d/r))^2*16;
newx=d*cos(theta+gamma*fr)+Cx;
newy=d*sin(theta+gamma*fr)+Cy;
a=floor(newx);
b=floor(newy);
for k=1:3;
outpic(x,y)=[1-newx+a, newx-a]*[A(a,b), A(a,b+1);A(a+1,b), A(a+1,b+1)]*[1-newy+b; newy-b];
end;
end;
end;
end;
endfunction;
B=swirl(A,150,3*pi); #the pic was rotated counterclockwise 540 degrees so gamma=+3*pi
image(B)
Assign 10 pic 1
The given image has:
Radius = 180 pixels and
Rotated =540 degrees clockwise.
Code will be like this:
pkg load image
cd c:\users\admin\pictures
A=imread("celebrity1.jpg");
function [outpic]=swirl(A,r,gamma);
A=double(A);
Cx=size(A,1)/2;
Cy=size(A,2)/2;
for x=1:size(A,1);
for y=1:size(A,2);
d=sqrt((x-Cx)^2+(y-Cy)^2);
if (d>r)||(d<1);>Cy);
theta=acos((x-Cx)/d);
else;
theta=-acos((x-Cx)/d);
end;
fr=(d/r)^2*(1-(d/r))^2*16;
newx=d*cos(theta+gamma*fr)+Cx;
newy=d*sin(theta+gamma*fr)+Cy;
a=floor(newx);
b=floor(newy);
for k=1:3;
outpic(x,y,k)=[1-newx+a, newx-a]*[A(a,b,k), A(a,b+1,k);A(a+1,b,k), A(a+1,b+1,k)]*[1-newy+b; newy-b];
end;
end;
end;
end;
endfunction;
B=swirl(A,180,-3*pi);
C=double(B)/255;
imwrite("celebrity1.jpg",C(:,:,1),C(:,:,2),C(:,:,3));
Sunday, June 22, 2008
Assign 9 Q1
Problem
Take thge images from Assignment 6 # 3 part(c) and convert them to an image with only 64 colors.
Do this by rounding the color values for every image so that each of the red, blue and green channels have values that are in the set {0, 85, 170, 255} (alternatively, if you are working with matrices with values between 0 and 1 then you will want to take your values to be 0, 1/3, 2/3 and 1. You will be representing the image by at most 4 x 4 x4 = 64 different colors.
Solution
pkg load image
cd c:\users\admin\pictures
A=imread("P1.jpg");
B=floor((A)/64)*85;
C=255*B;
imshow(C)
Assign 8 Q 5
Problem:
Start with the picture on the left (from Wiki) ,
make the picture on the right(change an
original into a new image).
Picture in question is at the following link.
http://wiki.math.yorku.ca/images/c/cf/Start.jpg
Using the nearest neighbourhood approach (Ass#7method #2) , I scaled down four of the images by factors of 0.8, 0.6, 0.4, and 0.2 like so.
A=imread("Assignment8last problem.jpg");
B=shrink2(A,.8); % size(B) = 408 613 3
C=shrink2(A,.6); % size(C) = 306 459 3
D=shrink2(A,.4); % size(D) = 203 306 3
E=shrink2(A,.2); % size(E) = 101 152 3
Next, I placed each of the scaled images in an appropriate region so to replicate (or at least try to) the given final image.
A(52:459,78:690,:)=B;
A(103:408,155:613,:)=C;
A(155:357,231:536,:)=D;
A(206:306,308:459,:)=E;
F=double(A)/255;
Assign8 Q3
Enlarge the color images that you scaled down in assignment 7
using a factor of by 1/f. Use the bilinear interpolation approximation.
function largeimage=growing(small,f)
rows=size(smallimage,1);
cols=size(smallimage,2);
Mp=floor(size(smallimage,1)*f);
Np=floor(size(smallimage,2)*f);
for i=1:(Mp-1);
for j=1:(Np-1);
a=i/f+1;
b=j/f+1;
r=floor(a);
s=floor(b);
if(r greater 0)&(r less rows)&(s greater 0)&(s less cols)
for k = 1:3;
largeimage(i,j,k)=[1-a+r,a-r]*double([small(r,s,k),small(r,s+1,k);small(r+1,s,k),small(r+1,s+1,k)])*[1-b+s;b-s];
end
end
end
end
endfunction
A=imread("p2.jpg");
B=growing((double(A)/255),(4));
imshow(B)
Assign8 Q2
Enlarge the color images that you scaled down in assignment 7
using a factor of 1/f. Use the "nearest neighbor" approximation.
function largeimage=growing(smallimage,f)
Mp=size(smallimage,1);
Np=size(smallimage,2);
newMp=floor(size(smallimage,1)*f);
newNp=floor(size(smallimage,2)*f);
for i=0:(newMp-1)
for j=0:(newNp-1)
a=round((i/f)+1);
b=round((j/f)+1);
if(a greater 0)&(a lessMp)&(b greater 0)&(b less Np)
largeimage(i+1,j+1,:)=smallimage(a,b,:);
end
end
end
end
A=imread("p1.jpg");
B=growing((double(A)/255),(4/3));
imshow(B)
Assign 8 Q1
the x and y directions by different factors.Scale one of the
two pictures that you downloaded from the web
(whichever looks better) by
(a) fx = 1.0 , fy = 0.5
(b) fx = 0.5, fy = 1.0
(c) fx = 0.2, fy = 0.8
function small=scale(largeimage,fx,fy);
Mp=floor(size(largeimage,1)*fx);
Np=floor(size(largeimage,2)*fy);
smallimage(:,:,1)=zeros(Mp,Np);
smallimage(:,:,2)=zeros(Mp,Np);
smallimage(:,:,3)=zeros(Mp,Np);
for i=0:(Mp-1);
for j=0:(Np-1);
for x=floor(i/fx):ceil((i+1)/fx)-1;
for y=floor(j/fy):ceil((j+1)/fy)-1;
ival=largeimage(x+1,y+1,:)
ival=double(ival);
if (x less i/fx)
ival=ival*(1-i/fx+x)
end;
if (x+1 greater (i+1)/fx)
ival=ival*(1-(i+1)/fx+x+1);
end;
if(y less i/fy)
ival=ival*(1-j/fy+y);
end;
if (y+1 greater (j+1)/fy)
ival=ival*(1-(j+1)/fy+y+1);
end;
smallimage(i+1,j+1,:)=smallimage(i+1,j+1,:)+ival;
end;
small(i+1,j+1,:)=small(i+1,j+1,:)/((1/fx)*(1/fy));
end;
end;
endfunction
A=imread("CokeCan.jpg");
B=scale((double(A)/255),1,.5);
imshow(B)
Assign 7 Q1
Please see the following useful link:
http://www.shrinkpictures.com
Method one:
Average over all pixels in the destination point(Sub square average shrink)
Code would be like this:
pkg load image
cd C:\
largeimage=double(imread("p1.jpg"));
f=0.10;
Mp=floor(size(largeimage,1)*f);
Np=floor(size(largeimage,2)*f);
smallimage(:,:,1)=zeros(Mp,Np);
smallimage(:,:,2)=zeros(Mp,Np);
smallimage(:,:,3)=zeros(Mp,Np);
for i=0:(Mp-1);
for j=0:(Np-1);
for x=(floor(i/f)):ceil((i+1)/f)-1;
for y=(floor(j/f)):ceil((j+1)/f)-1;
ival=largeimage(x+1,y+1,:);
if (x<(i/f)); ival=ival*(1+x-(i/f)); end if ((x+1)>(i+1)/f);
ival=ival*(1-(x+1)+((i+1)/f));
end
if (y<(j/f)); ival=ival*(1+y-(j/f)); end if ((y+1)>(j+1)/f);
ival=ival*(1-(y+1)+((j+1)/f));
end
smallimage(i+1,j+1,:)=smallimage(i+1,j+1,:)+ival;
end
end
end
end
small=smallimage*f*f;
imshow(double(small)/255);
Method 2:
To take the nearest neighborhood.
That is, the pixel at (i,j) on the smaller image
will be equal to the value of the pixel nearest
to (i/f, j/f) on the larger image.
pkg load image
cd C:\
largeimage=imread("p1.jpg");
largeimage=double(largeimage);
f=0.75;
Mp=floor(size(largeimage,1)*f-1);
Np=floor(size(largeimage,2)*f-1);
smallimage(:,:,1)=zeros(Mp-1,Np-1);
smallimage(:,:,2)=zeros(Mp-1,Np-1);
smallimage(:,:,3)=zeros(Mp-1,Np-1);
for i=1:(Mp-1)
for j=1:(Np-1)
a=round(i/f);
b=round(j/f);
smallimage(i,j,:)=largeimage(a,b,:);
end;
end;
imshow(double(smallimage/255))
Method 3
To take bilinear interpolation of the larger image.
The pixel at (i,j) on the smaller image will be equal
to the bilinear interpolation of 4 nearest neighbors of (i/f, j/f).
pkg load image
cd C:\
largeimage=double(imread("P1.jpg"));
f=0.75;
Mp=floor(size(largeimage,1)*f);
Np=floor(size(largeimage,2)*f);
smallimage(:,:,1)=zeros(Mp,Np);
smallimage(:,:,2)=zeros(Mp,Np);
smallimage(:,:,3)=zeros(Mp,Np);
for i=1:Mp
for j=1:Np
a=i/f;
b=j/f;
r=floor(a);
s=floor(b);
if (r>0) &(r(lessthan size(largeimage,1)&(s>0)&(s(lessthan size(largeimage,2)
for k=1:3
smallimage(i,j,k)=[1-a+r,a-r]*[largeimage(r,s,k),largeimage(r,s+1,k);largeimage(r+1,s,k),largeimage(r+1,s+1,k)]*[1-b+s;b-s];
end;
end;
end;
end;
imshow(smallimage/255)
Saturday, June 21, 2008
Assign 6 Q3b
Rainbow from Assignment 4 Q4 is given by:
To find its average color write the following code:
pkg load image
cd C:\users\admin\pictures
A=imread("assign4q18rainbow.jpg");
imshow(A)
size(A)
ans =
89 129 3
sum(sum(A))
ans =
ans(:,:,1) = 2076422
ans(:,:,2) = 1669866
ans(:,:,3) = 1580322
B=sum(sum(A))/size(A,1)/size(A,2)
B =
ans(:,:,1) = 180.86
ans(:,:,2) = 145.45
ans(:,:,3) = 137.65
for i=1:3
averagecolor(:,:,i)=B(i)*ones(100);
end
imshow(averagecolor)
Average color = white screen
Assign 6Q3Cpic2
This is my picture 2 in the centre and on the right corner is its average color.
The code for the average color of picture 2isas follows:
octave-3.0.1.exe:39> cd c:\
octave-3.0.1.exe:40> G=imread("p2.jpg");
octave-3.0.1.exe:41> H=double(G)/255;
octave-3.0.1.exe:42> size(H)
ans =
640 480 3
octave-3.0.1.exe:43> averagecolor=sum(sum(H))/(640*480)
averagecolor =
ans(:,:,1) = 0.31509
ans(:,:,2) = 0.38258
ans(:,:,3) = 0.20739
octave-3.0.1.exe:44> I=ones(256);
octave-3.0.1.exe:45> I(:,:,1)=0.31509*ones(256);
octave-3.0.1.exe:46> I(:,:,2)=0.38258*ones(256);
octave-3.0.1.exe:47> I(:,:,3)=0.20739*ones(256);
octave-3.0.1.exe:48> cd c:\users\public\documents
octave-3.0.1.exe:49> imwrite("p2out.jpg",I(:,:,1),I(:,:,2),I(:,:,3));
assign 6Q3Cpic1
My first picture is this(far right corner:
The average color of this oicture is in the middle:
The code for the average color is as follows:
octave-3.0.1.exe:28> cd c:\
octave-3.0.1.exe:29> A=imread("p1.jpg");
octave-3.0.1.exe:30> B=double(A)/255;
octave-3.0.1.exe:31> size(B)
ans =
158 106 3
octave-3.0.1.exe:32> averagecolor=sum(sum(B))/(158*106)
averagecolor =
ans(:,:,1) = 0.35086
ans(:,:,2) = 0.60035
ans(:,:,3) = 0.85278
octave-3.0.1.exe:33> C=ones(256);
octave-3.0.1.exe:34> C(:,:,1)=0.35086*ones(256);
octave-3.0.1.exe:35> C(:,:,2)=0.60035*ones(256);
octave-3.0.1.exe:36> C(:,:,3)=0.85278*ones(256);
octave-3.0.1.exe:37> cd c:\users\public\documents
octave-3.0.1.exe:38> imwrite("p1out.jpg", C(:,:,1),C(:,:,2),C(:,:,3));
Assign 4 Q 18
Q 18 Code for Rainbow is as follows:
Considering 6 colors, starting from Red and go up to magenta.
Red, Yellow, Green, Cyan, Blue,magenta:
Red+Green=Yellow
Red+Blue=Magenta
Blue+Green=cyan
R(:,:,1)=ones(256);
R(:,:,2)=ones(256,1)*[0:1:255]/255;
R(:,:,3)=zeros(256);
imshow(R)
Y(:,:,1)=ones(256,1)*[255:-1:0]/255;
Y(:,:,2)=ones(256);
Y(:,:,3)=zeros(256);
imshow(Y)
G(:,:,1)=zeros(256);
G(:,:,2)=ones(256);
G(:,:,3)=ones(256,1)*[0:1:255]/255;
imshow(G)
C(:,:,1)=zeros(256);
C(:,:,2)=ones(256,1)*[255:-1:0]/255;
C(:,:,3)=ones(256);
imshow(C)
B(:,:,1)=ones(256,1)*[0:1:255]/255;
B(:,:,2)=zeros(256);
B(:,:,3)=ones(256);
imshow(B)
M(:,:,1)=ones(256);
M(:,:,2)=zeros(256);
M(:,:,3)=ones(256,1)*[255:-1:0]/255;
imshow(M)
A=[R,Y,G,C,B,M];
imshow(A)
Note: Any other combination and order of colors can be considered and change the outlook of rainbow.
Thursday, June 5, 2008
assignment #6 Q3(a)
Wednesday, June 4, 2008
assignment #6 Q3
assignment #6 Q1
Q(1)
newmatrix=128*ones(256);
bigT=255*ones(256);
bigT(30:79,64:191)=zeros(50,128);
bigT(50:199,111:146)=zeros(150,36);
theta=(pi)/6;
for x=1:256;
for y=1:256;
u=x*cos(theta) - y*sin(theta);
v=x*sin(theta) + y*cos(theta);
up=mod(u,256) + 1;
vp=mod(v,256) + 1;
a=up;
b=mod(vp-1*up,256)+1;
r=floor(a);
s=floor(b);
if (r>0) & (r<256)>0) & (s<256);
mata=[1-a+r, a-r];
matb=[bigT(r,s), bigT(r,s+1); bigT((r+1),s), bigT((r+1),(s+1))];
matc=[1-b+s;b-s];
newmatrix(x,y)=mata*matb*matc;
end;
end;
end;
imshow(newmatrix)
assignment #6 Q2
Q(2):Create a 256 x 256 matix with ones in the (i,i+1) position and zeros elsewhere.
Ans.
A=zeros(256);
for x=1:256;
A(x,x+1)=1;
end;
--------------------------
A 256 x 256 matrix with 1's in the (i,i+1) position and zeros elsewhere can be coded as follows:
A=tril(ones(256),1);
B=tril(ones(256),0);
A-B
----------------------
In one line:
A=(tril(ones(256,1))-tril(ones(256),0)imshaow(A)
----------------
Tuesday, June 3, 2008
assignment #5 Q 3(part 3)
bigT=255*ones(256);
bigT(30:79,64:191)=zeros(50,128);
bigT(50:199,111:146)=zeros(150,36);
theta=(pi)/6;
bigT1=ones(256);
for x=0:255;
for y=0:255;
x1=(x*cos(theta)-y*sin(theta))+256;
y1=(x*sin(theta)+y*cos(theta));
x2=round(x1);
y2=round(y1);
bigT1(mod(x2,256)+1,mod(y2,256)+1)=bigT(x+1,y+1);
end;
end;
imshow(bigT1)
----------------------------------------------------------------------------------------------------------------------------
Skew and rotate:
newbigT=ones(256);
bigT=255*ones(256);
bigT(30:79,64:191)=zeros(50,128);
bigT(50:199,111:146)=zeros(150,36);
theta=(pi)/6;
for x=0:255
for y=0:255
x1=x;
y1=mod((y+1*x),256)+1;
x2=(x1*cos(theta)-y1*sin(theta))+256;
y2=(x1*sin(theta)+y1*cos(theta));
x3=round(x2);
y3=round(y2);
newbigT(mod(x3,256)+1,mod(y3,256)+1)=bigT(x+1,y+1);
end;
end;
imshow(newbigT)
assignment #5 Q 3(part 2)
assignment #5 Q 3
assignment #5 Q 2
Q(2) Give Octave commands to draw the top part of figure 6.4 in the book(without lettering)
Ans.
rgbycm=zeros(256);
for x=1:256;
for y=1:256;
r=(x-128)^2 + (y-100)^2;
g=(x-78)^2 + (y-125)^2;
b=(x-128)^2 + (y-150)^2;
if r<=2500;
red=1;
else;
red=0;
end;
if g<=2500;
green=1;
else;
green=0;
end;
if b<=2500;
blue=1;
else;
blue=0;
end;
rgbycm(x,y,1)=red;
rgbycm(x,y,2)=green;
rgbycm(x,y,3)=blue;
end;
end;
imshow(rgbycm)
assignment #5 Q 1
Monday, June 2, 2008
Assignment # 4 Q 15, 16, 17, 19, 20, 21, 22
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.