PIL TypeError: Cannot handle this data type for volumetric images

Hello I am working with volumetric image data and getting following error. Any help will be appreciated. Thanks!!

Hi @Push

Seems like this issue has nothing related to PyTorch.

But at a glance I see that PIL is complaining about wrong data type. It works with 2d or 3d arrays, where the number of channels comes in the last position and should be within 2,3 or 4.

Thanks @zetyquickly for your reply. Yes, error is nothing to do with PyTorch. Please take a look at following image.

Since, I am using gray scale image channel number is 1 and is specified in the last position. Still gives the same error. What is wrong with that? Thanks again!

PIL won’t work with tensor of size (40,40,40) and nor with (40,40,40,1).

It takes tensors an treat them like image objects. The sizes acceptable are (X,Y), (X,Y,1), (X,Y,3), (X,Y,4), where the X,Y are height and width of your image

You can read each element of your (40,40,40) shaped tensor, if you pass arr[i] to fromarray()

And you are right, this is not related to PyTorch. And it will be difficult to find an answer on PyTorch forum