napari-spatialdata icon indicating copy to clipboard operation
napari-spatialdata copied to clipboard

Split Stack resets coordinates?

Open harrig12 opened this issue 2 years ago • 9 comments

I have a SpatialData with two images, a and b. Each image is mapped to two coordinate system: global and aligned, with the following mapping:

a -> global: identity b -> global: identity a -> aligned: identity b -> aligned: affine

in the viewer, when I open the aligned images, things look good, but if I rightclick image b and use Split Stack to separate out the channels, then my aligned coordinated system seems to be ignored, and the channels all get reset to global. Mean (or other) projections don't seem to have this issue.

harrig12 avatar Jul 28 '23 16:07 harrig12

Hi, thanks for reporting.

@melonora do you know if there is a hook for Split Stack? I think that calling the function you wrote to transfer the metadata would fix this issue.

LucaMarconato avatar Jul 30 '23 22:07 LucaMarconato

@harrig12 @LucaMarconato there is no callback other than a new layer being added as far as I know. However, we can potentially overload the call with the SpatialDataViewer class. I will look into it and report back / implement changes later this week. @harrig12 would you be able to share a small test example? No worries if you can't. One question what number of channels does B have?

melonora avatar Jul 31 '23 15:07 melonora

Thanks a lot @melonora!

LucaMarconato avatar Jul 31 '23 16:07 LucaMarconato

Sure, here's an example zarr

splitstack_mwe.zarr.zip

The affine transformation on B is:

Affine (x, y -> x, y)
    [2.90898430e-01 6.02962457e-03 1.48529400e+02]
    [-2.58579771e-03  2.91931444e-01  2.53555781e+02]
    [0. 0. 1.]

In this example, I have 4 channels in B, but there may be anywhere from 1-40

Thanks! 💃

harrig12 avatar Aug 02 '23 16:08 harrig12

Thanks for providing the sample data! I will get on it

melonora avatar Aug 02 '23 20:08 melonora

Hi @harrig12,

Just to give an update. I opened #136 to support multiple spatialdata objects. As a follow up PR I can fix the issue that you have as I have added a callback function when a layer gets inserted. Could you tell me whether you are using split rgb or split stack? Based on napari documentation these should behave differently.

Based on napari documentation:

Split RGB - if the image layer is an RGB image, it will be split into 3 new layers with red, green, and blue values in separate layers.

Split Stack - if an image layer is a stack (has 3 or more dimensions), it is split into a list of layers along the axis. This option takes a little time to execute. Properties will be changed as follows:

    - Colormap: (magenta, green) for a stack with 2 channels, (CYMRGB) for stacks with more than 2 channels

    - Blending: additive

    - Contrast_limits: min and max values of the layer

    - All other properties, such as Scale and Translate will be propagated from the original stack.

melonora avatar Aug 08 '23 08:08 melonora

I'm using split stack

harrig12 avatar Aug 08 '23 17:08 harrig12

Hey spatialdata devs @melonora @LucaMarconato I report that this still happens on spatialdata 0.3.0 with napari-spatialdata 0.5.5

https://github.com/user-attachments/assets/3d786209-0319-4b40-bcb1-89f66c33df7f

Context: this is a subset (15 x 5000 x 5000) from a much larger sdata object (15, 44470, 73167). Not sure why the image goes far top left. Cropping looked like this Image

josenimo avatar Feb 25 '25 15:02 josenimo

Thanks for reporting. Apparently the transformation metadata is lost for the newly created layer. We should check if there is a callback in napari we can use to update the metadata.

LucaMarconato avatar Feb 25 '25 16:02 LucaMarconato