def test_bounding_box(self): assert_equal(crh.bounding_box(self.c), (1, 0, 3, 4))
def reconstruct(self): self.result.fill(0) pulses = 0 # Reconstruct only from pulses inside the thresholds for area in sorted(self.pulses.keys()): if area < self.area_threshold_min or \ area > self.area_threshold_max: continue for cr in self.pulses[area]: value = crh.get_value(cr) aval = abs(value) if aval < self.amplitude_threshold_min or \ aval > self.amplitude_threshold_max: continue volume = aval * area if volume < self.volume_threshold_min or \ volume > self.volume_threshold_max: continue ## # See: ## # ## # Measuring rectangularity by Paul L. Rosin ## # Machine Vision and Applications, Vol 11, No 4, December 1999 ## # http://www.springerlink.com/content/xb9klcax8ytnwth1/ ## # ## # for more information on computing rectangularity. ## # ## r0, c0, r1, c1 = crh.bounding_box(cr) ## if c0 == c1 or r0 == r1: ## rectangularity = 1 ## else: ## rectangularity = area / float((c1 - c0 + 1) * (r1 - r0 + 1)) ## if rectangularity < self.rectangularity_min or \ ## rectangularity > self.rectangularity_max: ## continue r0, c0, r1, c1 = crh.bounding_box(cr) if (c0 == c1) and (r0 == r1): circularity = 1 else: max_dim = max(abs(r0 - r1), abs(c0 - c1)) circularity = crh.nnz(cr) / \ (np.pi / 4 * (max_dim + 2)**2) # We add 2 to max_dim to allow for pixel overlap # with circumscribing circle if circularity < self.circularity_min or \ circularity > self.circularity_max: continue if self.absolute_sum: value = aval if self.amplitudes_one: value = 1 if self.replace: crh.set_array(self.result, cr, value) else: crh.set_array(self.result, cr, value, 'add') pulses += 1 mask = (self.lifetimes > self.lifetime_max) | \ (self.lifetimes < self.lifetime_min) self.result[mask] = 0 if self.subtract: self.result = np.abs(self.image - self.result) if self.output_threshold != 0: self.result[self.result <= self.output_threshold] = 0 self.pulses_used = pulses self.update_plot()