From 1676173af12602ad423afc3157809726f2bca99a Mon Sep 17 00:00:00 2001 From: GFleishman Date: Wed, 11 Oct 2023 13:33:35 -0400 Subject: [PATCH 1/8] updated defaults for easifish_registration_pipeline --- bigstream/application_pipelines.py | 36 ++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/bigstream/application_pipelines.py b/bigstream/application_pipelines.py index acc4955..0c4bd9b 100644 --- a/bigstream/application_pipelines.py +++ b/bigstream/application_pipelines.py @@ -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., @@ -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, @@ -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., @@ -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, From 0603ded0e30d65a55a3680e3df157bb4cbfe74be Mon Sep 17 00:00:00 2001 From: GFleishman Date: Mon, 16 Oct 2023 15:01:09 -0400 Subject: [PATCH 2/8] removed static_transform_list bug in alignment_pipeline --- bigstream/align.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bigstream/align.py b/bigstream/align.py index c5d3df8..1d2a21b 100644 --- a/bigstream/align.py +++ b/bigstream/align.py @@ -1210,14 +1210,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': From aff94abe3076dfd9c82fb457c4873beb7b247105 Mon Sep 17 00:00:00 2001 From: GFleishman Date: Mon, 16 Oct 2023 15:02:23 -0400 Subject: [PATCH 3/8] bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5900146..826621b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setuptools.setup( name="bigstream", - version="1.2.1", + version="1.2.2", author="Greg M. Fleishman", author_email="greg.nli10me@gmail.com", description="Tools for distributed alignment of massive images", From c6785922e418d8c16a78ff899c817ac4e7e59593 Mon Sep 17 00:00:00 2001 From: GFleishman Date: Tue, 17 Oct 2023 09:54:09 -0400 Subject: [PATCH 4/8] import psutil fix --- bigstream/configure_irm.py | 2 +- bigstream/stitch.py | 1 - bigstream/transform.py | 2 +- bigstream/utility.py | 1 + 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bigstream/configure_irm.py b/bigstream/configure_irm.py index 7b1de45..d40c7a8 100644 --- a/bigstream/configure_irm.py +++ b/bigstream/configure_irm.py @@ -1,4 +1,4 @@ -import os, psutil +import os import SimpleITK as sitk import bigstream.utility as ut diff --git a/bigstream/stitch.py b/bigstream/stitch.py index f0e3894..c10a940 100644 --- a/bigstream/stitch.py +++ b/bigstream/stitch.py @@ -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 diff --git a/bigstream/transform.py b/bigstream/transform.py index e8a15ae..795faef 100644 --- a/bigstream/transform.py +++ b/bigstream/transform.py @@ -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 diff --git a/bigstream/utility.py b/bigstream/utility.py index c5d33ff..f9a09b3 100644 --- a/bigstream/utility.py +++ b/bigstream/utility.py @@ -9,6 +9,7 @@ import h5py from ClusterWrap.decorator import cluster from zarr import blosc +import psutil def skip_sample(image, spacing, ss_spacing): From 344cb3be616156f47a7b25653cb9f817d1fd7c20 Mon Sep 17 00:00:00 2001 From: GFleishman Date: Tue, 17 Oct 2023 09:54:34 -0400 Subject: [PATCH 5/8] bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 826621b..425b2ee 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setuptools.setup( name="bigstream", - version="1.2.2", + version="1.2.3", author="Greg M. Fleishman", author_email="greg.nli10me@gmail.com", description="Tools for distributed alignment of massive images", From 445f0f8458e0eedc3d21c67d80dc6dd306b21fdd Mon Sep 17 00:00:00 2001 From: GFleishman Date: Fri, 20 Oct 2023 13:02:07 -0400 Subject: [PATCH 6/8] morphsnakes added dependency --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 425b2ee..24111b6 100644 --- a/setup.py +++ b/setup.py @@ -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' ] ) From 177dece72aac849ed02160e7a86d4565b59f0873 Mon Sep 17 00:00:00 2001 From: GFleishman Date: Fri, 20 Oct 2023 13:02:32 -0400 Subject: [PATCH 7/8] removed uneeded import from align.py --- bigstream/align.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bigstream/align.py b/bigstream/align.py index 1d2a21b..627fb32 100644 --- a/bigstream/align.py +++ b/bigstream/align.py @@ -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 From 24d732034a0ce88011a5dd8b1a9c0981288854fc Mon Sep 17 00:00:00 2001 From: GFleishman Date: Wed, 8 Nov 2023 14:00:30 -0500 Subject: [PATCH 8/8] added option to return all components in foreground_segmentation --- bigstream/level_set.py | 14 +++++++++++--- setup.py | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bigstream/level_set.py b/bigstream/level_set.py index c404949..baba13f 100644 --- a/bigstream/level_set.py +++ b/bigstream/level_set.py @@ -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, ): @@ -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. @@ -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 diff --git a/setup.py b/setup.py index 24111b6..94c7171 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setuptools.setup( name="bigstream", - version="1.2.3", + version="1.2.4", author="Greg M. Fleishman", author_email="greg.nli10me@gmail.com", description="Tools for distributed alignment of massive images",