[Tutor] What Centroid Algorithm Is This?
Wayne Watson
sierra_mtnview at sbcglobal.net
Mon Jan 26 19:20:28 CET 2009
I'm looking at a GUI program that handles meteor images. They leave a trail
across the sky. Each video frame (30 fps) provides data on the track, and a
centroid is found around each track point. 'm not familiar with the
algorithm that does this, but part of it is in the three def stmts below.
Maybe someone can hazard a guess? It looks like someone had fun doing this.
def MakeSelectsAndWeights( self ):
global SELECT1, SELECT2
global WEIGHT1, WEIGHT2
a1 = indices((640,))[0]
a2 = a1 + a1 * (701.0-640.0)/702.0
a3 = floor(a2)
SELECT1 = a3.astype( intc )
SELECT2 = SELECT1 + 1
WEIGHT2 = a2 - a3
WEIGHT1 = 1.0 - WEIGHT2
One more
def Centroid( self, ref, curr, mask ):
slopes = indices((488,722),int32)
nada = zeros((488,722),uint8)
result = where(curr > ref, curr-ref, nada)
result = where(result > mask, result-mask, nada)
xresult = 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,count
Another
def Central( self, ref, curr, mask ):
slopes = indices((488,722),int32)
nada = zeros((488,722),uint8)
result = where(curr > ref, curr-ref, nada)
result = where(result > mask, result-mask, nada)
total = sum(ravel(asarray(result,int32)))
count = sum(ravel(result > 0))
if total == 0:
print "Count: %d Total: %d" % (count,total)
return 361,244,0,0
blur = result[0:-2, 0:-2]
blur += result[0:-2, 1:-1]
blur += result[0:-2, 2: ]
blur += result[1:-1, 0:-2]
blur += result[1:-1, 1:-1]
blur += result[1:-1, 2: ]
blur += result[2: , 0:-2]
blur += result[2: , 1:-1]
blur += result[2: , 2: ]
index = argmax(ravel(blur))
ypos, xpos = divmod(index, 720)
xpos += 1
ypos += 1
return xpos,ypos,total,count
--
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/>
More information about the Tutor
mailing list