pctransform
Transform 3-D point cloud
Description
applies the specified 3-D affine transform, ptCloudOut
= pctransform(ptCloudIn
,tform
)tform
to the
point cloud, ptCloudIn
. The transformation can be a rigid
or nonrigid transform.
applies the displacement field ptCloudOut
= pctransform(ptCloudIn
,D
)D
to the point cloud. Point
cloud transformation using a displacement field define translations with respect
to each point in the point cloud.
Examples
Rotate 3-D Point Cloud Using Rigid Transformation
Read a point cloud.
ptCloud = pcread('teapot.ply');
Plot the point cloud.
figure pcshow(ptCloud) xlabel('X') ylabel('Y') zlabel('Z')
Create a transform object with a 45 degree rotation along the z-axis.
theta = pi/4; rot = [cos(theta) sin(theta) 0; ... -sin(theta) cos(theta) 0; ... 0 0 1]; trans = [0, 0, 0]; tform = rigid3d(rot,trans);
Transform the point cloud.
ptCloudOut = pctransform(ptCloud,tform);
Plot the transformed point cloud.
figure pcshow(ptCloudOut) xlabel('X') ylabel('Y') zlabel('Z')
Affine Transformations of 3-D Point Cloud
This example shows affine transformation of a 3-D point cloud. The specified forward transform can be a rigid or nonrigid transform. The transformations shown includes rotation (rigid transform) and shearing (nonrigid transform) of the input point cloud.
Read a point cloud into the workspace.
ptCloud = pcread('teapot.ply');
Rotation of 3-D Point Cloud
Create an affine transform object that defines a 45 degree rotation along the z-axis.
A = [cos(pi/4) sin(pi/4) 0 0; ... -sin(pi/4) cos(pi/4) 0 0; ... 0 0 1 0; ... 0 0 0 1]; tform = affine3d(A);
Transform the point cloud.
ptCloudOut1 = pctransform(ptCloud,tform);
Shearing of 3-D point cloud
Create an affine transform object that defines shearing along the x-axis.
A = [1 0 0 0; ... 0.75 1 0 0; ... 0.75 0 1 0; ... 0 0 0 1]; tform = affine3d(A);
Transform the point cloud.
ptCloudOut2 = pctransform(ptCloud,tform);
Display the Original and Affine Transformed 3-D Point Clouds
Plot the original 3-D point cloud.
figure1 = figure('WindowState','normal'); axes1 = axes('Parent',figure1); pcshow(ptCloud,'Parent',axes1); xlabel('X'); ylabel('Y'); zlabel('Z'); title('3-D Point Cloud','FontSize',14)
% Plot the rotation and shear affine transformed 3-D point clouds. figure2 = figure('WindowState','normal'); axes2 = axes('Parent',figure2); pcshow(ptCloudOut1,'Parent',axes2); xlabel('X'); ylabel('Y'); zlabel('Z'); title({'Rotation of 3-D Point Cloud'},'FontSize',14)
figure3 = figure('WindowState','normal'); axes3 = axes('Parent',figure3); pcshow(ptCloudOut2,'Parent',axes3); xlabel('X'); ylabel('Y'); zlabel('Z'); title({'Shearing of 3-D Point Cloud'},'FontSize',14)
Point Cloud Transformation Using Displacement Field
Read a point cloud into the workspace.
ptCloud = pcread('teapot.ply');
Create a displacement field D
of same size as the point cloud.
D = zeros(size(ptCloud.Location));
Set the displacement field value along x-axis for the first half of the points to 7.
pthalf = ptCloud.Count/2; D(1:pthalf,1) = 7;
Extract the indices of points within a region-of-interest (ROI) using the pointCloud
method findNeighborsInRadius
. Set the displacement field value along the x-, y-, and z-axis for points within the ROI to 4, 4, and -2, respectively.
indices = findNeighborsInRadius(ptCloud,[0 0 3.1],1.5); D(indices,1:2) = 4; D(indices,3) = -2;
Transform the point cloud using the displacement field.
ptCloudOut = pctransform(ptCloud,D);
Display the original and transformed point cloud.
figure pcshow(ptCloud) xlabel('X'); ylabel('Y'); zlabel('Z'); title('Original 3-D Point Cloud')
figure pcshow(ptCloudOut) xlabel('X'); ylabel('Y'); zlabel('Z'); title('Transformed 3-D Point Cloud Using Displacement Field')
Input Arguments
ptCloudIn
— Point cloud
pointCloud
object
Point cloud, specified as a pointCloud
object.
tform
— 3-D geometric transformation
rigid3d
object | affine3d
object
3-D geometric transformation, specified as a rigid3d
object or an affine3d
object. See Define Transformation Matrix
for details on how to set up an affine 3-D tform
input.
D
— Displacement field
M-by-3 matrix | M-by-N-by-3 array
Displacement field, specified as either M-by-3 or an
M-by-N-by-3 array. The
displacement field is a set of displacement vectors that specify the
magnitude and direction of translation for each point in the point cloud.
The size of the displacement field must be the same as the size of the
Location
property of the pointCloud
object.
Data Types: single
| double
Output Arguments
ptCloudOut
— Transformed point cloud
pointCloud
object
Transformed point cloud, returned as a pointCloud
object. The
transformation applies to the coordinates of points and their normal
vectors.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Version History
See Also
Objects
pointCloud
|planeModel
|affine3d
|rigid3d
Functions
pcplayer
|pcshow
|pcwrite
|pcread
|pcmerge
|pcdownsample
|pcfitplane
|pcdenoise
|pcregistericp
|pccat
|pcalign
Ouvrir l'exemple
Vous possédez une version modifiée de cet exemple. Souhaitez-vous ouvrir cet exemple avec vos modifications ?
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)