![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/601720/image.png)
How to create a surface of revolution from the 2D perimeter?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Martina Clairand
il 29 Apr 2021
Commentato: Martina Clairand
il 29 Apr 2021
Hello,
I would like to transform the pear-shaped object in the attached image to a 3D pear.
For this I first tried to obtain the perimeter of the object via this code:
%% To detect the object
E = imbinarize(IM);
etiqueta=bwlabel(E);
object=(etiqueta==1);
figure (1)
imshow(object)
%% To find the figure contour
[B,L] = bwboundaries(object);
boundary=B{1};
figure (2)
plot(boundary(:,2), boundary(:,1), 'k', 'LineWidth', 2)
Then I was planning to use "cylinder" to revolve the perimeter but I didn't manage to obtain what I expected. Do you have an idea on how I can convert my 2D pear-shaped object into a 3D pear?
Thank you in advance for your help!
0 Commenti
Risposta accettata
DGM
il 29 Apr 2021
There are probably plenty of ways to do this, but the basic idea is that you need to know the axis of rotation and you need a function describing the radius of the object. Since your boundary is a closed curve, you have a surplus of information. In this example, I just chose to use the upper half of the curve, but you could use the lower half or average them or something.
IM = imread('pear.jpg');
E = imbinarize(IM);
object=bwareafilt(E,1); % this can be done with bwareafilt() if you have it
imshow2(object,'invert')
% i guess the object is already centered at y=140
% select the upper curve
[~,upper] = max(object);
xextent = [find(upper>1,1,'first') find(upper>1,1,'last')];
upper = 140-upper(upper>1); % trim off invalid radii
upper([1 end]) = 0; % close the curve
% in order to orient the cylinder, reorder the axes
[Y Z X] = cylinder(upper,40);
% by default, Z is normalized, so it has to be denormalized
surf(X*diff(xextent)+xextent(1),Y,Z)
axis equal
shading flat
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/601720/image.png)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Lighting, Transparency, and Shading in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!