Skip to content

Commit

Permalink
Merge pull request #775 from karanphil/move_load_img
Browse files Browse the repository at this point in the history
Move load img
  • Loading branch information
arnaudbore authored Oct 23, 2023
2 parents 6beaa31 + dc7c2bf commit f8dce6d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
26 changes: 26 additions & 0 deletions scilpy/io/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,35 @@

from dipy.io.utils import is_header_compatible
import logging
import nibabel as nib
import numpy as np
import os

from scilpy.utils.util import is_float


def load_img(arg):
if is_float(arg):
img = float(arg)
dtype = np.float64
else:
if not os.path.isfile(arg):
raise ValueError('Input file {} does not exist.'.format(arg))
img = nib.load(arg)
shape = img.header.get_data_shape()
dtype = img.header.get_data_dtype()
logging.info('Loaded {} of shape {} and data_type {}.'.format(
arg, shape, dtype))

if len(shape) > 3:
logging.warning('{} has {} dimensions, be careful.'.format(
arg, len(shape)))
elif len(shape) < 3:
raise ValueError('{} has {} dimensions, not valid.'.format(
arg, len(shape)))

return img, dtype


def merge_labels_into_mask(atlas, filtering_args):
"""
Expand Down
24 changes: 1 addition & 23 deletions scripts/scil_image_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import numpy as np

from scilpy.image.volume_math import (get_image_ops, get_operations_doc)
from scilpy.io.image import load_img
from scilpy.io.utils import (add_overwrite_arg,
add_verbose_arg,
assert_outputs_exist)
Expand Down Expand Up @@ -59,29 +60,6 @@ def _build_arg_parser():
return p


def load_img(arg):
if is_float(arg):
img = float(arg)
dtype = np.float64
else:
if not os.path.isfile(arg):
raise ValueError('Input file {} does not exist.'.format(arg))
img = nib.load(arg)
shape = img.header.get_data_shape()
dtype = img.header.get_data_dtype()
logging.info('Loaded {} of shape {} and data_type {}.'.format(
arg, shape, dtype))

if len(shape) > 3:
logging.warning('{} has {} dimensions, be careful.'.format(
arg, len(shape)))
elif len(shape) < 3:
raise ValueError('{} has {} dimensions, not valid.'.format(
arg, len(shape)))

return img, dtype


def main():
parser = _build_arg_parser()
args = parser.parse_args()
Expand Down

0 comments on commit f8dce6d

Please sign in to comment.