Skip to content
Snippets Groups Projects
Commit 12522981 authored by Andrey Aristov's avatar Andrey Aristov
Browse files

path to save

parent 1da898a4
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ META_ALIGNED = {'ImageJ': '1.53c', ...@@ -25,7 +25,7 @@ META_ALIGNED = {'ImageJ': '1.53c',
'LUTs': [grey, green, blue] 'LUTs': [grey, green, blue]
} }
def align_stack(data_or_path, template16, mask2, plot=False, path=None, binnings=(1,16,2), suffix='.aligned.tif'): def align_stack(data_or_path, template16, mask2, plot=False, path_to_save=None, binnings=(1,16,2), suffix='.aligned.tif'):
''' '''
stack should contain two channels: bright field and fluorescence. stack should contain two channels: bright field and fluorescence.
BF will be binned 8 times and registered with template8 (aligned BF). BF will be binned 8 times and registered with template8 (aligned BF).
...@@ -44,9 +44,11 @@ def align_stack(data_or_path, template16, mask2, plot=False, path=None, binnings ...@@ -44,9 +44,11 @@ def align_stack(data_or_path, template16, mask2, plot=False, path=None, binnings
print(path, stack.shape) print(path, stack.shape)
else: else:
assert data_or_path.ndim == 3 and data_or_path.shape[0] == 2 assert data_or_path.ndim == 3 and data_or_path.shape[0] == 2
assert path is not None assert path_to_save is not None, "Please provide the path to save the data"
stack = data_or_path stack = data_or_path
print(f'Aligned stack will be saved to {path_to_save}')
bf, tritc = stack[:2] bf, tritc = stack[:2]
stack_temp_scale = binnings[1] // binnings[0] stack_temp_scale = binnings[1] // binnings[0]
mask_temp_scale = binnings[1] // binnings[2] mask_temp_scale = binnings[1] // binnings[2]
...@@ -64,7 +66,7 @@ def align_stack(data_or_path, template16, mask2, plot=False, path=None, binnings ...@@ -64,7 +66,7 @@ def align_stack(data_or_path, template16, mask2, plot=False, path=None, binnings
tvec8 = get_transform(f_bf, template16, plot=plot) tvec8 = get_transform(f_bf, template16, plot=plot)
plt.show() plt.show()
tvec = scale_tvec(tvec8, mask_temp_scale) tvec = scale_tvec(tvec8, mask_temp_scale)
print(path, tvec) print(tvec)
try: try:
aligned_tritc = unpad(transform(tritc[::stack_mask_scale, ::stack_mask_scale], tvec), mask2.shape) aligned_tritc = unpad(transform(tritc[::stack_mask_scale, ::stack_mask_scale], tvec), mask2.shape)
aligned_bf = unpad(transform(bf[::stack_mask_scale, ::stack_mask_scale], tvec), mask2.shape) aligned_bf = unpad(transform(bf[::stack_mask_scale, ::stack_mask_scale], tvec), mask2.shape)
...@@ -87,12 +89,12 @@ def align_stack(data_or_path, template16, mask2, plot=False, path=None, binnings ...@@ -87,12 +89,12 @@ def align_stack(data_or_path, template16, mask2, plot=False, path=None, binnings
aligned_stack = np.stack((aligned_bf, aligned_tritc, mask2)).astype('uint16') aligned_stack = np.stack((aligned_bf, aligned_tritc, mask2)).astype('uint16')
imwrite((p:="".join((*path.split('.')[:-1] , suffix))), aligned_stack, imagej=True, metadata=META_ALIGNED) imwrite(path_to_save, aligned_stack, imagej=True, metadata=META_ALIGNED)
print(f'Saved aligned stack {p}') print(f'Saved aligned stack {path_to_save}')
return aligned_stack return aligned_stack, tvec
def align_stack_nd(stack, template16, mask2, path=None, plot=False, binnings=(1,16,2), suffix='.aligned.tif') -> (np.ndarray, dict): def align_stack_nd(stack, template16, mask2, path=None, plot=False, binnings=(1,16,2), suffix='.aligned.tif'):
''' '''
stack should contain two channels: bright field and fluorescence. stack should contain two channels: bright field and fluorescence.
BF will be binned 8 times and registered with template8 (aligned BF). BF will be binned 8 times and registered with template8 (aligned BF).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment