The Math Forum

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.soft-sys.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

Advanced Search

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

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

Hi, Nic,

Thanks for your help.


I want to generate a binary point cloud of a sphere in an array as same size as the input BW. The XYZD is a 4-element vector. The first 3 elements are the XYZ coordinates of the sphere's center point and the 4th element is the diameter of the sphere.

For example:
SphereArray=XYZD2Sphere(false(128,128,128),[50 60 70 30]);

will get an output SphereArray a 128-128-128 binary array with a 30-cm diameter sphere (trues) located around center point [50 60 70].

But now the sphere centers at [60 50 70]. I guess the x and y axis swap. I cannot find the errors from the code.

"Nic Roberts" <> wrote in message <i2bpem$9ug$>...
> Hi Joseph
> It isnt imediatly apparent from your code what it is you are trying to achieve. When I run your code I just get a massive array of zeros. Is your intent to remove a sphere of data from BW?
> Nic
> "Joseph " <> wrote in message <i2bil4$aqh$>...

> > 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]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.