Skip to content
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

add dicom support for data source loader #454

Merged
merged 1 commit into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 22 additions & 0 deletions python/src/nnabla/utils/data_source_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import six
import tempfile

from nnabla.utils import image_utils
from nnabla.utils.image_utils import imresize, imread
from nnabla.logger import logger

Expand Down Expand Up @@ -318,6 +319,26 @@ def load_image_cv2(file, shape=None, max_range=1.0):
return img


def load_image_dcm(file, shape=None, normalize=False):
if normalize:
max_range = 1.0
else:
max_range = -1

img = None
try:
if 'dicom' not in image_utils.get_available_backends():
raise ValueError("Please ensure cv2 and dicom is installed.")

current_backend = image_utils.get_backend()
image_utils.set_backend('dicom')
img = load_image_imread(file, shape, max_range)
return img
finally:
image_utils.set_backend(current_backend)
return img


def load_image(file, shape=None, normalize=False):
if normalize:
max_range = 1.0
Expand Down Expand Up @@ -382,6 +403,7 @@ def load_npy(path, shape=None, normalize=False):
'.gif': load_image,
'.tif': load_image,
'.tiff': load_image,
'.dcm': load_image_dcm,
'.csv': load_csv,
'.npy': load_npy}

Expand Down
5 changes: 3 additions & 2 deletions python/src/nnabla/utils/image_utils/backend_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def backend(self, backend):

self._backend = backend

logger.info(
"use {} for the backend of image utils".format(self._backend))
# Too verbose for common user
# logger.info(
# "use {} for the backend of image utils".format(self._backend))

@property
def module(self):
Expand Down