def suppress_nonmaxima(self, r=7): """ Removes from this cluster all points within *r* pixels of a point with greater intensity. In the case of a tie, only the ``last-encountered'' tied point is preserved. """ local_maxima = [] for p in self.points: z_p = get_z(p) neighbor_zs = [ get_z(q) for q in self.points if q != p and sqdist(p, q) < r**2 ] if neighbor_zs == list(): local_maxima.append(p) else: z_max = max(neighbor_zs) if z_p > z_max: local_maxima.append(p) elif z_p == z_max: # eliminate tie set_z(p, 0) self.points = local_maxima
def suppress_nonmaxima(self, r=7): """ Removes from this cluster all points within *r* pixels of a point with greater intensity. In the case of a tie, only the ``last-encountered'' tied point is preserved. """ local_maxima = [] for p in self.points: z_p = get_z(p) is_max = True tie = False for q in [ other for other in self.points if other != p ]: z_q = get_z(q) if sqdist(p, q) < r**2: if z_q > z_p: is_max = False elif z_q == z_p: is_max = False tie = True if is_max: # count it local_maxima.append(p) elif tie: # eliminate tie set_z(p, 0) self.points = local_maxima
def highpass_filter(self, threshold=0.5): """ todo """ z_max = max([ get_z(point) for point in self.points ]) z_cutoff = z_max * threshold highpoints = [] for point in self.points: if get_z(point) > z_cutoff: highpoints.append(point) self.points = highpoints
def calc_center(self): """ Finds the average coordinates of *self.points*, weighted by pixel intensity, and saves them in *self.center*. """ N = 0 Ex = 0 Ey = 0 for point in self.points: x = get_x(point) y = get_y(point) z = get_z(point) N += z Ex += z*x Ey += z*y self.prevcenter = self.center self.center = Point(Ex/N, Ey/N)