3

I have a 3d map or matrix and I want to construct the point cloud from it. I've already done that using this code:

function [pcloud, distance] = depthToCloud(depth, topleft)
% depthToCloud.m - Convert depth image into 3D point cloud
% Author: Liefeng Bo and Kevin Lai
%
% Input: 
% depth - the depth image
% topleft - the position of the top-left corner of depth in the original depth image. Assumes depth is uncropped if this is not provided
%
% Output:
% pcloud - the point cloud, where each channel is the x, y, and z euclidean coordinates respectively. Missing values are NaN.
% distance - euclidean distance from the sensor to each point
%

if nargin < 2
    topleft = [1 1];
end

depth= double(depth);
depth(depth == 0) = nan;

% RGB-D camera constants
center = [320 240];
[imh, imw] = size(depth);
constant = 570.3;
MM_PER_M = 1000;

% convert depth image to 3d point clouds
pcloud = 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);
pcloud(:,:,1) = xgrid.*depth/constant/MM_PER_M;
pcloud(:,:,2) = ygrid.*depth/constant/MM_PER_M;
pcloud(:,:,3) = depth/MM_PER_M;
%distance = sqrt(sum(pcloud.^2,3));

but I'm asking if there is any more efficient way? Also after constructing the point cloud I want to get the normal of each point and I used the built-in matlab function surfnorm but its takes a lot of processing time. So if anyone could assist me do this a better and more efficient way.

Tak
  • 3,536
  • 11
  • 51
  • 93
  • What is the size of your image and what OS do you have? – Oleg Jul 28 '13 at 10:40
  • 640x480 and I'm working on windows – Tak Jul 28 '13 at 10:51
  • The code looks efficient. Have you tried to `profile` your script to see what is taking much time? – Oleg Jul 28 '13 at 11:02
  • Yes I know, thats why I'm asking if any expert can assist me. Any solutions for getting the normal of each 3d point? – Tak Jul 28 '13 at 13:21
  • Saying that it takes a lot of processing time is not sufficient. While you might think it should take less it might well be taking the necessary time. Please [profile](http://www.mathworks.co.uk/help/matlab/matlab_prog/profiling-for-improving-performance.html) your script to detect the bottleneck, and then post results back. – Oleg Jul 28 '13 at 16:03
  • @OlegKomarov for surfnorm function its a built-in Matlab function and I don't know how it works that's why I'm asking if there is any other solution to get the normals of each 3D point – Tak Jul 29 '13 at 02:59
  • you could always try using gpuarray and the parallel processing toolbox to speed it up – slam_duncan Sep 30 '14 at 16:03
  • Can anyone tell me what the RGB-D camera parameters are all about ? I am trying to compute 3D point clouds for some depth kinect images that have been made available to me but I do not know the parameters. – roni Oct 03 '15 at 07:42

0 Answers0