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)

No comments: