Tuesday, June 24, 2008

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

No comments: