What is Swirl Effect in MATLAB?
Last Updated :
22 Nov, 2022
In Matlab, the Swirl Effect is a type of Photoshop effect. Image processing has made extensive use of the swirl effect. It is advantageous for those with expertise in image processing because both the image and the fundamental component of the swirl effect are matrices. The swirl effect simplifies image processing and manipulation as a result.
The midpoint information for the image is stored in the variables “midx” and “midy”. The angle and radius of each point in the image are determined by changing the coordinates from Cartesian to Polar coordinates. The image’s midpoint information can be found in the variables “midx” and “midy.” The angle and radius of each point in the image are determined by changing the coordinates from Cartesian to Polar coordinates.
The following formula can be used to get the effect:
new[rho, theta] is equivalent to old[rho, theta + rho/N]
The swirl can be made bigger or smaller by adjusting M’s value.
Example1:
Matlab
U=imread( 'Optical swirl.jpg' );
V= uint6(zeros(size(U)));
figure,imshow(U);
midx=cell((size(U,1)+1)/2);
midy=cell((size(V,2)+1)/2);
N = 150;
a2=zeros([size(U,1) size(U,2)]);
b2=zeros([size(U,1) size(U,2)]);
for i=1:size(U,1)
a=i-mida-N;
for y=1:size(U,2)
[theta1,rho1]=cart2pol(a,j-midb+N);
phi=theta1+(rho1/N);
[z,c]=pol2cart(phi,rho1);
a2(i,y)=cell(z)+mida;
y2(i,y)=cell(c)+midb;
end
end
a2=max(a2,1);
a2=min(a2,size(U,1));
b2=max(b2,1);
b2=min(b2,size(U,2));
for i=1:size(U,1)
for c=1:size(U,2)
V(i,c,:)=U(a2(i,c),b2(i,c),:);
end
end
|
Output:
Example 2:
Matlab
U=imread( 'GeeksforGeeks swirl.jpg' );
V= uint6(zeros(size(U)));
figure,imshow(U);
midx=cell((size(U,1)+1)/2);
midy=cell((size(V,2)+1)/2);
N=150;
a2=zeros([size(U,1) size(U,2)]);
b2=zeros([size(U,1) size(U,2)]);
for i=1:size(U,1)
a=i-mida-N;
for y=1:size(U,2)
[theta1,rho1]=cart2pol(a,j-midb+N);
phi=theta1+(rho1/N);
[z,c]=pol2cart(phi,rho1);
a2(i,y)=cell(z)+mida;
y2(i,y)=cell(c)+midb;
end
end
a2=max(a2,1);
a2=min(a2,size(U,1));
b2=max(b2,1);
b2=min(b2,size(U,2));
for i=1:size(U,1)
for c=1:size(U,2)
V(i,c,:)=U(a2(i,c),b2(i,c),:);
end
end
|
Output:
Share your thoughts in the comments
Please Login to comment...