Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label outlines cause wrong transformation #273

Closed
aeisenbarth opened this issue Jun 6, 2024 · 2 comments · May be fixed by #275
Closed

Label outlines cause wrong transformation #273

aeisenbarth opened this issue Jun 6, 2024 · 2 comments · May be fixed by #275

Comments

@aeisenbarth
Copy link
Contributor

aeisenbarth commented Jun 6, 2024

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")
@timtreis
Copy link
Member

timtreis commented Aug 28, 2024

@aeisenbarth I think we fixed the issue as a side-effect of the last PRs - at least I cannot reproduce it anymore. Could you verify?

If it's solved, could you remove your changes to render.py from #275? I'd be happy to merge in your test and the resulting image

@aeisenbarth
Copy link
Contributor Author

Yes, the issue was also fixed by the refactoring of _render_labels. Thanks!
I rebased the branch to only include the test.

@timtreis timtreis closed this as completed Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants