How can I convert a file format FIG to PCD?

Hi.
I'm new to matlab. I did the following to edit point cloud data.
ptCloud=pcread(filename)
pcshow(ptCloud)
After editing, the data is saved as a FIG file, how can I convert it to a PCD file?

 Accepted Answer

There is a function called pcwrite. The MATLAB documentation has a good article on it.

14 Comments

fig files contain the complete information about the graphics objects, including the size of the figure, the position of the axes, the format to be used for the axes tick marks. Most of that information cannot be saved to pcd. If you are working with a fig file you need to findobj() the pointCloud from the figure, and extract the data from it, and pcwrite()
Thank you Walter and Benjamin.
I want to save this point cloud data as pcd files. I'd like to know the specific code.
Untested.
fig = openfig('NameOfFig.fig');
outnamebase = "pcout_";
pcviewers = findobj(fig, 'tag', 'pcviewer');
for K = 1 : length(pcviewers)
x = pcviewers(K).XData;
y = pcviewers(K).YData;
z = pcviewers(K).ZData;
C = pcviewers(K).CData;
xyz = [x,y,z];
ptc = pointCloud(xyz, 'Color', C);
outname = outnamebase + K + ".pcd";
pcwrite(ptc, outname);
end
This writes all point clouds that are in the figure. It has to reconstruct them as fig files store Scatter objects rather than pointCloud objects.
Sorry for the late reply.
I ran the code and got the following error. Do you know how to solve this problem?
The first error statement reads "Invalid argument for the position 1. The size of oh the input 'xyzPoints' must be an M-by-3 list of points or an M-by-N-by-3 array for an organized point cloud."
The first error statement reads " 'Color' must correspond to the number of input points. "
Could you show size(x) and size(C)?
I have seen some cases where the XData was a 2d matrix instead of a vector, but I have not figured out how that could be, as all the pointCloud code I have looked at expects it to be a vector.
What is class(C) and min() and max(C)?
Thanks for the quick reply.
How can I check? Do I type in the code or check the fig file?
put a breakpoint on the line
ptc = pointCloud(xyz, 'Color', C);
and run the code. When it gets there, in the command window type in
whos x C
min(C(:)), max(C(:))
and show us the results
Try this
fig = openfig('NameOfFig.fig');
outnamebase = "pcout_";
pcviewers = findobj(fig, 'tag', 'pcviewer');
for K = 1 : length(pcviewers)
x = pcviewers(K).XData;
y = pcviewers(K).YData;
z = pcviewers(K).ZData;
C = pcviewers(K).CData;
xyz = [x(:),y(:),z(:)];
if size(C,2) == 1
ptc = pointCloud(xyz, 'Intensity', C);
else
ptc = pointCloud(xyz, 'Color', C);
end
outname = outnamebase + K + ".pcd";
pcwrite(ptc, outname);
end
Wow! You are amazing!
I have one question.
I made a pcd file after deleting point clouds, but looking at the contents of 'pcout_1.pcd', there are still 1,832 point clouds.
Does this mean that point clouds disappear visually, but point clouds remain in terms of internal information?
There are 1832 points in one point cloud.
You might want to change the colormap to highlight more of the points. There are a lot of dark blue points in the front right.
OH, I see.
fig = openfig('NameOfFig.fig'); outnamebase = "pcout_"; pcviewers = findobj(fig, 'tag', 'pcviewer'); for K = 1 : length(pcviewers) x = pcviewers(K).XData; y = pcviewers(K).YData; z = pcviewers(K).ZData; C = pcviewers(K).CData; xyz = [x(:),y(:),z(:)]; if size(C,2) == 1 ptc = pointCloud(xyz, 'Intensity', C); else ptc = pointCloud(xyz, 'Color', C); end outname = outnamebase + K + ".pcd"; pcwrite(ptc, outname); end
↑ I would like to know more about what each line of this code does.

Sign in to comment.

More Answers (0)

Products

Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!