def test_ray_features_circle_down_edge(self): seg = np.zeros((400, 600), dtype=bool) x, y = draw.circle(200, 250, 150, shape=seg.shape) seg[x, y] = True points = [(200, 250), (150, 200), (250, 200), (250, 300)] for i, point in enumerate(points): ray_dist_raw = compute_ray_features_segm_2d( seg, point, edge='down', angle_step=ANGULAR_STEP) ray_dist, shift = shift_ray_features(ray_dist_raw) points_rt = reconstruct_ray_features_2d(point, ray_dist, shift) p_fig = export_ray_results(seg, point, points_rt, ray_dist_raw, ray_dist, 'circle-full_edge-down-%i.png' % i) self.assertTrue(os.path.isfile(p_fig)) # insert white interior x, y = draw.circle(200, 250, 120, shape=seg.shape) seg[x, y] = False for i, point in enumerate(points): ray_dist_raw = compute_ray_features_segm_2d( seg, point, edge='down', angle_step=ANGULAR_STEP) ray_dist, shift = shift_ray_features(ray_dist_raw) points_rt = reconstruct_ray_features_2d(point, ray_dist, shift) p_fig = export_ray_results(seg, point, points_rt, ray_dist_raw, ray_dist, 'circle-inter_edge-down-%i.png' % i) self.assertTrue(os.path.isfile(p_fig))
def test_ray_features_circle_down_edge(self): seg = np.zeros((400, 600), dtype=bool) x, y = draw.circle(200, 250, 150, shape=seg.shape) seg[x, y] = True points = [(200, 250), (150, 200), (250, 200), (250, 300)] for i, point in enumerate(points): ray_dist_raw = seg_fts.compute_ray_features_segm_2d( seg, point, angle_step=ANGULAR_STEP, edge='down') ray_dist, shift = seg_fts.shift_ray_features(ray_dist_raw) points = seg_fts.reconstruct_ray_features_2d( point, ray_dist, shift) p_fig = export_ray_results(seg, point, points, ray_dist_raw, ray_dist, 'circle_e-down-A-%i.png' % i) self.assertTrue(os.path.exists(p_fig)) x, y = draw.circle(200, 250, 120, shape=seg.shape) seg[x, y] = False for i, point in enumerate(points): ray_dist_raw = seg_fts.compute_ray_features_segm_2d( seg, point, angle_step=ANGULAR_STEP, edge='down') ray_dist, shift = seg_fts.shift_ray_features(ray_dist_raw) points = seg_fts.reconstruct_ray_features_2d( point, ray_dist, shift) p_fig = export_ray_results(seg, point, points, ray_dist_raw, ray_dist, 'circle_e-down-B-%i.png' % i) self.assertTrue(os.path.exists(p_fig))
def compute_points_features(segm, points, params): """ for each point in segmentation compute relevant features according params :param ndarray segm: segmentations :param [(int, int)] points: positions in image :param {str: any} params: parameters :return ([[float]], list(str)): [[float] * nb_features] * nb_points, list(str) * nb_features """ features, feature_names = np.empty((len(points), 0)), list() # segmentation histogram if 'fts_hist_diams' in params and params['fts_hist_diams'] is not None: features_hist, names_hist = seg_fts.compute_label_histograms_positions( segm, points, diameters=params['fts_hist_diams']) features = np.hstack((features, features_hist)) feature_names += names_hist names_ray = list() # default empty, require some at leas one compute # Ray features if 'fts_ray_step' in params and params['fts_ray_step'] is not None: list_features_ray = [] perform_closer = all( (params.get('fts_ray_closer', False), len(params['fts_ray_types']) > 1)) shifting = not perform_closer for ray_edge, ray_border in params['fts_ray_types']: features_ray, _, names_ray = seg_fts.compute_ray_features_positions( segm, points, angle_step=params['fts_ray_step'], edge=ray_edge, border_labels=ray_border, smooth_ray=params['fts_ray_smooth'], shifting=shifting, ) # if closer, save all in temporray array else add to feature space if perform_closer: list_features_ray.append(features_ray) else: features = np.hstack((features, features_ray)) feature_names += names_ray # take the closest ray and then perform the shifting if perform_closer: features_ray = [ seg_fts.shift_ray_features(ray)[0] for ray in np.min(np.array(list_features_ray), axis=0) ] features = np.hstack((features, np.array(features_ray))) feature_names += names_ray return features, feature_names
def test_ray_features_circle(self): seg = np.ones((400, 600), dtype=bool) x, y = draw.circle(200, 250, 100, shape=seg.shape) seg[x, y] = False points = [(200, 250), (150, 200), (250, 200), (250, 300)] for i, point in enumerate(points): ray_dist_raw = compute_ray_features_segm_2d( seg, point, angle_step=ANGULAR_STEP) ray_dist, shift = shift_ray_features(ray_dist_raw) points = reconstruct_ray_features_2d(point, ray_dist, shift) p_fig = export_ray_results(seg, point, points, ray_dist_raw, ray_dist, 'circle-%i.png' % i) self.assertTrue(os.path.isfile(p_fig))
def test_ray_features_polygon(self): seg = np.ones((400, 600), dtype=bool) x, y = draw.polygon(np.array([50, 170, 300, 250, 150, 150, 50]), np.array([100, 270, 240, 150, 150, 80, 50]), shape=seg.shape) seg[x, y] = False centres = [(150, 200), (200, 250), (250, 200), (120, 100)] for i, point in enumerate(centres): ray_dist_raw = compute_ray_features_segm_2d( seg, point, angle_step=ANGULAR_STEP) ray_dist, shift = shift_ray_features(ray_dist_raw) points = reconstruct_ray_features_2d(point, ray_dist, shift) p_fig = export_ray_results(seg, point, points, ray_dist_raw, ray_dist, 'polygon-%i.png' % i) self.assertTrue(os.path.isfile(p_fig))