def get_pixel_dimensions(image, target_meters_per_pixel_dimensions): metric_dimensions = image.to_metric_dimensions(image.pixel_dimensions) try: pixel_width = round_number(metric_dimensions[0] / float( target_meters_per_pixel_dimensions[0])) pixel_height = round_number(metric_dimensions[1] / float( target_meters_per_pixel_dimensions[1])) except TypeError: pixel_width, pixel_height = image.pixel_dimensions return pixel_width, pixel_height
def estimate_negative_count(image_scope, positive_pixel_centers): canvas = np.zeros(tuple(image_scope.pixel_dimensions), dtype='bool') # Compute the positive pixel area for index, positive_pixel_center in enumerate(positive_pixel_centers): pixel_frame = image_scope.get_pixel_frame_from_pixel_center( positive_pixel_center) (pixel_x, pixel_y), (pixel_width, pixel_height) = pixel_frame canvas[pixel_x:pixel_x + pixel_width, pixel_y:pixel_y + pixel_height] = 1 positive_pixel_area = canvas.sum() # Compute the negative pixel area image_pixel_area = reduce(operator.mul, image_scope.pixel_dimensions) negative_pixel_area = image_pixel_area - positive_pixel_area # Compute the ratio of negatives to positives negative_area_over_positive_area = negative_pixel_area / float( positive_pixel_area) # Estimate the required number of negative examples positive_count = len(positive_pixel_centers) return round_number(negative_area_over_positive_area * positive_count)
def _to_pixel_width(self, projected_width): g0, g1, g2, g3, g4, g5 = self.calibration_pack return round_number(projected_width / float(g1))
def _to_pixel_height(self, projected_height): g0, g1, g2, g3, g4, g5 = self.calibration_pack return round_number(projected_height / float(g5))
return round_number(projected_height / float(g5)) def to_projected_xy(self, (pixel_x, pixel_y)): 'Get projected coordinates given pixel coordinates' g0, g1, g2, g3, g4, g5 = self.calibration_pack projected_x = g0 + pixel_x * g1 + pixel_y * g2 projected_y = g3 + pixel_x * g4 + pixel_y * g5 return np.array([projected_x, projected_y]) def to_pixel_xy(self, (projected_x, projected_y)): 'Get pixel coordinates given projected coordinates' g0, g1, g2, g3, g4, g5 = self.calibration_pack k = float(g1 * g5 - g2 * g4) x = -g0 * g5 + g2 * g3 - g2 * projected_y + g5 * projected_x y = -g1 * (g3 - projected_y) + g4 * (g0 - projected_x) return np.array([round_number(x / k), round_number(y / k)]) class MetricCalibration(ProjectedCalibration): def __init__(self, calibration_pack, proj4): super(MetricCalibration, self).__init__(calibration_pack) self.proj4 = proj4 self._metric_proj4 = self._get_metric_proj4() self._in_metric_projection = self.proj4 == self._metric_proj4 self._transform_to_metric_xy = get_transformPoint( self.proj4, self._metric_proj4) self._transform_to_projected_xy = get_transformPoint( self._metric_proj4, self.proj4) self._metric_xy1 = self._to_metric_xy((0, 0)) def _become(self, c):