Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Problems during Generation of a Spherical Point Cloud
Replies: 2   Last Post: Jul 24, 2010 11:45 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
maniacWaltz

Posts: 16
Registered: 4/10/08
Problems during Generation of a Spherical Point Cloud
Posted: Jul 23, 2010 4:08 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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 4-element 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 (x-cx)^2+(y-cy)^2+(z-cz)^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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.