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 remove_geographic_outliers(self): avg_nn = 0 for p in self.points: avg_nn += sqrt(min([ sqdist(p, q) for q in self.points if q != p ])) avg_nn /= len(self.points) inliers = [] for p in self.points: min_neighbor = sqrt(min([ sqdist(p, q) for q in self.points if q != p ])) if 0.5*avg_nn < min_neighbor and min_neighbor < 2*avg_nn: inliers.append(p) self.points = inliers
def d_center(self): """ Returns the most recent change in center coordinates as the squared distance between current and previous centers or *None* if no previous center exists. """ if self.prevcenter == None: return None else: return sqdist(self.prevcenter, self.center)
def _calc_corners(self): """ Locates four corners to approximate the convex hull of *self.points* and saves them as *self.corners*. """ corners = None max_area = 0 origin = Point(0, 0) preimage_corners = [ Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1) ] for P in self._all_quads(): area = A_2x(P) if area > max_area: if sqdist(P[0], origin) == min([ sqdist(p, origin) for p in P ]): max_area = area corners = P self.corners = corners
def sqdist_to(self, point): """ Returns the squared distance of a point from the center of this cluster. """ return sqdist(self.center, point)