Skip to content

Commit

Permalink
have ground truth fusion working now
Browse files Browse the repository at this point in the history
still need to sort out optimization..
  • Loading branch information
akhanf committed Jan 27, 2025
1 parent 84e0986 commit a90a15d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 42 deletions.
1 change: 0 additions & 1 deletion dask-stitch/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ rule create_test_dataset_single_ome_zarr:
output:
ome_zarr=directory('results/tile-{tile}_SPIM.ome.zarr'),
nifti='results/tile-{tile}_SPIM.nii',
nifti_fromzarr='results/tile-{tile}_fromzarr_SPIM.nii',
true_offset='results/tile-{tile}_desc-groundtruth_offset.txt'
script: 'scripts/create_test_dataset_singletile.py'

Expand Down
22 changes: 8 additions & 14 deletions dask-stitch/scripts/assign_translation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import numpy as np
from zarrnii import ZarrNii
from zarrnii import ZarrNii, AffineTransform

def assign_translations(ome_zarr_paths, translations, output_niftis, output_ome_zarrs):
"""
Expand All @@ -20,21 +20,15 @@ def assign_translations(ome_zarr_paths, translations, output_niftis, output_ome_
print(translation)
# Load the OME-Zarr dataset
znimg = ZarrNii.from_ome_zarr(path)
# Update the affine matrix
updated_affine = znimg.affine
print(f'original affine: {updated_affine}')

#HACK FIX:
#affine has translation negated and flipped, for whatever reason.. need to fix this in zarrnii
#updated_affine[:3,3] = -1 * np.flip(updated_affine[:3,3])

affine = znimg.affine

if znimg.axes_order == 'ZYX':
affine[:3, 3] += translation[::-1] # Add the optimized translation
else:
affine[:3, 3] += translation # Add the optimized translation



updated_affine[:3, 3] += translation # Add the optimized translation
print(f'updated affine: {updated_affine}')

znimg.affine = updated_affine
znimg.affine = affine

# Save the updated ZarrNii
znimg.to_nifti(out_nii)
Expand Down
30 changes: 3 additions & 27 deletions dask-stitch/scripts/create_test_dataset_singletile.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ def create_test_dataset_single(tile_index, template="MNI152NLin2009cAsym", res=2

# TODO: Simulate error by applying a transformation to the image before

random_offset_low=-0
random_offset_high=0
random_offset_low=-10
random_offset_high=10
# initially lets just do a random jitter
offset = np.random.uniform(random_offset_low, random_offset_high, size=(grid_shape[0],grid_shape[1],3)) # Random 3D offsets for each tile

#save this offset to a text file so we know the ground truth
np.savetxt(snakemake.output.true_offset, -offset[x,y,:].reshape((1,3)), fmt="%.6f")
np.savetxt(snakemake.output.true_offset, offset[x,y,:].reshape((1,3)), fmt="%.6f")


xfm_img_data = affine_transform(img_data,matrix=np.eye(3,3),offset=offset[x,y,:],order=3,mode='nearest')
Expand Down Expand Up @@ -124,27 +124,3 @@ def create_test_dataset_single(tile_index, template="MNI152NLin2009cAsym", res=2



print("LOOP0")
print(test_znimg)

test_znimg2 = ZarrNii.from_ome_zarr(snakemake.output.ome_zarr)
print("LOOP1")
print(test_znimg2) #we want this to be identical to test_znimg



test_znimg2.to_nifti(snakemake.output.nifti_fromzarr)

"""
test_znimg2.to_ome_zarr('mytest_writeafterread.ome.zarr')
test_znimg3 = ZarrNii.from_path('mytest_writeafterread.ome.zarr')
print("LOOP2")
print(test_znimg3)
test_znimg3.to_ome_zarr('mytest_writeafterread2.ome.zarr')
test_znimg4 = ZarrNii.from_path('mytest_writeafterread2.ome.zarr')
print("LOOP3")
print(test_znimg4)
"""

0 comments on commit a90a15d

Please sign in to comment.