Vicious cloud

  • I have a three-dimensional geometric shape that I have to convert to a point cloud.
  • The resulting point cloud can be considered equivalent to a point cloud obtained from laser scanning of an object.
  • No mesh generation
  • The generated points can be evenly distributed or maybe just randomly spaced - it does not matter
  • The three-dimensional form can be represented as a three-dimensional mathematical formula
  • This must be done using MATLAB.
+3
matlab point-clouds
source share
2 answers

It is hard to answer without an example, but it looks like you just want to perform a montecarlo simulation ?

Suppose your shape is defined by the function f and that you have limits X, Y stored in two element vectors, for example. xlim = [-10 10], that is, all possible x values โ€‹โ€‹of this form lie between x = -10 and x = 10, then I would suggest that you do f return some error code if there is no value for a particular xy pair. I guess it will be NaN . So f(x,y) is the function you write, either returns z if it can, or NaN if it cannot

 n= 10000; counter = 1; shape = nan(n, 3) while counter < n x = rand*diff(xlim) + mean(xlmin); y = rand*diff(ylim) + mean(ylim); z = f(x,y) if ~isnan(z) shape(counter, :) = [x, y, z]; counter = counter + 1 end end 

Thus, the above code will generate 10,000 (not unique, but easily adapted) points of random sampling according to your form.

Now, having typed this, I understand that maybe your figure is actually not that big, and maybe you can evenly try it out, and not randomly:

 for x = xlim(1):xstep:xlim(2) for y = ylim(1):ystep:ylim(2) shape(counter, :) = [x, y, f(x,y)]; end end 

or if you write f for vectorization (preferred)

 shape = [(xlim(1):xstep:xlim(2))', (ylim(1):ystep:ylim(2))', f(xlim(1):xstep:xlim(2), ylim(1):ystep:ylim(2)); 

and then anyway

 shape(isnan(shape(:, 3), :) = []; %remove the points that fell outside the shape 
+4
source share

Here is the code for creating a cloud image with a depth image from a PrimeSense camera.

Input / output of this function:

 -inputs depth -depth map topleft -topleft coordinates of the segmented image in the whole image -outputs pclouds -3d point clouds 

MatLab Code:

 depth = double(depth); % Size of camera image center = [320 240]; [imh, imw] = size(depth); constant = 570.3; % convert depth image to 3d point clouds pclouds = zeros(imh,imw,3); xgrid = ones(imh,1)*(1:imw) + (topleft(1)-1) - center(1); ygrid = (1:imh)'*ones(1,imw) + (topleft(2)-1) - center(2); pclouds(:,:,1) = xgrid.*depth/constant; pclouds(:,:,2) = ygrid.*depth/constant; pclouds(:,:,3) = depth; distance = sqrt(sum(pclouds.^2,3)); 

Edit: this source from this article http://www.cs.washington.edu/rgbd-dataset/software.html

You can find another Cloud feature in MatLab and C ++ that might interest you.

+1
source share

All Articles