-
Notifications
You must be signed in to change notification settings - Fork 41
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
[DAR-4932][External] correct pixdim application in mask to polygon #968
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,7 +376,7 @@ def adjust_for_pixdims(x, y, pixdims): | |
else: | ||
return {"x": y, "y": x} | ||
else: | ||
return {"x": y * pixdims[1], "y": x * pixdims[0]} | ||
return {"x": y * pixdims[0], "y": x * pixdims[1]} | ||
|
||
_labels, external_paths, _internal_paths = find_contours(mask) | ||
if len(external_paths) > 1: | ||
|
@@ -515,12 +515,12 @@ def process_nifti( | |
ornt: Optional[List[List[float]]] = [[0.0, -1.0], [1.0, -1.0], [2.0, -1.0]], | ||
) -> Tuple[np.ndarray, Tuple[float]]: | ||
""" | ||
Function that converts a nifti object to the RAS orientation, then converts to the passed ornt orientation. | ||
Converts a nifti object of any orientation to the passed ornt orientation. | ||
The default ornt is LPI. | ||
|
||
Args: | ||
input_data: nibabel nifti object. | ||
ornt: (n,2) orientation array. | ||
ornt: (n,2) orientation array. It defines a transformation from RAS. | ||
ornt[N,1] is a flip of axis N of the array, where 1 means no flip and -1 means flip. | ||
ornt[:,0] is the transpose that needs to be done to the implied array, as in arr.transpose(ornt[:,0]). | ||
|
||
|
@@ -529,9 +529,14 @@ def process_nifti( | |
pixdims: tuple of nifti header zoom values. | ||
""" | ||
img = correct_nifti_header_if_necessary(input_data) | ||
img = nib.funcs.as_closest_canonical(img) | ||
data_array = nib.orientations.apply_orientation(img.get_fdata(), ornt) | ||
pixdims = img.header.get_zooms() | ||
orig_ax_codes = nib.orientations.aff2axcodes(img.affine) | ||
orig_ornt = nib.orientations.axcodes2ornt(orig_ax_codes) | ||
transform = nib.orientations.ornt_transform(orig_ornt, ornt) | ||
reoriented_img = img.as_reoriented(transform) | ||
|
||
data_array = reoriented_img.get_fdata() | ||
pixdims = reoriented_img.header.get_zooms() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes to Before, the pixdims were taken from volume reoriented to RAS, meaning the output orientation needed to be in RAS order as well for the pixdims to be ordered correctly. Now the output's axes can be any order. |
||
return data_array, pixdims | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the real change in logic.