发布于 2013-04-19 06:32:52
没有一个例子很难回答,但听起来你只是想要执行一个montecarlo模拟
假设您的形状是由函数f定义的,并且您的X,Y限制存储在两个元素向量中,例如xlim =-1010,即这个形状的所有可能的x值都在x= -10和x= 10之间,那么我建议如果一个特定的say对没有值,f会返回某种错误代码。我假设那将是NaN。因此,f(x,y)是一个您正在编写的函数,如果可以返回z,如果不能返回NaN
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因此,上面的代码将生成10000 (非唯一的,但这很容易适应)点随机抽样在您的形状。
现在,在输入这个之后,我意识到也许你的形状实际上并不那么大,也许你可以对它进行均匀的采样,而不是随机的:
for x = xlim(1):xstep:xlim(2)
for y = ylim(1):ystep:ylim(2)
shape(counter, :) = [x, y, f(x,y)];
end
end 或者如果您编写f以被矢量化(更好)
shape = [(xlim(1):xstep:xlim(2))', (ylim(1):ystep:ylim(2))', f(xlim(1):xstep:xlim(2), ylim(1):ystep:ylim(2));然后不管是哪种
shape(isnan(shape(:, 3), :) = []; %remove the points that fell outside the shape发布于 2013-04-19 12:52:36
下面是用PrimeSense摄像机的深度图像创建云图像的代码。
此功能的输入/输出:
-inputs
depth -depth map
topleft -topleft coordinates of the segmented image in the whole image
-outputs
pclouds -3d point cloudsMatLab代码:
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));编辑:此源来自当前的文章http://www.cs.washington.edu/rgbd-dataset/software.html
您可以在MatLab和C++中找到其他您感兴趣的云函数。
https://stackoverflow.com/questions/16098209
复制相似问题