Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Medical imaging tutorial (#172)
Browse files Browse the repository at this point in the history
* made dataloader work for dicom

* tutorial working

* made xray training work

* made tutorial work correctly

* fastai2 update

* added SIIM_SMALL dataset

* restored vision/core

* fixed ImageBlock import

* integrated SIIM dataset into medical tutorial

* implemented DICOM import in vision.core

* added SIIM folder structure image and updated medical imaging tutorial

* completed medical imaging tutorial

* cleaned repository for pull request

* implemented PILDicom and updated medical tutorial

* removed pydicom from vision.core

* created variable to store tta output

* reverted dcmread function
  • Loading branch information
moritzschwyzer authored Mar 15, 2020
1 parent 30f483a commit 430479f
Show file tree
Hide file tree
Showing 6 changed files with 619 additions and 10 deletions.
4 changes: 4 additions & 0 deletions fastai2/data/checks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,9 @@
"http://files.grouplens.org/datasets/movielens/ml-100k.zip": [
4924029,
"39f6af2d7ea4e117f8838e4a302fec70"
],
"http://files.vedavimedical.com/siim_small.tgz": [
33277183,
"bb55c5ba9aa9eb9dcac9e0f29581b52c"
]
}
3 changes: 3 additions & 0 deletions fastai2/data/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class URLs():
PASCAL_2007 = f'{S3_IMAGELOC}pascal_2007.tgz'
PASCAL_2012 = f'{S3_IMAGELOC}pascal_2012.tgz'

# Medical Imaging datasets
SIIM_SMALL = 'http://files.vedavimedical.com/siim_small.tgz'

#Pretrained models
OPENAI_TRANSFORMER = f'{S3_MODEL}transformer.tgz'
WT103_FWD = f'{S3_MODEL}wt103-fwd.tgz'
Expand Down
28 changes: 22 additions & 6 deletions fastai2/medical/imaging.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/60_medical.imaging.ipynb (unless otherwise specified).

__all__ = ['DcmDataset', 'DcmTag', 'DcmMultiValue', 'dcmread', 'get_dicom_files', 'get_dicom_files', 'pixels',
'scaled_px', 'array_freqhist_bins', 'dicom_windows', 'TensorCTScan', 'PILCTScan', 'show', 'uniform_blur2d',
'gauss_blur2d', 'mask2bbox', 'crop_resize', 'shape']
__all__ = ['DcmDataset', 'DcmTag', 'DcmMultiValue', 'dcmread', 'get_dicom_files', 'get_dicom_files', 'dcmread',
'TensorDicom', 'PILDicom', 'pixels', 'scaled_px', 'array_freqhist_bins', 'dicom_windows', 'TensorCTScan',
'PILCTScan', 'show', 'uniform_blur2d', 'gauss_blur2d', 'mask2bbox', 'crop_resize', 'shape']

# Cell
from ..basics import *
Expand All @@ -26,9 +26,25 @@ def get_dicom_files(path, recurse=True, folders=None):
return get_files(path, extensions=[".dcm"], recurse=recurse, folders=folders)

# Cell
@patch
def dcmread(self:Path, force = False):
return pydicom.dcmread(str(self), force)
def dcmread(fn:(Path,str), force = False):
"Open a `DICOM` file"
return pydicom.dcmread(str(fn), force)

# Cell
class TensorDicom(TensorImage): _show_args = {'cmap':'gray'}

# Cell
class PILDicom(PILBase):
_open_args,_tensor_cls,_show_args = {},TensorDicom,TensorDicom._show_args
@classmethod
def create(cls, fn:(Path,str), mode=None)->None:
"Open a `DICOM file` from path `fn` and load it as a `PIL Image`"
im = Image.fromarray(dcmread(fn).pixel_array)
im.load()
im = im._new(im.im)
return cls(im.convert(mode) if mode else im)

PILDicom._tensor_cls = TensorDicom

# Cell
@patch_property
Expand Down
16 changes: 15 additions & 1 deletion nbs/04_data.external.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@
" LSUN_BEDROOMS = f'{S3_IMAGE}bedroom.tgz'\n",
" PASCAL_2007 = f'{S3_IMAGELOC}pascal_2007.tgz'\n",
" PASCAL_2012 = f'{S3_IMAGELOC}pascal_2012.tgz'\n",
" \n",
" # Medical Imaging datasets\n",
" SIIM_SMALL = 'http://files.vedavimedical.com/siim_small.tgz'\n",
"\n",
" #Pretrained models\n",
" OPENAI_TRANSFORMER = f'{S3_MODEL}transformer.tgz'\n",
Expand Down Expand Up @@ -624,7 +627,18 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#hide\n",
"# url = URLs.IMAGEWANG_160\n",
Expand Down
36 changes: 33 additions & 3 deletions nbs/60_medical.imaging.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,39 @@
"outputs": [],
"source": [
"#export\n",
"@patch\n",
"def dcmread(self:Path, force = False):\n",
" return pydicom.dcmread(str(self), force)"
"def dcmread(fn:(Path,str), force = False):\n",
" \"Open a `DICOM` file\"\n",
" return pydicom.dcmread(str(fn), force)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#export\n",
"class TensorDicom(TensorImage): _show_args = {'cmap':'gray'}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#export\n",
"class PILDicom(PILBase):\n",
" _open_args,_tensor_cls,_show_args = {},TensorDicom,TensorDicom._show_args\n",
" @classmethod\n",
" def create(cls, fn:(Path,str), mode=None)->None:\n",
" \"Open a `DICOM file` from path `fn` and load it as a `PIL Image`\"\n",
" im = Image.fromarray(dcmread(fn).pixel_array) \n",
" im.load()\n",
" im = im._new(im.im)\n",
" return cls(im.convert(mode) if mode else im)\n",
"\n",
"PILDicom._tensor_cls = TensorDicom"
]
},
{
Expand Down
542 changes: 542 additions & 0 deletions nbs/61_tutorial.medical_imaging.ipynb

Large diffs are not rendered by default.

0 comments on commit 430479f

Please sign in to comment.