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

Fixed problem with parameters xmax, ymax and zmax #2604

Merged
merged 4 commits into from Feb 20, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions scripts/sct_crop_image.py
Expand Up @@ -87,8 +87,8 @@ def get_parser():
'-xmax',
type=int,
default=-1,
help="Higher bound for cropping along X. Setting '-1' will crop to the maximum dimension, '-2' will crop to "
"the maximum dimension minus 1 slice, etc.",
help="Higher bound for cropping along X. Setting '-1' will crop to the maximum dimension (i.e. no change), "
"'-2' will crop to the maximum dimension minus 1 slice, etc.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zmin should be: "Lower bound for cropping along Z.",
zmax should be: "Higher bound for cropping along Z. Follows the same rules as xmax."

metavar=Metavar.int,
)
optional.add_argument(
Expand All @@ -109,14 +109,14 @@ def get_parser():
'-zmin',
type=int,
default=0,
help="Lower bound for cropping along Z. Follows the same rules as xmax.",
help="Lower bound for cropping along Z.",
metavar=Metavar.int,
)
optional.add_argument(
'-zmax',
type=int,
default=-1,
help="Higher bound for cropping along Z. Inputting -1 will set it to the maximum dimension.",
help="Higher bound for cropping along Z. Follows the same rules as xmax.",
metavar=Metavar.int,
)
optional.add_argument(
Expand Down
9 changes: 5 additions & 4 deletions spinalcordtoolbox/cropping.py
Expand Up @@ -35,12 +35,13 @@ def _get_min_value(input):
return input

def _get_max_value(input, dim):
# If empty, return dim+1 (corresponds to the maximum of the given dimension, e.g. nx)
# If empty, return maximum dimension (i.e. no change)
if input is None:
return dim + 1
# If negative sign, return dim+1 if -1, dim if -2, dim-1 if -3, etc.
return dim
# If input is "-1", return maximum dimension (i.e. no change). If input is "-2", returns maximum
# dimension minus one, etc.
elif np.sign(input) == -1:
return input + dim + 1
return input + dim
# If user specified a non-negative value, use that
else:
return input
Expand Down
2 changes: 1 addition & 1 deletion testing/test_sct_crop_image.py
Expand Up @@ -45,7 +45,7 @@ def test_integrity(param_test):

# check if cropping was correct depending on the scenario
if index_args == 0:
xyz = (58, 9, 52)
xyz = (57, 9, 52)
elif index_args == 1:
xyz = (10, 55, 13)
elif index_args == 2:
Expand Down