How to create a surface of revolution from the 2D perimeter?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
DGM
2021-4-29
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!