Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Math Forum
»
Discussions
»
Software
»
comp.softsys.matlab
Notice: We are no longer accepting new posts, but the forums will continue to be readable.
Topic:
Problems during Generation of a Spherical Point Cloud
Replies:
2
Last Post:
Jul 24, 2010 11:45 PM




Problems during Generation of a Spherical Point Cloud
Posted:
Jul 23, 2010 4:08 AM


Hi, all,
I am new to Matlab and using it for image processing. I am writing a function to generate a point cloud of a sphere on a 3D image the size of which is same as the input image BW. Another input XYZD is a 4element vector containing the X,Y and Z positions of the center point and the diameter of the sphere. The output of the function SphereBW is the new 3D image with the sphere point cloud.
The code is pasted below:
function SphereBW=XYZD2Sphere(BW,XYZD)
SphereBW=false(size(BW,1),size(BW,2),size(BW,3));
cx=XYZD(1);cy=XYZD(2);cz=XYZD(3);diameter=XYZD(4); for x=1:size(BW,1) for y=1:size(BW,2) for z= 1:size(BW,3) if (xcx)^2+(ycy)^2+(zcz)^2<(diameter/2)^2 SphereBW(x,y,z)=1; end end end end
end
But the sphere I generate is put to a wrong location in the new image where it seems that the X and Y coordinates are swapped. e.g. if my input BW size is [512 512 100] and XYZD vector is [250 150 50 30] the center point of the sphere locates at [150 250 50] in the output image SphereBW.
Please help me to figure out what is wrong with my function. If you know how to write any other elegant codes (without for loops), please teach me as well.
Many thanks!!!
Joseph



