spatialdata
spatialdata copied to clipboard
registration got unmatched images
Hi, here I tried to register the DAPI staining images between nanostring and xenium, and apply that transformation to the segmentation masks, the images aligns well in the napari, however, when I extracted the registered images and plot with matplotlib, I found they were not matched, do you have any suggestions? Thanks!
```python
xenium_sdata = SpatialData(images=img_xenium,shapes=shape_xenium)
nano_sdata = SpatialData(images=img_nano,shapes=shape_nano)
affine = align_elements_using_landmarks(
references_coords=xenium_sdata["landmarks"],
moving_coords=nano_sdata["landmarks"],
reference_element=xenium_sdata["DAPI"],
moving_element=nano_sdata["DAPI"],
reference_coordinate_system="global",
moving_coordinate_system="global",
new_coordinate_system="aligned",
)
affine
def postpone_transformation(
sdata: SpatialData,
transformation: BaseTransformation,
source_coordinate_system: str,
target_coordinate_system: str,
):
for element_type, element_name, element in sdata._gen_elements():
old_transformations = get_transformation(element, get_all=True)
if source_coordinate_system in old_transformations:
old_transformation = old_transformations[source_coordinate_system]
sequence = Sequence([old_transformation, transformation])
set_transformation(element, sequence, target_coordinate_system)
postpone_transformation(
sdata=nano_sdata,
transformation=affine,
source_coordinate_system="global",
target_coordinate_system="aligned",
)
img_nano_aligned = nano_sdata.transform_element_to_coordinate_system('DAPI','aligned',True)
img_xenium_aligned = xenium_sdata.images['DAPI']
```
Here are the images that I got with matplotlib
Screenshots
img_nano_aligned
img_xenium_aligned
aligned images in napri(nanostring DAPI is colored with red and xenium DAPI is colored with blue)