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. :-) Eike Welk wrote: On Monday 26 January 2009, Wayne Watson wrote:the three def stmts below. Maybe someone can hazard a guess? It looks like someone had fun doing this.First bookmark this webpage. It explains every important function in Numpy: http://www.scipy.org/Numpy_Example_List_With_Docdef Centroid( self, ref, curr, mask ):ref is maybe dark frameslopes = indices((488,722),int32) nada = zeros((488,722),uint8)Do discrimination; areas that are not covered by the meteor are 0result = where(curr > ref, curr-ref, nada) result = where(result > mask, result-mask, nada)Compute center of mass http://en.wikipedia.org/wiki/Center_of_mass#Definition Look at first formula - result is m - slopes[1] is x-component of r - slopes[0] is y-component of rxresult = result * slopes[1] yresult = result * slopes[0] total = sum(ravel(asarray(result,int32))) count = sum(ravel(result > 0)) if total == 0: return 360,240,0,0 xpos = sum(ravel(xresult))/total ypos = sum(ravel(yresult))/total return xpos,ypos,total,countExample 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 - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor --
Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) 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 Web Page: <www.speckledwithstars.net/> |
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor