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

Move load img #775

Merged
merged 4 commits into from
Oct 23, 2023
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
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