<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thanks for the annotations and references. I see a fair number of
functions in Numpy, but none called centroid. Is there a name for this
particular algorithm? I suspect there are many such methods. It looks
like there many be several concepts at play here that fit together into
a whole. I may have to get out my really old Num Recipies book. :-)<br>
<br>
Eike Welk wrote:
<blockquote cite="mid:200901262120.55668.eike.welk@gmx.net" type="cite">
  <pre wrap="">On Monday 26 January 2009, Wayne Watson wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">the three def stmts below. Maybe someone can hazard a guess? It
looks like someone had fun doing this.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
First bookmark this webpage. It explains every important function in 
Numpy:
<a class="moz-txt-link-freetext" href="http://www.scipy.org/Numpy_Example_List_With_Doc">http://www.scipy.org/Numpy_Example_List_With_Doc</a>

  </pre>
  <blockquote type="cite">
    <pre wrap="">     def Centroid( self, ref, curr, mask ):
    </pre>
  </blockquote>
  <pre wrap=""><!---->ref is maybe dark frame
  </pre>
  <blockquote type="cite">
    <pre wrap="">         slopes = indices((488,722),int32)
         nada   = zeros((488,722),uint8)

    </pre>
  </blockquote>
  <pre wrap=""><!---->Do discrimination; areas that are not covered by the meteor are 0
  </pre>
  <blockquote type="cite">
    <pre wrap="">         result = where(curr &gt; ref, curr-ref, nada)
         result = where(result &gt; mask, result-mask, nada)

    </pre>
  </blockquote>
  <pre wrap=""><!---->
Compute center of mass
<a class="moz-txt-link-freetext" href="http://en.wikipedia.org/wiki/Center_of_mass#Definition">http://en.wikipedia.org/wiki/Center_of_mass#Definition</a>
Look at first formula 
- result is m
- slopes[1] is x-component of r
- slopes[0] is y-component of r
  </pre>
  <blockquote type="cite">
    <pre wrap="">         xresult = result * slopes[1]
         yresult = result * slopes[0]
         total   = sum(ravel(asarray(result,int32)))
         count   = sum(ravel(result &gt; 0))
         if total == 0:
             return 360,240,0,0

         xpos = sum(ravel(xresult))/total
         ypos = sum(ravel(yresult))/total

         return xpos,ypos,total,count
    </pre>
  </blockquote>
  <pre wrap=""><!---->

Example algorithm done in Ipython invoked with
ipython --pylab
----
In [20]:weights = array([0,0,1,1,1],'d')
#These are three weights of mass 1. 
#They are located at the positions 2, 3, 4. 
#The center of gravity is therefore at position 3.

In [21]:distances = indices(weights.shape)

In [22]:distances
Out[22]:array([[0, 1, 2, 3, 4]])

In [23]:moments = weights * distances

In [24]:moments
Out[24]:array([[ 0.,  0.,  2.,  3.,  4.]])

In [25]:tot_weight = sum(weights)

In [26]:tot_moment = sum(moments)

In [27]:center = tot_moment/tot_weight

In [28]:center
Out[28]:3.0
#Yay, this is the correct result!


Kind regards,
Eike.
_______________________________________________
Tutor maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:Tutor@python.org">Tutor@python.org</a>
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a>

  </pre>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<meta content="text/html;" http-equiv="Content-Type">
<title>Signature.html</title>
<pre class="moz-signature" cols="76">           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
<font color="#330099">            </font>
<b><b style="color: rgb(204, 51, 204);" class="b">       <span
 style="font-family: monospace; color: rgb(153, 51, 153);">  Copper and its alloys have been found effective in hospital
         sinks, hand rails, beds, ... in significantly reducing 
         bacteria. Estimates are 1/20 people admitted to a hospital
         become infected, and 1/20 die from the infection.
                       -- NPR Science Friday, 01/16/2009 
</span></b></b><b style="color: rgb(204, 51, 204);" class="b"><span
 style="font-family: monospace; color: rgb(153, 51, 153);"></span></b><span
 style="color: rgb(153, 51, 153);"></span><span
 style="color: rgb(153, 51, 153);">
</span><span style="color: rgb(153, 51, 153);"></span><b
 style="color: rgb(204, 51, 204);" class="b"><span
 style="font-family: monospace;"></span></b><span
 style="color: rgb(204, 51, 204);"></span>                    Web Page: &lt;<a class="moz-txt-link-abbreviated" href="http://www.speckledwithstars.net/">www.speckledwithstars.net/</a>&gt;</pre>
</div>
</body>
</html>