Skip to content

Torch backend returns tensor of different shape and data type then input #56

@biagio-lunit

Description

@biagio-lunit

First of all, thank you for implementing this library, it is useful to have different stain normalization algorithms with a simple pip install.

Describe the bug
Macenko normalizer changes the image shape and dtype after normalization,
which requires additional steps in the dataloader which is unexpected and unnecessary.

To Reproduce

H, W, C = 100, 100, 3
target = torch.rand(C, H, W).to(torch.float32)
query = torch.rand(C, H, W).to(torch.float32)
normalizer = torchstain.normalizers.MacenkoNormalizer(backend="torch")
normalizer.fit(target)
query_norm = normalizer.normalize(query)[0]
assert query_norm.shape == query.shape, f'{query_norm.shape} == {query.shape}'
assert query_norm.dtype == query.dtype, f'{query_norm.dtype} == {query.dtype}'

the output is

AssertionError: torch.Size([100, 100, 3]) == torch.Size([3, 100, 100])
AssertionError: torch.int32 == torch.float32

Expected behavior
Image before and after normalization should be the same shape and type.

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