Skip to content

support int16 grayscale images #105

@bodokaiser

Description

@bodokaiser

This is often the case with medical (MRI) data.

Required changes would be in ToTensor probably something like:

# PIL image mode: 1, L, P, I, F, RGB, YCbCr, RGBA, CMYK
if pic.mode == 'YCbCr':
  nchannel = 3
else:
  nchannel = len(pic.mode)
# handle PIL Image
buf = pic.tobytes()
if len(buf) > pic.width * pic.height * nchannel:
  img = torch.LongTensor(torch.LongStorage.from_buffer(buf))
else:
  img = torch.ByteTensor(torch.ByteStorage.from_buffer(pic.tobytes()))
img = img.view(pic.size[1], pic.size[0], nchannel)

as well as in ToPILImage (just remove normalization to [0, 255] here?).

However I can't assess possible side effects. int16 support may be not very good in pillow (e.g. plt.imshow(Image.fromarray(int16_np_array)) does not work) also there may be other transforms which depend on [0, 255] byte range.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions