Closed tibuch closed 7 months ago
Conclusion: It works! :tada:
Based on the demo code from the linked issue above:
tile_translations = []
a04 = plate_acquistion.get_well_acquisitions(["A04"])[0]
tile_scales = []
tile_paths = []
for t in a04.get_tiles():
if t.get_position()[1] == 0 and t.get_position()[2] == 0:
tile_translations.append(
{
'y': t.get_zyx_position()[1],
'x': t.get_zyx_position()[2]
}
)
tile_scales.append(
{
'y': 1,
'x': 1,
}
)
tile_paths.append(t._paths[0])
msims = []
for tile_translation, tile_scale, tile_path in zip(tile_translations, tile_scales, tile_paths):
print(tile_translation, tile_scale)
sim = si_utils.get_sim_from_array(
da.from_zarr(imread(tile_path, aszarr=True))[np.newaxis],
dims=['c', 'y', 'x'],
scale=tile_scale,
translation=tile_translation,
transform_key='stage_metadata',
c_coords=["DAPI"],
)
msim = msi_utils.get_msim_from_sim(sim, scale_factors=[])
msims.append(msim)
with ProgressBar():
params = registration.register(
msims,
reg_channel_index=0,
transform_key='stage_metadata',
new_transform_key='translation_registered',
registration_binning={'y': 1, 'x': 1},
pre_registration_pruning_method=None,
plot_summary=False,
)
new_tiles = []
i = 0
for t in a04.get_tiles():
if t.get_position()[1] == 0 and t.get_position()[2] == 0:
ntile = copy(t)
ntile.position = TilePosition(
time=ntile.position.time,
channel=ntile.position.channel,
z=ntile.position.z,
y=ntile.position.y + params[i][0][0, -1],
x=ntile.position.x + params[i][0][1, -1]
)
new_tiles.append(
ntile
)
i += 1
stitcher = DaskTileStitcher(
tiles=new_tiles,
chunk_shape=(2000, 2000),
output_shape = (1, 1, 3, 21500, 215000),
)
img = stitcher.get_stitched_image(
fuse_func=stitching_utils.fuse_mean
)
In my toy example I see that the top-left tile is not aligned nicely to the rest. It might be related to different z-positioning. Currently I just chose z-pos == 0 and did not compute a max projection.
It would be awesome if we can use multiview-stitcher to update our tile positions before stitching.
See this issue to get started.