Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
points in voxels

Subject: points in voxels

From: Eli

Date: 19 Nov, 2009 00:29:18

Message: 1 of 5

Dear Matlab users,
I am trying to write a program that could efficiently determine which voxel a point in space lies inside.
Supposing I have a 3 dimensional cube in space, that is segmented into n^3 smaller voxels. Each of these voxels will have an index ranging from 1:n^3 and each voxel centre can be determined easily.
No suppose I take p number of random points with coordinates (Xp,Yp,Zp) located somewhere inside the big cube.
I would really appreciate suggestions to writing a very efficient code to determine which voxel index each of these points lie inside.
At this point I have an array Mapper, with dimensions (n^3,3) indicating the centre of each small voxel.
Thanks very much,
-Eli

Subject: points in voxels

From: ImageAnalyst

Date: 19 Nov, 2009 02:43:29

Message: 2 of 5

On Nov 18, 7:29 pm, "Eli " <elech...@ryerson.ca> wrote:
> Dear Matlab users,
> I am trying to write a program that could efficiently determine which voxel a point in space lies inside.
> Supposing I have a 3 dimensional cube in space, that is segmented into n^3 smaller voxels. Each of these voxels will have an index ranging from 1:n^3 and each voxel centre can be determined easily.
> No suppose I take p number of random points with coordinates (Xp,Yp,Zp) located somewhere inside the big cube.
> I would really appreciate suggestions to writing a very efficient code to determine which voxel index each of these points lie inside.
> At this point I have an array Mapper, with dimensions (n^3,3) indicating the centre of each small voxel.
> Thanks very much,
> -Eli

---------------------------------------------------------------------------------------
You need to use the sub2ind() function. For example:

workspace; % Show the Workspace panel.
voxels = zeros(3,4,5) % Create a 3D array - I don't care what values
it has.
% Find index of voxel at (x,y,z) = (1,1,1).
index1 = sub2ind(size(voxels), 1,1,1)
% Find index of voxel at (x,y,z) = (1,2,4).
index2 = sub2ind(size(voxels), 1,2,4)
% Find index of voxel at (x,y,z) = (3,4,5).
index3 = sub2ind(size(voxels), 3,4,5)

Subject: points in voxels

From: Eli

Date: 19 Nov, 2009 03:03:03

Message: 3 of 5

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <dba81928-387f-46d6-a867-e5d56468d3c8@g23g2000yqh.googlegroups.com>...
> On Nov 18, 7:29?pm, "Eli " <elech...@ryerson.ca> wrote:
> > Dear Matlab users,
> > I am trying to write a program that could efficiently determine which voxel a point in space lies inside.
> > Supposing I have a 3 dimensional cube in space, that is segmented into n^3 smaller voxels. Each of these voxels will have an index ranging from 1:n^3 and each voxel centre can be determined easily.
> > No suppose I take p number of random points with coordinates (Xp,Yp,Zp) located somewhere inside the big cube.
> > I would really appreciate suggestions to writing a very efficient code to determine which voxel index each of these points lie inside.
> > At this point I have an array Mapper, with dimensions (n^3,3) indicating the centre of each small voxel.
> > Thanks very much,
> > -Eli
>
> ---------------------------------------------------------------------------------------
> You need to use the sub2ind() function. For example:
>
> workspace; % Show the Workspace panel.
> voxels = zeros(3,4,5) % Create a 3D array - I don't care what values
> it has.
> % Find index of voxel at (x,y,z) = (1,1,1).
> index1 = sub2ind(size(voxels), 1,1,1)
> % Find index of voxel at (x,y,z) = (1,2,4).
> index2 = sub2ind(size(voxels), 1,2,4)
> % Find index of voxel at (x,y,z) = (3,4,5).
> index3 = sub2ind(size(voxels), 3,4,5)

thanks for the help, but I think you misunderstood my problem.
I am able to index the voxels. but suppose I choose a random point (x,y,z), which will not in general have integer values, and will not in general lie in the centre of the voxel. I wish to find which voxel this point falls in. What I am doing now. is calculating the difference between my point and the centres of all voxels, and then finding the minimum distance, however, this is quite computationally heavy. Is there a faster way to determine in which voxel index my point falls?
-Eli

Subject: points in voxels

From: alecive

Date: 22 Mar, 2012 13:12:12

Message: 4 of 5

"Eli " <elechtma@ryerson.ca> wrote in message <he2ch7$7gm$1@fred.mathworks.com>...
> thanks for the help, but I think you misunderstood my problem.
> I am able to index the voxels. but suppose I choose a random point (x,y,z), which will not in general have integer values, and will not in general lie in the centre of the voxel. I wish to find which voxel this point falls in. What I am doing now. is calculating the difference between my point and the centres of all voxels, and then finding the minimum distance, however, this is quite computationally heavy. Is there a faster way to determine in which voxel index my point falls?
> -Eli

Hi Eli,

I have the same problem as yours. Did you solve by yourself such an issue? I think that the workaround you proposed works only if the voxel is a sphere around the central point, but if you have a squared voxel the problem is not fully solved.

Subject: points in voxels

From: Roger Stafford

Date: 22 Mar, 2012 17:12:12

Message: 5 of 5

"Eli " <elechtma@ryerson.ca> wrote in message <he23gu$5bv$1@fred.mathworks.com>...
> Dear Matlab users,
> I am trying to write a program that could efficiently determine which voxel a point in space lies inside.
> Supposing I have a 3 dimensional cube in space, that is segmented into n^3 smaller voxels. Each of these voxels will have an index ranging from 1:n^3 and each voxel centre can be determined easily.
> No suppose I take p number of random points with coordinates (Xp,Yp,Zp) located somewhere inside the big cube.
> I would really appreciate suggestions to writing a very efficient code to determine which voxel index each of these points lie inside.
> At this point I have an array Mapper, with dimensions (n^3,3) indicating the centre of each small voxel.
> Thanks very much,
> -Eli
- - - - - - - - -
  You haven't specified the scale factors used in your x, y, z coordinates of points within your "3 dimensional cube in space". However, assuming the voxel cubes are all the same size, there must exist constants ax,ay,az and bx,by,bz such that ix = round(ax*Xp+bx), iy = round(ay*Yp+by), and iz = round(az*Zp+bz) give you the indices of the corresponding voxel. Then as imageAnalyst says, you can use 'sub2ind' to find the corresponding linear index, or else you can use the expression i = ix+n*((iy-1)+n*(iz-1)) for that purpose. (Actually you could adjust the y and z constants so as to avoid the -1 subtractions.)

  Why do you prefer the linear index to subscript indices?

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us