Skip to content

Commit

Permalink
Merge pull request #193 from rmarkello/ref/leftify_atlas
Browse files Browse the repository at this point in the history
[REF] Re-orient img in `leftify_atlas()`
  • Loading branch information
rmarkello authored May 31, 2021
2 parents f8484fe + 0bd17e6 commit faa44de
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
36 changes: 34 additions & 2 deletions abagen/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@
]


def _reorient_image(image, orientation='RAS'):
"""
Re-orients `image` to `orientation`
Parameters
----------
image : niimg_like
Image to be re-oriented
orientation : str or tuple-of-str
Orientation, drawing from options ('L', 'R')('I', 'S')('P', 'S').
Default: 'RAS'
Returns
-------
reoriented : niimg_like
Re-oriented image
"""

orig_ornt = nib.io_orientation(image.affine)
targ_ornt = nib.orientations.axcodes2ornt(orientation)
transform = nib.orientations.ornt_transform(orig_ornt, targ_ornt)
image = image.as_reoriented(transform)

return image


def leftify_atlas(atlas):
"""
Zeroes out all ROIs in the right hemisphere of volumetric `atlas`
Expand All @@ -40,14 +66,20 @@ def leftify_atlas(atlas):

atlas = check_img(atlas)

# get original orientation then orient to RAS+
orient = nib.orientations.ornt2axcodes(nib.io_orientation(atlas.affine))
atlas = _reorient_image(atlas, 'RAS')

# get ijk corresponding to zero-point
i, j, k = np.squeeze(transforms.xyz_to_ijk([0, 0, 0], atlas.affine))
i = np.squeeze(transforms.xyz_to_ijk([0, 0, 0], atlas.affine))[0]

# zero out all positive voxels; img is RAS+ so positive = right hemisphere
data = np.array(atlas.dataobj, copy=True)
data[int(i):] = 0

return atlas.__class__(data, atlas.affine, header=atlas.header)
out = atlas.__class__(data, atlas.affine, header=atlas.header)

return _reorient_image(out, orient)


def annot_to_gifti(atlas):
Expand Down
4 changes: 2 additions & 2 deletions docs/user_guide/expression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ expression data. In the above example, two of the rows are missing data:
[2 rows x 15633 columns]

These regions, corresponding to the right frontal pole (label 72) and right
temporal pole (label 73) in the Desikan-Killiany atlas, were not matched to
any tissue samples; this is likely due to the fact that only two of the six
temporal pole (label 73) in the Desikan-Killiany atlas, were not matched to
any tissue samples; this is likely due to the fact that only two of the six
donors have tissue samples taken from the right hemisphere.

If you require a *dense* matrix---that is, you need expression values for
Expand Down

0 comments on commit faa44de

Please sign in to comment.