Skip to content

Commit

Permalink
feat: spatial filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-grim authored Jan 3, 2025
1 parent c2b83f6 commit 6ed940c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/aind_exaspim_soma_detection/soma_proposal_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run_on_whole_brain(
proposals.extend(thread.result())
pbar.update(1)
pbar.update(1)
return global_filtering(proposals)
return spatial_filtering(proposals, 20)


def generate_proposals(
Expand Down Expand Up @@ -131,10 +131,12 @@ def generate_proposals(

# Filter initial proposals + convert coordinates
filtered_proposals = list()
for voxel in filter_proposals(img_patch, proposals):
filtered_proposals.append(
img_util.local_to_physical(voxel[::-1], offset, multiscale)
)
if len(proposals) > 0:
proposals = spatial_filtering(proposals, 5)
for voxel in filter_proposals(img_patch, proposals):
filtered_proposals.append(
img_util.local_to_physical(voxel[::-1], offset, multiscale)
)
return filtered_proposals


Expand Down Expand Up @@ -352,7 +354,7 @@ def fitness_quality(img_patch, voxels, params):
return np.corrcoef(actual, fitted)[0, 1]


def global_filtering(xyz_list):
def spatial_filtering(xyz_list, dist):
"""
Filters a list of 3D points by merging nearby points based on a given
distance threshold.
Expand All @@ -375,7 +377,7 @@ def global_filtering(xyz_list):
if xyz_query not in visited:
# Search nbhd
points = list()
idxs = kdtree.query_ball_point(xyz_query, 24)
idxs = kdtree.query_ball_point(xyz_query, dist)
for xyz in map(tuple, kdtree.data[idxs]):
points.append(xyz)
visited.add(xyz)
Expand Down

0 comments on commit 6ed940c

Please sign in to comment.