Is there any way to use torchvision.transforms.ToPILImage for float64 images?

Hello, I’m trying to use torchvision.transforms.ToPILImage so that I can augment my data.
My images are from MRI data so they have not the same range as normal images have and the type of them are float64 and the size of each image is 320x320x3.
It does work with size 320x320 in the same rest of the setting.
I don’t understand, why it doesn’t work with 3D while it works with 2D. why? why?
Anyway, I hope anybody can tell me how to solve this problem.

It seems that FP64 images are not supported by PIL as seen here.
What kind of error message you are getting at the moment?

Thank you for replying!!

Traceback (most recent call last):
File “/media/volume1/juna/.local/lib/python3.5/site-packages/torch/utils/data/_utils/”, line 99, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File “/media/volume1/juna/.local/lib/python3.5/site-packages/torch/utils/data/_utils/”, line 99, in
samples = collate_fn([dataset[i] for i in batch_indices])
File “…/datasets/”, line 264, in getitem
image = Image.fromarray(image)
File “/media/volume1/juna/.local/lib/python3.5/site-packages/PIL/”, line 2647, in fromarray
raise TypeError(“Cannot handle this data type”)
TypeError: Cannot handle this data type

Umm well, at the beginning I was trying to use “Image.fromarray(image)” and the error above is the error I got.
So I tried to use torchvision.transforms.ToPILImage instead but people on the internet said it also doesn’t work for float images.
Are there any other python packages I can use for float images?
Otherwise, I’m considering making custom tranform classes.

I would recommend to try to use a Python package, which is specialized to read medical images, so that your data won’t be clipped or disturbed in any other way.
Once you’ve found a package, you could use their load functionality inside your __getitem__ method.

That’s great idea. Thank you for your help!