From f8384915513b0f5800489462782756773c57c1bf Mon Sep 17 00:00:00 2001 From: Mike Taormina Date: Mon, 24 May 2021 16:04:47 -0700 Subject: [PATCH 1/2] cull_boundary_points function to clean up user supplied key points that are too close to the volume boundary --- bigstream/features.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bigstream/features.py b/bigstream/features.py index 91fb5d8..41d3cc9 100644 --- a/bigstream/features.py +++ b/bigstream/features.py @@ -90,3 +90,13 @@ def match_points(A, B, scores, threshold): # return positions of corresponding points return a_pos[keeps, :3], b_pos[best_indcs[keeps], :3] +def cull_boundary_points(points, distance, volshape, offset=[0,0,0]): + """ + Only retain points farther than distance from the edges of volume with shape volshape + """ + upperlim = [i-distance for i in volshape] + lowerlim = [distance for i in volshape] + keep_lows = np.all(points[:,0:3] - offset > lowerlim, axis=1) + keep_highs = np.all(points[:,0:3] - offset + 1 < upperlim, axis=1) + idx = np.argwhere(keep_highs & keep_lows) + return np.squeeze(points[idx,:]) \ No newline at end of file From fb6e7ef04b233eda957a98024a7b15bcc2753de8 Mon Sep 17 00:00:00 2001 From: Mike Taormina Date: Mon, 24 May 2021 16:05:17 -0700 Subject: [PATCH 2/2] Clean up user supplied key points --- bigstream/affine.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bigstream/affine.py b/bigstream/affine.py index 1f1bfd9..8129f52 100644 --- a/bigstream/affine.py +++ b/bigstream/affine.py @@ -39,6 +39,12 @@ def ransac_affine( if verbose: ns = fix_spots.shape[0] print(f'FIXED image: found {ns} key points') + else: + # Not sure what the convention should be for pixel vs. physical coordinates. + # This is assuming pixels at the same resolution as `fix` and `mov`. + fix_spots = features.cull_boundary_points(fix_spots, cc_radius, fix.shape) + if fix_spots.shape[1]==3: + fix_spots = np.hstack([fix_spots, np.ones((fix_spots.shape[0],1))]) if mov_spots is None: mov_spots = features.blob_detection( @@ -52,7 +58,11 @@ def ransac_affine( if verbose: ns = mov_spots.shape[0] print(f'MOVING image: found {ns} key points') - + else: + mov_spots = features.cull_boundary_points(mov_spots, cc_radius, mov.shape) + if mov_spots.shape[1]==3: + mov_spots = np.hstack([mov_spots, np.ones((mov_spots.shape[0], 1))]) + # sort sort_idx = np.argsort(fix_spots[:, 3])[::-1] fix_spots = fix_spots[sort_idx, :3][:nspots]