# Coordinates of centre of gravity

Hi,

I want to analyze a matrix (1 plane, 2 dimensions) and get coordinates of the centre of gravity. I can’t really explain it much clearer but here’s an example of what I want:

input:

1 0 0

0 0 1

0 0 0

output:

x=1, y=0.5

Another example:

2 0 0

0 0 1

0 0 0

output:

x=0.66, y=0.33

…I hope this is clear?

I think that the calculations should be something like this:

(0 * sum of all cells in row 0/ sum of all cells in matrix) +

(1 * sum of all cells in row 1/ sum of all cells in matrix) +

etc. = y

… and of course the same thing goes for the columns.

But how can I do this efficiently?

- Tarik

I think there might be an object in cv.jit that does this calculation

for you… cv.jit.centroid.

wes

On 11/23/06, Tarik

>

> Hi,

>

> I want to analyze a matrix (1 plane, 2 dimensions) and get coordinates of the centre of gravity. I can’t really explain it much clearer but here’s an example of what I want:

>

> input:

>

> 1 0 0

> 0 0 1

> 0 0 0

>

> output:

>

> x=1, y=0.5

>

> Another example:

>

> 2 0 0

> 0 0 1

> 0 0 0

>

> output:

>

> x=0.66, y=0.33

>

>

> …I hope this is clear?

>

> I think that the calculations should be something like this:

>

> (0 * sum of all cells in row 0/ sum of all cells in matrix) +

> (1 * sum of all cells in row 1/ sum of all cells in matrix) +

> etc. = y

>

> … and of course the same thing goes for the columns.

>

> But how can I do this efficiently?

>

>

> – Tarik

>

I’m not sure yet on how to use FTM for this kind of calculations but I’ll find out. And thanks for the tip, ’cause FTM seems to be a BIG improvement in the max-world! I haven’t heard of it before…

– T

cv.jit.centroids does do that. also tap.jit.sum, I think.