Skip to content

Commit

Permalink
Add some Visible Human datasets (#679)
Browse files Browse the repository at this point in the history
* Add some Visible Human datasets

* Rename module

* Fix URL formatting

* Fix module name
  • Loading branch information
fepegar committed Oct 3, 2021
1 parent ca4890a commit b1b6b66
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 4 deletions.
53 changes: 49 additions & 4 deletions docs/source/datasets.rst
Expand Up @@ -99,16 +99,16 @@ MNI
:class:`Pediatric`
~~~~~~~~~~~~~~~~~~

.. autoclass:: Pediatric
:members:
:show-inheritance:

.. plot::

import torchio as tio
subject = tio.datasets.Pediatric((4.5, 8.5))
subject.plot()

.. autoclass:: Pediatric
:members:
:show-inheritance:


:class:`Sheep`
~~~~~~~~~~~~~~
Expand All @@ -134,6 +134,46 @@ MNI
:show-inheritance:


.. currentmodule:: torchio.datasets.visible_human


Visible Human Project
---------------------

The `Visible Human Project <https://www.nlm.nih.gov/research/visible/visible_human.html>`_
is an effort to create a detailed data set of cross-sectional photographs of
the human body, in order to facilitate anatomy visualization applications.
It is used as a tool for the progression of medical findings, in which these
findings link anatomy to its audiences.
A male and a female cadaver were cut into thin slices which were then
photographed and digitized (from `Wikipedia <https://en.wikipedia.org/wiki/Visible_Human_Project>`_).

:class:`VisibleMale`
~~~~~~~~~~~~~~~~~~~~

.. plot::

import torchio as tio
tio.datasets.VisibleMale('Shoulder').plot()

.. autoclass:: VisibleMale
:members:
:show-inheritance:


:class:`VisibleFemale`
~~~~~~~~~~~~~~~~~~~~~~

.. plot::

import torchio as tio
tio.datasets.VisibleFemale('Shoulder').plot()

.. autoclass:: VisibleFemale
:members:
:show-inheritance:


ITK-SNAP
--------

Expand All @@ -144,6 +184,11 @@ ITK-SNAP
:class:`BrainTumor`
~~~~~~~~~~~~~~~~~~~

.. plot::

import torchio as tio
tio.datasets.BrainTumor().plot()

.. autoclass:: BrainTumor
:members:
:show-inheritance:
Expand Down
3 changes: 3 additions & 0 deletions torchio/datasets/__init__.py
Expand Up @@ -5,6 +5,7 @@
from .ixi import IXI, IXITiny
from .rsna_miccai import RSNAMICCAI
from .itk_snap import BrainTumor, T1T2, AorticValve
from .visible_human import VisibleFemale, VisibleMale
from .mni import Colin27, Sheep, Pediatric, ICBM2009CNonlinearSymmetric


Expand All @@ -23,4 +24,6 @@
'Sheep',
'Pediatric',
'ICBM2009CNonlinearSymmetric',
'VisibleFemale',
'VisibleMale',
]
75 changes: 75 additions & 0 deletions torchio/datasets/visible_human.py
@@ -0,0 +1,75 @@
import abc
import tempfile

from .. import Subject, ScalarImage
from ..utils import get_torchio_cache_dir
from ..download import download_and_extract_archive


class VisibleHuman(abc.ABC, Subject):

URL = 'https://mri.radiology.uiowa.edu/website_documents/visible_human_tar_files/{}{}.tar.gz' # noqa: E501, FS003

def __init__(self, part: str):
self.part = self._parse_part(part)
if not self.cache_part_dir.is_dir():
tempdir = tempfile.gettempdir()
filename = f'{self.__class__.__name__}-{self.part}.tar.gz'
download_and_extract_archive(
self.url,
tempdir,
filename=filename,
extract_root=self.cache_class_dir,
remove_finished=True,
)
super().__init__({self.part.lower(): ScalarImage(self.cache_part_dir)})

@property
def cache_class_dir(self):
return get_torchio_cache_dir() / self.__class__.__name__

@property
def cache_part_dir(self):
return self.cache_class_dir / self.part

@property
def url(self):
return self.URL.format(self.PREFIX, self.part)

def _parse_part(self, part: str) -> None:
part_capital = part.capitalize()
if part_capital not in self.PARTS:
message = f'Part "{part}" not in available parts: {self.PARTS}'
raise ValueError(message)
return part_capital


class VisibleMale(VisibleHuman):
"""Visible Male CT Datasets.
Args:
part: Can be ``'Head'``, ``'Hip'``, ``'Pelvis'`` or ``'Shoulder'``.
"""

PREFIX = 'VHMCT1mm_'
PARTS = (
'Head',
'Hip',
'Pelvis',
'Shoulder',
)


class VisibleFemale(VisibleHuman):
"""Visible Female CT Datasets.
Args:
part: Can be ``'Ankle'``, ``'Head'``, ``'Hip'``, ``'Knee'``,
``'Pelvis'`` or ``'Shoulder'``.
"""

PREFIX = 'VHF-'
PARTS = VisibleMale.PARTS + (
'Ankle',
'Knee',
)

0 comments on commit b1b6b66

Please sign in to comment.