diff --git a/CBCTCardiacSegmentation/CreateCBCTSegmentations.py b/CBCTCardiacSegmentation/CreateCBCTSegmentations.py index c206960..8fe741d 100644 --- a/CBCTCardiacSegmentation/CreateCBCTSegmentations.py +++ b/CBCTCardiacSegmentation/CreateCBCTSegmentations.py @@ -27,6 +27,7 @@ def CreateCBCTSegmentations(CBCTDir,OutputDir='./CBCTSegmentations',SegmentationMethod='Synthetic',PlanningCTDir='',ElastixParamDir='',StructFile='', + ElastixRunDir = '', HeartPadDistance=30, KeepTempFiles=False): @@ -68,7 +69,8 @@ def CreateCBCTSegmentations(CBCTDir,OutputDir='./CBCTSegmentations',Segmentation Register Images to prepare for Segmentation """ if not(SegmentationMethod == 'Direct'): - VolReg = VolumeRegistration(RegOutputDir=TempDir,ParamDir=ElastixParamDir) + VolReg = VolumeRegistration(RegOutputDir=TempDir,ParamDir=ElastixParamDir, + ElastixDir=ElastixRunDir) #Align PlanningCT Volume to CBCT Volume print('Initial Alignment of Planning CT File to CBCT File') @@ -179,6 +181,7 @@ def CreateCBCTSegmentations(CBCTDir,OutputDir='./CBCTSegmentations',Segmentation parser.add_argument('--SegmentationMethod',default='Synthetic',type=str,help='The method used to segment the CBCT image {Synthetic|Transform|Direct}. Default is Synthetic') parser.add_argument('--PlanningCTDir',type=str, default='',help='Location of the Planning CT that is to be segmented. Can be a Dicom Series or Volume file. Default is None') parser.add_argument('--ElastixParamDir',type=str,default='',help='Location of the elastix parameter files used for the registrations. Default is the parameters is the provided ElastixParameterFiles') + parser.add_argument('--ElastixRunDir',type=str,default='',help='Location of the bin and lib directories from the installed/downaloded version of elastix to be used. Needed for linux implementations') parser.add_argument('--StructFile',type=str,default='',help='Location of the structures contoured from the planning CT File. Default is None') parser.add_argument('--KeepTempFiles',action='store_true',help='If true the temporary files and directories created will not be deleted. If False these files will be deleted.') diff --git a/CBCTCardiacSegmentation/Registration.py b/CBCTCardiacSegmentation/Registration.py index 25bc3be..a6ef674 100644 --- a/CBCTCardiacSegmentation/Registration.py +++ b/CBCTCardiacSegmentation/Registration.py @@ -14,7 +14,7 @@ class VolumeRegistration: def __init__(self, RegOutputDir='', ParamDir='', RigidParamFile='', NonRigidParamFile='', InverseParamFile='', - RigidNonRigidParamFile='',TranslationParamFile='',GPUEnabled=False): + RigidNonRigidParamFile='',TranslationParamFile='',ElastixDir='',GPUEnabled=False): if not ParamDir: #If no elastix parameter directory defined then get the one @@ -26,6 +26,11 @@ def __init__(self, RegOutputDir='', ParamDir='', RigidParamFile='', NonRigidPara self.RegOutputDir = RegOutputDir + if platform.system() == 'Linux': + assert not(not ElastixDir),'Directory to elastix bin/lib files needs to be added for linux' + + self.ElastixDir = ElastixDir + if not ParamDir: self.RigidParamFile = RigidParamFile self.NonRigidParamFile = NonRigidParamFile @@ -157,7 +162,7 @@ def TransformVolume(self, ParamFile, OutputFile, FixedVolume): def CallFunctionFromCmdLine(self,CmdStr): # Run command from terminal if platform.system() == 'Linux': - run(CmdStr, shell=True, env={"PATH": '/home/mark/elastix/bin', "LD_LIBRARY_PATH": '/home/mark/elastix/lib'}) + run(CmdStr, shell=True, env={"PATH": os.path.join(self.ElastixDir,'bin'), "LD_LIBRARY_PATH": os.path.join(self.ElastixDir,'lib')}) else: run(CmdStr) diff --git a/tests/test_CBCT_Segmentation.py b/tests/test_CBCT_Segmentation.py index 9d33d33..25b320f 100644 --- a/tests/test_CBCT_Segmentation.py +++ b/tests/test_CBCT_Segmentation.py @@ -113,7 +113,7 @@ def test_BadSegMethodInput(): rmtree(data_path) rmtree(OutputDir) - + def test_NiftiCBCTSegmentationGeneration(): # Download the test data @@ -131,6 +131,10 @@ def test_NiftiCBCTSegmentationGeneration(): ElastixParamDir = '' StructFile = '' + #Define Elastix directories + home_dir = Path(os.path.expanduser('~')) # may have to update for github system + elastix_dir = home_dir / 'ElastixDownload' / 'elastix-5.0.1-linux' + for SegMethod in SegmentationMethods: print(SegMethod) OutputDir = './CBCTSegmentations' @@ -139,7 +143,8 @@ def test_NiftiCBCTSegmentationGeneration(): SegmentationMethod=SegMethod, PlanningCTDir=PlanningCTDir, ElastixParamDir=ElastixParamDir, - StructFile=StructFile) + StructFile=StructFile, + ElastixRunDir=elastix_dir) CardiacSegList = ['Heart','A_Aorta','A_Cflx','A_Coronary_L','A_Coronary_R','A_LAD','A_Pulmonary','Atrium_L', 'Atrium_R','CN_Atrioventricular','CN_Sinoatrial','V_Venacava_S','Valve_Aortic','Valve_Mitral', @@ -210,4 +215,4 @@ def test_NiftiToDicomStruct(): assert Path(OutputStructFile).exists(),'Output Struct {} was not created successfully'.format(OutputStructFile) rmtree(data_path) - rmtree(OutputDir) \ No newline at end of file + rmtree(OutputDir)