How to create a surface of revolution from the 2D perimeter?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Martina Clairand
el 29 de Abr. de 2021
Comentada: Martina Clairand
el 29 de Abr. de 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 comentarios
Respuesta aceptada
DGM
el 29 de Abr. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!