Skip to content

Label outlines cause wrong transformation #273

Closed
@aeisenbarth

Description

@aeisenbarth

It seems outline=True takes a code path that causes labels to have a wrong scale.

It is important for the images that I render to not have filled labels, but outlines.

Example

import numpy as np
import spatialdata as sd
import spatialdata_plot # noqa: F401
from skimage.transform import AffineTransform

# Same array, same transformation used for both image and labels.
# They should exactly overlap.
array = np.zeros((100, 100), dtype=int)
array[30:70, 30:70] = 1
affine = sd.transformations.Affine(
    AffineTransform(translation=(10, 10), rotation=np.deg2rad(15), scale=0.65).params,
    input_axes=("y", "x"),
    output_axes=("y", "x"),
)
image1 = sd.models.Image2DModel.parse(
    array[:, :, np.newaxis], dims=("y", "x", "c"), transformations={"global": affine}
)
labels1 = sd.models.Labels2DModel.parse(
    array, dims=("y", "x"), transformations={"global": affine}
)
sdata = sd.SpatialData(images={"image1": image1}, labels={"labels1": labels1})

# Render with defaults. Spatialdata-plot fills the labels with color, but no outline.
sdata.pl.render_images("image1").pl.render_labels("labels1").pl.show(title="without outline", save="without_outline.png")

# Render without fill, but with outline, because I don't want to occlude what is behind the labels.
sdata.pl.render_images("image1").pl.render_labels(
    "labels1", fill_alpha=0.0, outline=True, outline_alpha=1.0
).pl.show(title="with outline", save="with_outline.png")

Metadata

Metadata

Assignees

No one assigned

    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