Skip to content

Commit

Permalink
Merge pull request #27 from JaneliaSciComp/algorithm_dev
Browse files Browse the repository at this point in the history
updated defaults for easifish_registration_pipeline
  • Loading branch information
GFleishman authored Nov 8, 2023
2 parents cf387aa + 24d7320 commit 7ca7e77
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 25 deletions.
8 changes: 3 additions & 5 deletions bigstream/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from bigstream.transform import apply_transform, compose_transform_list
from bigstream.metrics import patch_mutual_information
from bigstream import features
from scipy.spatial import cKDTree
import cv2


Expand Down Expand Up @@ -1210,14 +1209,13 @@ def alignment_pipeline(
'deform':lambda **c: deformable_align(*a, **{**b, **c})[1],}

# loop over steps
initial_transform_count = len(static_transform_list)
new_transforms = []
for alignment, arguments in steps:
arguments = {**kwargs, **arguments}
arguments['static_transform_list'] = static_transform_list
static_transform_list.append(align[alignment](**arguments))
arguments['static_transform_list'] = static_transform_list + new_transforms
new_transforms.append(align[alignment](**arguments))

# return in the requested format
new_transforms = static_transform_list[initial_transform_count:]
if return_format == 'independent':
return new_transforms
elif return_format == 'compressed':
Expand Down
36 changes: 24 additions & 12 deletions bigstream/application_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ def easifish_registration_pipeline(
Any arguments you would like to pass to the global instance of
bigstream.align.feature_point_ransac_affine_align. See the
docstring for that function for valid parameters.
default : {'blob_sizes':[6, 20]}
default : {'alignment_spacing':np.min(fix_lowres_spacing)*4,
'blob_sizes':[int(round(np.min(fix_lowres_spacing)*4)),
int(round(np.min(fix_lowres_spacing)*16))]}
global_affine_kwargs : dict
Any arguments you would like to pass to the global instance of
bigstream.align.affine_align. See the docstring for that function
for valid parameters.
default : {'shrink_factors':(2,),
'smooth_sigmas':(2.5,),
default : {'alignment_spacing':np.min(fix_lowres_spacing)*4,
'shrink_factors':(2,),
'smooth_sigmas':(np.min(fix_lowres_spacing)*8,),
'optimizer_args':{
'learningRate':0.25,
'minStep':0.,
Expand All @@ -102,14 +105,15 @@ def easifish_registration_pipeline(
Any arguments you would like to pass to the local instances of
bigstream.align.feature_point_ransac_affine_align. See the
docstring for that function for valid parameters.
default : {'blob_sizes':[6, 20]}
default : {'blob_sizes':same physical size as global_ransac values,
but scaled to highres voxel grid}
local_deform_kwargs : dict
Any arguments you would like to pass to the local instances of
bigstream.align.deformable_align. See the docstring for that function
for valid parameters.
default : {'smooth_sigmas':(0.25,),
'control_point_spacing':50.0,
default : {'smooth_sigmas':(np.min(fix_highres_spacing)*2,),
'control_point_spacing':np.min(fix_highres_spacing)*128,
'control_point_levels':(1,),
'optimizer_args':{
'learningRate':0.25,
Expand Down Expand Up @@ -150,9 +154,14 @@ def easifish_registration_pipeline(
mov_lowres = mov_lowres[...]

# configure global affine alignment at lowres
a = {'blob_sizes':[6, 20]}
b = {'shrink_factors':(2,),
'smooth_sigmas':(2.5,),
alignment_spacing = np.min(fix_lowres_spacing)*4
blob_min = int(round(np.min(fix_lowres_spacing)*4))
blob_max = int(round(np.min(fix_lowres_spacing)*16))
a = {'alignment_spacing':alignment_spacing,
'blob_sizes':[blob_min, blob_max]}
b = {'alignment_spacing':alignment_spacing,
'shrink_factors':(2,),
'smooth_sigmas':(2*alignment_spacing,),
'optimizer_args':{
'learningRate':0.25,
'minStep':0.,
Expand Down Expand Up @@ -181,9 +190,12 @@ def easifish_registration_pipeline(
np.save(f'{write_directory}/affine.npy', aligned)

# configure local deformable alignment at highres
a = {'blob_sizes':[6, 20]}
b = {'smooth_sigmas':(0.25,),
'control_point_spacing':50.0,
ratio = np.min(fix_spacing_lowres) / np.min(fix_spacing_highres)
blob_min = int(round(blob_min * ratio))
blob_max = int(round(blob_min * ratio))
a = {'blob_sizes':[blob_min, blob_max]}
b = {'smooth_sigmas':(2*np.min(fix_spacing_highres),),
'control_point_spacing':np.min(fix_spacing_highres)*128,
'control_point_levels':(1,),
'optimizer_args':{
'learningRate':0.25,
Expand Down
2 changes: 1 addition & 1 deletion bigstream/configure_irm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, psutil
import os
import SimpleITK as sitk
import bigstream.utility as ut

Expand Down
14 changes: 11 additions & 3 deletions bigstream/level_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def foreground_segmentation(
smooth_sigmas=(8.,4.,2.),
lambda2=20.,
background=None,
return_largest_cc_only=True,
mask=None,
mask_smoothing=1,
):
Expand Down Expand Up @@ -151,6 +152,12 @@ def foreground_segmentation(
An estimate of the average background intensity value. If None, it will
automatically be estimated from the image using level_set.estimate_background
return_largest_cc_only : bool (default: True)
If true, final mask is eroded, then connected components are found,
only the largest cc is dilated and retained. If false, the entire
final level set is returned, even if the topology changed (e.g. multiple
discontinuous regions were found)
mask : binary nd-array (default: None)
Optional initialization for the level set. Must be the same shape as image.
Expand Down Expand Up @@ -183,9 +190,10 @@ def foreground_segmentation(
)

# basic topological correction
mask = binary_erosion(mask, iterations=2)
mask = largest_connected_component(mask)
mask = binary_dilation(mask, iterations=2)
if return_largest_cc_only:
mask = binary_erosion(mask, iterations=2)
mask = largest_connected_component(mask)
mask = binary_dilation(mask, iterations=2)
mask = binary_fill_holes(mask).astype(np.uint8)

# ensure output is on correct grid
Expand Down
1 change: 0 additions & 1 deletion bigstream/stitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from distributed import Event
import time
import os
import psutil
import aicspylibczi
from ngff_zarr import to_ngff_image, to_multiscales, to_ngff_zarr

Expand Down
2 changes: 1 addition & 1 deletion bigstream/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import SimpleITK as sitk
import bigstream.utility as ut
from bigstream.configure_irm import interpolator_switch
import os, psutil
import os
from scipy.ndimage import map_coordinates


Expand Down
1 change: 1 addition & 0 deletions bigstream/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import h5py
from ClusterWrap.decorator import cluster
from zarr import blosc
import psutil


def skip_sample(image, spacing, ss_spacing):
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="bigstream",
version="1.2.1",
version="1.2.4",
author="Greg M. Fleishman",
author_email="[email protected]",
description="Tools for distributed alignment of massive images",
Expand All @@ -25,6 +25,7 @@
'numcodecs>=0.9.1',
'fishspot>=0.2.3',
'SimpleITK>=2.2.0',
'tifffile>=2022.10.10'
'tifffile>=2022.10.10',
'morphsnakes>=2.0.0'
]
)

0 comments on commit 7ca7e77

Please sign in to comment.