Loading DICOM images into PyTorch
Recently I needed to load DICOM files for modeling and I've learned about handly library - imageio. It can handle a lot of different file types effortlessly, one of them DICOM volumetrtic datasets.
!pip install imageio
import imageio
import torch
As an example, I've downloaded some dicom files from this site
!curl "https://www.visus.com/fileadmin/content/pictures/Downloads/JiveX_DICOME_Viewer/case1.zip" > "case1.zip"
!unzip -q case1.zip
and simply pass the folder to imageio like this:
np_arr = imageio.volread('case1')
dicom_torch = torch.from_numpy(np_arr)
dicom_torch.shape
... and this is how it looks like
import matplotlib.pyplot as plt
%matplotlib inline
plt.imshow(dicom_torch[10])