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,
similarity, or affine transformation.
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 transformation object with a 45 degree rotation along the z-axis.
rotationAngles = [0 0 45]; translation = [0 0 0]; tform = rigidtform3d(rotationAngles,translation);
Transform the point cloud.
ptCloudOut = pctransform(ptCloud,tform);
Plot the transformed point cloud.
figure pcshow(ptCloudOut) xlabel('X') ylabel('Y') zlabel('Z')
Rigid and Nonrigid Transformations of 3-D Point Cloud
This example applies a rigid transformation (rotation) and a nonrigid transformation (shear) to a 3-D point cloud.
Read a point cloud into the workspace.
ptCloud = pcread('teapot.ply');
Plot the original 3-D point cloud.
figure1 = figure; axes1 = axes(Parent=figure1); pcshow(ptCloud,Parent=axes1,AxesVisibility='on'); xlabel('X'); ylabel('Y'); zlabel('Z'); title('3-D Point Cloud',FontSize=14)
Rotation of 3-D Point Cloud
Create a rigid transformation object that defines a 45 degree rotation along the z-axis.
rotationAngles = [0 0 45]; translation = [0 0 0]; tform = rigidtform3d(rotationAngles,translation);
Transform the point cloud.
ptCloudOut1 = pctransform(ptCloud,tform);
Plot the rotated point cloud.
figure2 = figure; axes2 = axes(Parent=figure2); pcshow(ptCloudOut1,Parent=axes2,AxesVisibility='on'); xlabel('X'); ylabel('Y'); zlabel('Z'); title({'Rotation of 3-D Point Cloud'},FontSize=14)
Shearing of 3-D point cloud
Create an affine transformation object that defines shearing along the x-axis.
A = [1 0.75 0.75 0; ... 0 1 0 0; ... 0 0 1 0; ... 0 0 0 1]; tform = affinetform3d(A);
Transform the point cloud.
ptCloudOut2 = pctransform(ptCloud,tform);
Plot the transformed point cloud.
figure3 = figure; axes3 = axes(Parent=figure3); pcshow(ptCloudOut2,Parent=axes3,AxesVisibility='on'); 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
rigidtform3d
object | simtform3d
object | affinetform3d
object
3-D geometric transformation, specified as a rigidtform3d
, simtform3d
, or affinetform3d
object. See Specify 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
Introduced in R2015aR2022b: Supports new geometric transformation objects
Starting in R2022b, most Computer Vision Toolbox™ functions create and perform geometric transformations using the
premultiply convention. Accordingly, you can now specify tform
as a rigidtform3d
, simtform3d
, or affinetform3d
object, which use the premultiply convention.
Although you can still specify tform
as a rigid3d
object or an affine3d
object, these objects are
not recommended because they use the postmultiply convention. You can streamline
your geometric transformation workflows by switching to the new premultiply
geometric transformation objects. For more information, see Migrate Geometric Transformations to Premultiply Convention.
See Also
Objects
Functions
pcplayer
|pcshow
|pcwrite
|pcread
|pcmerge
|pcdownsample
|pcfitplane
|pcdenoise
|pcregistericp
|pccat
|pcalign
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)