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

Option to source reconstruct eye ball parcels #160

Open
cgohil8 opened this issue Feb 9, 2023 · 2 comments
Open

Option to source reconstruct eye ball parcels #160

cgohil8 opened this issue Feb 9, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request souce recon

Comments

@cgohil8
Copy link
Collaborator

cgohil8 commented Feb 9, 2023

Would be good to have the option of using parcellation files that include eye balls.

@cgohil8 cgohil8 added the enhancement New feature or request label Feb 9, 2023
@cgohil8
Copy link
Collaborator Author

cgohil8 commented Sep 15, 2023

To create nifti files for the eye balls:

#!/bin/bash

# Create left eye sphere
fslmaths $FSLDIR/data/standard/MNI152_T1_2mm -mul 0 -add 1 -roi 62 1 91 1 16 1 0 1 point -odt float
fslmaths point -kernel sphere 9 -fmean lefteye -odt float

# Right mask
fslswapdim lefteye.nii.gz -x y z righteye.nii.gz

# Normalise mask to 1s
fslmaths  lefteye.nii.gz -div lefteye.nii.gz lefteye_norm.nii.gz
fslmaths  righteye.nii.gz -div righteye.nii.gz righteye_norm.nii.gz

# Resample eye ball nii files to 8 mm resolution
flirt -in lefteye_norm.nii.gz -ref MNI152_T1_8mm_brain.nii.gz -out lefteye_norm.nii.gz -applyisoxfm 8
flirt -in righteye_norm.nii.gz -ref MNI152_T1_8mm_brain.nii.gz -out righteye_norm.nii.gz -applyisoxfm 8

Add them to existing parcellation files with:

import numpy as np
import nibabel as nib

parcellation_file = "Glasser52_binary_space-MNI152NLin6_res-8x8x8.nii.gz"

# Load parcellation
parc = nib.load(parcellation_file)
parc_data = parc.get_fdata()

# Load eyes
left_eye = nib.load("lefteye_norm.nii.gz")
left_eye_data = left_eye.get_fdata()

right_eye = nib.load("righteye_norm.nii.gz")
right_eye_data = right_eye.get_fdata()

# Add the parcel dimension
left_eye_data = left_eye_data[..., np.newaxis]
right_eye_data = right_eye_data[..., np.newaxis]

# Make voxel values binary
left_eye_data[left_eye_data > 0] = 1
right_eye_data[right_eye_data > 0] = 1

# Concatenate eye and parc arrays
new_parc_data = np.concatenate([parc_data, left_eye_data, right_eye_data], axis=3)

# Save new parcellation
new_parc = nib.Nifti1Image(new_parc_data, parc.affine, parc.header)
nib.save(new_parc, parcellation_file.replace(".nii.gz", "_with-eyes.nii.gz"))

Plot the parcellation with

from osl.source_recon import parcellation

parcellation.plot_parcellation(
    "Glasser52_binary_space-MNI152NLin6_res-8x8x8_with-eyes.nii.gz",
    output_file="parcellation_with_eyes.png",
)

This is the output:
parcellation_with_eyes

@cgohil8 cgohil8 assigned cgohil8 and unassigned woolrich Sep 15, 2023
@cgohil8 cgohil8 linked a pull request Sep 15, 2023 that will close this issue
@cgohil8 cgohil8 reopened this Oct 11, 2023
@cgohil8
Copy link
Collaborator Author

cgohil8 commented Oct 11, 2023

Reopened this issue because there was a problem with the parcellation files that included eye balls.

The issue is the voxels covering the eyeballs are not included when we setup the voxel grid (in head space) during the forward modelling. We only create a voxel grid inside the inner skull:

https://github.com/OHBA-analysis/osl/blob/main/osl/source_recon/rhino/forward_model.py#L194

@cgohil8 cgohil8 removed a link to a pull request Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request souce recon
Projects
None yet
Development

No branches or pull requests

2 participants