Skip to content

Applying an Affine transformation modifies the object in a non-equivalent manner #296

Closed

Description

@timtreis

MRE

import math

import matplotlib.pyplot as plt
import spatialdata_plot
from spatialdata.datasets import raccoon
from spatialdata.transformations import (
    Affine,
    Identity,
    MapAxis,
    Scale,
    Sequence,
    Translation,
    get_transformation,
    get_transformation_between_coordinate_systems,
    set_transformation,
)
from spatialdata import transform

sdata = raccoon()

theta = math.pi / 6
rotation = Affine(
    [
        [math.cos(theta), -math.sin(theta), 0],
        [math.sin(theta), math.cos(theta), 0],
        [0, 0, 1],
    ],
    input_axes=("x", "y"),
    output_axes=("x", "y"),
)

set_transformation(sdata.images["raccoon"], rotation, to_coordinate_system="global")

t = get_transformation(sdata.images["raccoon"], to_coordinate_system="global")
print(t)
print("--------------------")

sdata.images["raccoon"] = transform(sdata.images["raccoon"], t)

get_transformation(sdata.images["raccoon"], to_coordinate_system="global")
image

Activity

  1. giovp commented on Jun 22, 2023

    @giovp
    Member

    this is quite interesting, @LucaMarconato do you have any clue on why would that be the case?

  2. timtreis commented on Jun 26, 2023

    @timtreis
    MemberAuthor

    It's because translations are handled differently than rotation or scaling. While the latter two are actually applied, translations are just saved as an offset. So by applying the affine (consisting of all three), it applies two and just stores the translate (again).

  3. LucaMarconato commented on Jun 27, 2023

    @LucaMarconato
    Member

    Forgot to answer here (we discussed this in Zulip). It is because as he said the translations are not applied to the image (since we don't modify the coordinates), but also because when calling transform(), a rotated image is "padded" around the corners with a fill value (default 0), and this requires to prepend a new translation.

    Anyway, both behaviors are weird because we don't update the xarray coordinates, but after the transformation refactoring this will be addressed, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions