def geometric_voting_rel(boxes, wmax, wmin, rtol, intersect_mode, verb=False): global centers, w_max, w_min, radii, r_rel_tol, vote_db, relative_search, verbose relative_search = True vote_db = {} r_rel_tol = rtol w_max = wmax w_min = wmin n = boxes.shape[0] radii = np.zeros(n) center_points = np.zeros((n, 2)) # approximate all radii in pixels for i, box in enumerate(boxes): radii[i] = util.calculate_radius(box) center_points[i] = util.calculate_center(box) centers = center_points # get sorting vector sort = radii.argsort()[::-1] # sort dat shit radii = radii[sort] tuple_generator = combos(np.arange(n), 2) for count, (ci, cj) in enumerate(tuple_generator): # get pair-database indices of pair candidates if intersect_mode: ci_candidates, cj_candidates = search_pair(ci, cj, True) add_votes_to_db(vote_db, ci, ci_candidates) add_votes_to_db(vote_db, cj, cj_candidates) else: ci_d, ci_r, cj_d, cj_r = search_pair(ci, cj, False) add_votes_to_db(vote_db, ci, ci_d) add_votes_to_db(vote_db, ci, ci_r) add_votes_to_db(vote_db, cj, cj_d) add_votes_to_db(vote_db, cj, cj_r) return do_final_validation(), vote_db
def exclusion_by_intersection_rel(boxes, wmax, wmin, rtol, verb=False): global centers, w_max, w_min, radii, r_rel_tol, intersect_db, relative_search, verbose relative_search = True verbose = verb intersect_db = {} r_rel_tol = rtol w_max = wmax w_min = wmin n = boxes.shape[0] radii = np.zeros(n) center_points = np.zeros((n, 2)) # approximate all radii in pixels for i, box in enumerate(boxes): radii[i] = util.calculate_radius(box) center_points[i] = util.calculate_center(box) centers = center_points # get sorting vector sort = radii.argsort()[::-1] # sort dat shit radii = radii[sort] tuple_generator = combos(np.arange(n), 2) for ci, cj in tuple_generator: # get pair-database indices of pair candidates ci_candidates, cj_candidates = search_pair(ci, cj, True) add_ids_to_db(intersect_db, ci, ci_candidates) add_ids_to_db(intersect_db, cj, cj_candidates) return do_final_validation()
def calculate_km_per_pixel(): hdf = pd.HDFStore('crater_database/crater_db.h5', 'r') crater_db = hdf.get('/db') km_per_pixel = {} for img, anns in ann_data.items(): kmpp_img = 0 count = 0 for ann in anns: real_radius = approximate_visual_distance(crater_db.loc[crater_db.index[(ann['crater_id'])], 'radius']) pixel_radius = calculate_radius([ann['x1'], ann['y1'], ann['x2'], ann['y2']]) kmpp_img += real_radius / pixel_radius count += 1 if count != 0: kmpp_img /= count km_per_pixel[img] = kmpp_img hdf.close() return km_per_pixel
def geometric_voting_abs(boxes, km_pp, r_tol, d_tol, wmax, verb=False): global radius_candidates, rtol, dtol, centers, vote_db, kmpp, w_max, relative_search, verbose relative_search = False vote_db = {} radius_candidates = {} dtol = d_tol rtol = r_tol w_max = wmax kmpp = km_pp n = boxes.shape[0] radii = np.zeros(n) center_points = np.zeros((n, 2)) # calculate all radii and center points for i, box in enumerate(boxes): radii[i] = util.calculate_radius(box) * kmpp center_points[i] = util.calculate_center(box) # get sorting vector sort = radii.argsort()[::-1] # sort dat shit radii = radii[sort] center_points = center_points[sort] center_points *= kmpp centers = center_points # get the radius candidates for c, r in enumerate(radii): radius_candidates[c] = pdb.get_craters_by_real_radius(r, r_tol) tuples = list(combos(np.arange(n), 2)) t = len(tuples) intersect = False for count, (ci, cj) in enumerate(tuples): util.print_progress(count, t, 'Pairs loop', 'complete') ci_candidates, cj_candidates = search_pair(ci, cj, False) vote_db = add_votes_to_db(vote_db, ci, ci_candidates) vote_db = add_votes_to_db(vote_db, cj, cj_candidates) if not intersect: vote_db = add_votes_to_db(vote_db, ci, radius_candidates[ci]) vote_db = add_votes_to_db(vote_db, cj, radius_candidates[cj]) # check_db() return do_final_validation()
def measure(anns, kmpp): hdf = pd.HDFStore('crater_database/crater_db.h5', 'r') crater_db = hdf.get('/db') g = len(anns) tuples = combos(np.arange(g), 2) u = 0 v = 0 diff_dist = 0 diff_rad = 0 for a in range(g): box_a = [anns[a]['x1'], anns[a]['y1'], anns[a]['x2'], anns[a]['y2']] pixel_derived_radius = calculate_radius(box_a) * kmpp real_radius = crater_db.loc[crater_db.index[(anns[a]['crater_id'])], 'radius'] d = real_radius / pixel_derived_radius diff_rad += d print('RADIUS DIFF: ', d) v += 1 diff_rad /= v print('########################### RADIUS AVG DIFF: ', diff_rad) for a, b in tuples: u += 1 print('#####################') print('distances between ', anns[a]['crater_id'], ' with ', anns[a]['lat'], anns[a]['lon'], 'and', anns[b]['crater_id'], ' with ', anns[b]['lat'], anns[b]['lon']) hav = calculate_haversine_distance([anns[a]['lat'], anns[a]['lon']], [anns[b]['lat'], anns[b]['lon']]) appr_real = approximate_visual_distance(hav) print('haversine: ', hav) print('approx: ', appr_real) box_a = [anns[a]['x1'], anns[a]['y1'], anns[a]['x2'], anns[a]['y2']] box_b = [anns[b]['x1'], anns[b]['y1'], anns[b]['x2'], anns[b]['y2']] approx_dist_pixels = \ cdist(np.array([calculate_center(box_a)]), np.array([calculate_center(box_b)]))[0][0] appr_img = approx_dist_pixels * kmpp print('approx pixel dist from bounding box: ', approx_dist_pixels, 'approx km dist from bounding box: ', appr_img) print('difference factor: ', appr_img / appr_real) diff_dist += appr_img / appr_real print('#####################', 'DIFF_AVG:', diff_dist / u, '####################') hdf.close()
def exclusion_by_intersection_abs(boxes, km_pp, r_tol, d_tol, wmax, verb=False): global radius_candidates, rtol, dtol, centers, intersect_db, kmpp, w_max, relative_search, verbose relative_search = False intersect_db = {} radius_candidates = {} dtol = d_tol rtol = r_tol w_max = wmax kmpp = km_pp n = boxes.shape[0] radii = np.zeros(n) center_points = np.zeros((n, 2)) # calculate all radii and center points for i, box in enumerate(boxes): radii[i] = util.calculate_radius(box) * kmpp center_points[i] = util.calculate_center(box) # get sorting vector sort = radii.argsort()[::-1] # sort dat shit radii = radii[sort] center_points = center_points[sort] center_points *= kmpp centers = center_points # get the radius candidates for c, r in enumerate(radii): radius_candidates[c] = pdb.get_craters_by_real_radius(r, r_tol) tuples = list(combos(np.arange(n), 2)) for ci, cj in tuples: ci_candidates, cj_candidates = search_pair(ci, cj, True) add_ids_to_db(intersect_db, ci, ci_candidates) add_ids_to_db(intersect_db, cj, cj_candidates) return do_final_validation()