Skip to content

21 add DICOM format in the LoadImage tutorial #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 17, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 63 additions & 20 deletions load_medical_images.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,20 @@
"name": "stdout",
"output_type": "stream",
"text": [
"MONAI version: 0.2.0\n",
"Python version: 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31) [GCC 7.3.0]\n",
"Numpy version: 1.18.1\n",
"Pytorch version: 1.6.0\n",
"MONAI version: 0.2.0+165.g72df264\n",
"Python version: 3.6.10 |Anaconda, Inc.| (default, May 8 2020, 02:54:21) [GCC 7.3.0]\n",
"Numpy version: 1.19.1\n",
"Pytorch version: 1.7.0a0+8deb4fe\n",
"\n",
"Optional dependencies:\n",
"Pytorch Ignite version: NOT INSTALLED or UNKNOWN VERSION.\n",
"Pytorch Ignite version: 0.3.0\n",
"Nibabel version: 3.1.1\n",
"scikit-image version: 0.15.0\n",
"Pillow version: 7.2.0\n",
"Tensorboard version: 2.1.0\n",
"Tensorboard version: 1.15.0+nv\n",
"gdown version: 3.12.2\n",
"TorchVision version: 0.8.0a0\n",
"ITK version: 5.1.1\n",
"\n",
"For details about installing the optional dependencies, please visit:\n",
" https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n",
Expand Down Expand Up @@ -140,7 +143,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 2,
"metadata": {
"tags": []
},
Expand All @@ -158,7 +161,7 @@
" [0., 0., 0., 1.]]), 'affine': array([[1., 0., 0., 0.],\n",
" [0., 1., 0., 0.],\n",
" [0., 0., 1., 0.],\n",
" [0., 0., 0., 1.]]), 'spatial_shape': [128, 128, 128], 'filename_or_obj': '/tmp/tmpg4lwxckh/test_image.nii.gz'}\n"
" [0., 0., 0., 1.]]), 'spatial_shape': [128, 128, 128], 'filename_or_obj': '/tmp/tmp8k6mrupv/test_image.nii.gz'}\n"
]
}
],
Expand Down Expand Up @@ -187,7 +190,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -203,7 +206,7 @@
" [0., 0., 0., 1.]]), 'affine': array([[1., 0., 0., 0.],\n",
" [0., 1., 0., 0.],\n",
" [0., 0., 1., 0.],\n",
" [0., 0., 0., 1.]]), 'spatial_shape': [128, 128, 128], 'filename_or_obj': '/tmp/tmpg4lwxckh/test_image.nii.gz'}\n"
" [0., 0., 0., 1.]]), 'spatial_shape': [128, 128, 128], 'filename_or_obj': '/tmp/tmp8k6mrupv/test_image.nii.gz'}\n"
]
}
],
Expand All @@ -219,6 +222,46 @@
"print(f\"meta data:{meta}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load 3D image in DICOM format"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"image data shape:(128, 128, 128)\n",
"meta data:{'0008|0016': '1.2.840.10008.5.1.4.1.1.7.2', '0008|0018': '1.2.826.0.1.3680043.2.1125.1.67521977900196267350223751193327363', '0008|0020': '20200916', '0008|0030': '020830.308835 ', '0008|0050': '', '0008|0060': 'OT', '0008|0090': '', '0010|0010': '', '0010|0020': '', '0010|0030': '', '0010|0040': '', '0020|000d': '1.2.826.0.1.3680043.2.1125.1.14047733743954145972234965692640011', '0020|000e': '1.2.826.0.1.3680043.2.1125.1.69821186495165346685618438462015632', '0020|0010': '', '0020|0011': '', '0020|0013': '', '0020|0052': '1.2.826.0.1.3680043.2.1125.1.59609996444569026233113858995717616', '0028|0002': '1', '0028|0004': 'MONOCHROME2 ', '0028|0008': '128 ', '0028|0009': '(5200,9230)', '0028|0010': '128', '0028|0011': '128', '0028|0100': '8', '0028|0101': '8', '0028|0102': '7', '0028|0103': '0', '0028|1052': '0 ', '0028|1053': '1 ', '0028|1054': 'US', 'origin': array([0., 0., 0.]), 'spacing': array([1., 1., 1.]), 'direction': array([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.]]), 'original_affine': array([[1., 0., 0., 0.],\n",
" [0., 1., 0., 0.],\n",
" [0., 0., 1., 0.],\n",
" [0., 0., 0., 1.]]), 'affine': array([[1., 0., 0., 0.],\n",
" [0., 1., 0., 0.],\n",
" [0., 0., 1., 0.],\n",
" [0., 0., 0., 1.]]), 'spatial_shape': [128, 128, 128], 'filename_or_obj': '/tmp/tmp8k6mrupv/test_image.dcm'}\n"
]
}
],
"source": [
"filename = os.path.join(tempdir, \"test_image.dcm\")\n",
"dcm_image = np.random.randint(256, size=(128, 128, 128)).astype(np.uint8())\n",
"itk_np_view = itk.image_view_from_array(dcm_image)\n",
"itk.imwrite(itk_np_view, filename)\n",
"data, meta = LoadImage()(filename)\n",
"\n",
"print(f\"image data shape:{data.shape}\")\n",
"print(f\"meta data:{meta}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -228,7 +271,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 5,
"metadata": {
"tags": []
},
Expand All @@ -243,7 +286,7 @@
" [0., 1., 0.],\n",
" [0., 0., 1.]]), 'affine': array([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.]]), 'spatial_shape': [256, 256], 'filename_or_obj': '/tmp/tmpg4lwxckh/test_image.png'}\n"
" [0., 0., 1.]]), 'spatial_shape': [256, 256], 'filename_or_obj': '/tmp/tmp8k6mrupv/test_image.png'}\n"
]
}
],
Expand Down Expand Up @@ -272,7 +315,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -285,13 +328,13 @@
" [0., 1., 0.],\n",
" [0., 0., 1.]]), 'affine': array([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.]]), 'spatial_shape': [256, 256], 'filename_or_obj': '/tmp/tmpg4lwxckh/test_image.png'}\n"
" [0., 0., 1.]]), 'spatial_shape': [256, 256], 'filename_or_obj': '/tmp/tmp8k6mrupv/test_image.png'}\n"
]
}
],
"source": [
"loader = LoadImage()\n",
"loader.register(ITKReader(c_order_axis_indexing=True))\n",
"loader.register(ITKReader())\n",
"data, meta = loader(filename)\n",
"\n",
"print(f\"image data shape:{data.shape}\")\n",
Expand All @@ -310,15 +353,15 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"image data shape:(256, 256, 2)\n",
"meta data:{'format': None, 'mode': 'LA', 'width': 256, 'height': 256, 'info': {}, 'spatial_shape': [256, 256], 'filename_or_obj': '/tmp/tmpg4lwxckh/test_image.png'}\n"
"meta data:{'format': None, 'mode': 'LA', 'width': 256, 'height': 256, 'info': {}, 'spatial_shape': [256, 256], 'filename_or_obj': '/tmp/tmp8k6mrupv/test_image.png'}\n"
]
}
],
Expand All @@ -340,7 +383,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 9,
"metadata": {
"tags": []
},
Expand All @@ -355,7 +398,7 @@
" [0., 1., 0.],\n",
" [0., 0., 1.]]), 'affine': array([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.]]), 'spatial_shape': [256, 256], 'filename_or_obj': '/tmp/tmpg4lwxckh/test_image.png'}\n"
" [0., 0., 1.]]), 'spatial_shape': [256, 256], 'filename_or_obj': '/tmp/tmp8k6mrupv/test_image.png'}\n"
]
}
],
Expand Down Expand Up @@ -383,7 +426,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand Down