Re: Calculating the Center of Mass of a 3D Binary Array/Matrix
- From: Lazyrussian <lazyrussian@xxxxxxxxx>
- Date: Sat, 10 Nov 2007 08:23:12 -0000
On Nov 9, 5:01 pm, Peter Boettcher <boettc...@xxxxxxxxxx> wrote:
Lazyrussian <lazyruss...@xxxxxxxxx> writes:
On Nov 9, 2:17 pm, Peter Boettcher <boettc...@xxxxxxxxxx> wrote:
Lazyrussian <lazyruss...@xxxxxxxxx> writes:
I've finished with steps 1 and 2 (quite easy).
I wanted to do the following (not using the sum matlab function =
sum() represents equals large-sigma with bounds)
A = sum(mx)/M
B = sum(my)/M
C = sum(mz)/M
where m = mass (or the value at the specified coordinate)
where x = the x (or first) dimension
where y = the y (or second) dimension
where z = the z (or third) dimension
where M = total mass over three dimensions (easy to do using a triple
sum function in matlab)
where (A,B,C) = will equal the new coordinates (in decimal format),
but multiplying them by a multiplicative factor shoudl fix that ( a
total guess)
Major problems:
I am keeping the two coordinates that I'm not summing over at a
constant number (i.e. zero)
If I do this, then all I am adding up/summing over are the outer edges
of the matrix which don't contain the tumor (I know this for a fact).
Right. You actually need to sum ALL values for each of the coordinates,
not just a single plane. Think of computing each coordinate (x,y, and
z) independently. Each component actually looks like a triple sum, over
x, and y, and z. On the inside, just as you've written it, is
x*m(x,y,z). This for the x component of the centroid. Then again for
the y and the z.
After that, you can note that when you program it, you can accumulate
all of the components into their own variables in the inner loop.
Finally, in MATLAB, the vectorized version would have you multiply the
entire 3D field with another one that has the value of the x index in
all the right elements. See "meshgrid" to help with that. Then you
just sum all elements in all 3 dimensions. Then do it again for y, and
for z.
After researching on the internet, I have come to the conclusion that
I am dealing with a centroid, something which I have never seen in my
life.
Based on your description, you are.
-Peter
Peter, I've typed up about a 70 line code (with comments). It
calculates the center of mass as if it weren't a plane. I also have 20
lines of code or so that are commented out that sum over the whole
tumor.
I've uploaded it to my site - would you mind checking it out, or
helping me out with the actual coding (I self-taught myself this
language without any manual/help guide), so I only know so much.
I took a look, but the code doesn't seem to have a triple sum...
How's this:
data = <your data>
for z=1:size(data,3)
for y=1:size(data,2)
for x=1:size(data,1)
sum_x = sum_x + x*data(x,y,z);
sum_y = sum_y + y*data(x,y,z);
sum_z = sum_z + z*data(x,y,z);
end
end
end
"Vectorizing" left as an exercise to the reader. By the way, the MATLAB
manuals are all available for free online. It might help you to read
through some of those.
-Peter
Thanks for your help. I've actually read up on an easier way of
finding the center of mass using the FIND command to get all the tumor
coordinates in 2D and looping it to get the total in 3D.
Thanks again!
.
- Follow-Ups:
- References:
- Calculating the Center of Mass of a 3D Binary Array/Matrix
- From: Lazyrussian
- Re: Calculating the Center of Mass of a 3D Binary Array/Matrix
- From: Peter Boettcher
- Re: Calculating the Center of Mass of a 3D Binary Array/Matrix
- From: Lazyrussian
- Re: Calculating the Center of Mass of a 3D Binary Array/Matrix
- From: Peter Boettcher
- Calculating the Center of Mass of a 3D Binary Array/Matrix
- Prev by Date: Rate-compatible punctured convolutional codes
- Next by Date: Re: Showing multiple figures simultaneously
- Previous by thread: Re: Calculating the Center of Mass of a 3D Binary Array/Matrix
- Next by thread: Re: Calculating the Center of Mass of a 3D Binary Array/Matrix
- Index(es):
Relevant Pages
|
Loading