-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
3,527 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Tue Nov 30 06:01:05 2021 | ||
@author: cbri3325 | ||
""" | ||
import SimpleITK as sitk | ||
import os | ||
from ImageAnalysisFunctions import * | ||
|
||
data_supradir = 'Path to data directory' #Set working directory | ||
|
||
subjs_path = [ f.path for f in os.scandir(data_supradir) if f.is_dir() ] #Create a list of the paths to the subjects directories | ||
subjs_name = [ f.name for f in os.scandir(data_supradir) if f.is_dir() ] #Create a lisdt of subjects names | ||
|
||
n_subj = len(subjs_name) #Total number of subjects | ||
|
||
|
||
|
||
for current in subjs_name: | ||
subj_dir = data_supradir+current | ||
subj_name = current | ||
|
||
# PETFET= sitk.ReadImage(subj_dir +'/'+ subj_name +'_PET_FET_inFETCT.nii') | ||
# CTFET= sitk.ReadImage(subj_dir +'/'+ subj_name +'_CT_FET.nii') | ||
|
||
# brain=sitk.BinaryThreshold(CTFET, 0.0, 100.0) | ||
# brain2=sitk.BinaryFillhole(brain) | ||
# brain2=sitk.BinaryMorphologicalOpening(brain2, (8,8,8), sitk.sitkBall, 0.0, 1.0) | ||
# sitk.WriteImage(brain2, subj_dir+'/brain_mask.nii') | ||
|
||
#Perform brain extraction on PET image | ||
print('Perform brain extraction on PET image for '+subj_name) | ||
PET_FET = sitk.ReadImage(subj_dir +'/'+ subj_name +'_PET_FET_inFETCT.nii', sitk.sitkFloat32) #read PET FET image | ||
brain_mask = sitk.ReadImage(subj_dir +'/brain_mask.nii') #read brain mask | ||
|
||
brain_mask_filled = sitk.BinaryMorphologicalClosing(brain_mask, (1,1,1), sitk.sitkBall, 1.0) #fill holes in brain mask | ||
# sitk.WriteImage(brain_mask_filled, subj_dir +'/brain_mask_filled.nii') #save filled mask | ||
|
||
brain_mask_cleaned = sitk.BinaryMorphologicalOpening(brain_mask_filled, (1,1,1), sitk.sitkBall, 0.0, 1.0) #remove small structures in brain mask filled | ||
# sitk.WriteImage(brain_mask_cleaned, subj_dir +'/brain_mask_cleaned.nii') #save cleaned mask | ||
|
||
# brain_mask_cleaned = sitk.ReadImage(subj_dir +'/brain_mask_cleaned.nii') | ||
|
||
PET_FET_bet = generate_mask(PET_FET, brain_mask_cleaned) | ||
sitk.WriteImage(PET_FET_bet, subj_dir +'/' + subj_name + '_PET_FET_bet.nii') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Mon Feb 6 13:21:43 2023 | ||
@author: Caterina Brighi | ||
""" | ||
|
||
#%% Import functions | ||
|
||
import os | ||
import shutil | ||
|
||
#%% Set Working directory | ||
|
||
data_supradir = 'Path to data directory' #Set working directory | ||
|
||
subjs_path = [ f.path for f in os.scandir(data_supradir) if f.is_dir() ] #Create a list of the paths to the subjects directories | ||
subjs_name = [ f.name for f in os.scandir(data_supradir) if f.is_dir() ] #Create a lisdt of subjects names | ||
subjs_name.remove('Analysis Results Plots') | ||
|
||
n_subj = len(subjs_name) #Total number of subjects | ||
|
||
dest_dir = 'C:/Users/cbri3325/OneDrive - The University of Sydney (Staff)/Caterina Brighi/Data/test/' | ||
|
||
#%%Create a for loop to perform image analysis on each subject sequentially | ||
|
||
for current in subjs_name: | ||
subj_dir = data_supradir+current | ||
subj_name = current | ||
|
||
print('Copying images for '+current) | ||
|
||
#Make new patient directory | ||
if not os.path.exists(dest_dir+current):#if it does not already exist, create a directory of patient data | ||
os.mkdir(dest_dir+current) | ||
pt_dir = dest_dir+current | ||
|
||
if not os.path.exists(pt_dir+'/Original/'):#if it does not already exist, create a directory of patient data | ||
os.mkdir(pt_dir+'/Original/') | ||
orig_dir = pt_dir+'/Original/' | ||
|
||
if not os.path.exists(pt_dir+'/ROIs/'):#if it does not already exist, create a directory of patient data | ||
os.mkdir(pt_dir+'/ROIs/') | ||
roi_dir = pt_dir+'/ROIs/' | ||
|
||
if not os.path.exists(pt_dir+'/Registered/'):#if it does not already exist, create a directory of patient data | ||
os.mkdir(pt_dir+'/Registered/') | ||
reg_dir = pt_dir+'/Registered/' | ||
|
||
if not os.path.exists(pt_dir+'/Transforms/'):#if it does not already exist, create a directory of patient data | ||
os.mkdir(pt_dir+'/Transforms/') | ||
tfm_dir = pt_dir+'/Transforms/' | ||
|
||
#Copy images into test folder | ||
shutil.copy2(subj_dir+'/Original images/'+current+'_CT_FET.nii', orig_dir+'CT_FET.nii') | ||
shutil.copy2(subj_dir+'/Original images/'+current+'_CT_TER.nii', orig_dir+'CT_PSMA.nii') | ||
shutil.copy2(subj_dir+'/Original images/'+current+'_PET_FET.nii', orig_dir+'PET_FET.nii') | ||
shutil.copy2(subj_dir+'/Original images/'+current+'_PET_TER.nii', orig_dir+'PET_PSMA.nii') | ||
|
||
# shutil.copy2(subj_dir+'/Registered images/'+current+'_PET_FET_inFETCT.nii', img_dir+'PET_FET.nii') | ||
# shutil.copy2(subj_dir+'/Registered images/'+current+'_CT_TER_inFETCT.nii', img_dir+'CT_PSMA.nii') | ||
# shutil.copy2(subj_dir+'/Registered images/'+current+'_PET_TER_inFETCT.nii', img_dir+'PET_PSMA.nii') | ||
|
Oops, something went wrong.