Open In App

Cone Effect in MATLAB

Last Updated : 02 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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




% 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:

  • Read the original image using imread. Show it using the title ‘Original’.
  • Create a variable that will store the final image having a cone effect in the original image.
  • Calculate the mid values.
  • We’ll use nested for loops to create the required cone effect.
  • Use cart2pol to convert cartesian to polar coordinates.
  • Analyze the values of the array. If it is less than 1, we’ll replace it with 1 else replace it with the size of the array.
  • Now set the pixels of the final image. 
  • Show the final image using the title ‘Image with Cone Effect’.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads