Open In App

Cone Effect in MATLAB

MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. With the help of this software, we can also give the cone effect to an image. It is done by using the image’s midpoint. After this, we convert the points into polar coordinates to find the angle and the radius. Then we’ll change K in radius*K in order to achieve the cone effect. 

Cone Effect is the effect when an image shrinks to its center forming a cone like effect.



Example 1:




% MATLAB code for code effect
% read and show the original image
original = imread('image1.png');
imshow(original); title('original');
  
% final will store the image with cone effect 
final=uint8(zeros(size(original)));
  
% Calculating mid values
Xmid=ceil((size(original,1)+1)/2);
Ymid=ceil((size(original,2)+1)/2);
  
  
% declaring K
K=180;
x2=zeros([size(original,1) size(original,2)]);
y2=zeros([size(original,1) size(original,2)]);
  
% Using nested for loops to create cone effect 
for i = 1:size(original,1)
    x = i - Xmid;
    for j = 1:size(original,2)
        [theta,rho] = cart2pol(x, j-Ymid);
        sqtrho = sqrt(rho * K);
        [a,b] = pol2cart(theta, sqtrho);
        x2(i,j) = ceil(a) + Xmid; 
        y2(i,j) = ceil(b) + Ymid;
    end
end
  
  
% Changing array values
  
x2(x2<1)=1;
x2(x2>size(original,1))=size(original,1);
       
y2(y2<1)=1;
y2(y2>size(original,2))=size(original,2);
  
  
for i=1:size(original,1)
    for j=1:size(original,2)
        final(i,j,:) = original(x2(i,j),y2(i,j),:);
    end
end
   
% showing final image
figure, imshow(final);title('Image with Cone Effect');

Output:



Input Image:

 

Output(Image with the Cone Effect):

 

Explanation:


Article Tags :