def DICOM2mha(self, path_rootFolder, img_folder, StudyID, AccessionN, DicomExamNumber, MorNMcase, finding_side):
        # perform conversion
        DicomDirectory = img_folder+os.sep+str(int(StudyID))+os.sep+AccessionN
        if not os.path.exists(DicomDirectory):
            DicomDirectory = img_folder+os.sep+str(int(StudyID))+os.sep+DicomExamNumber
         
        DynSeries_id = MorNMcase['DynSeries_id']
        T2Series_id = MorNMcase['T2Series_id']

        ### split bilateral series into left and right
        [self.Left_pos_pat, self.Left_ori_pat, self.Right_pos_pat, self.Right_ori_pat] = processDicoms.get_LorR_from_bilateral(DicomDirectory, DynSeries_id, T2Series_id)
        
        # get T2 position and orientation
        [self.T2_pos_pat, self.T2_ori_pat, self.T2fatsat] = processDicoms.get_T2_pos_ori(DicomDirectory, T2Series_id)  

        # convert DynSeries_id
        # Left
#        cmd = path_rootFolder+os.sep+'dcm23d'+os.sep+'bin'+os.sep+'dcm23d.exe -i '+DicomDirectory+os.sep+DynSeries_id+os.sep+'Left'+' -o '+DicomDirectory+os.sep+'temp'
#        print '\n---- Begin conversion of ' + DynSeries_id + 'Left to mha...' ;
#        p1 = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
#        p1.wait()
#        
#        os.chdir(DicomDirectory+os.sep+'temp')
#        proc = subprocess.Popen('ls -a', stdout=subprocess.PIPE)
#        output = proc.stdout.read()
#        filetomove = output.split('\n')[2]
#        os.chdir(DicomDirectory)
#        proc = subprocess.Popen(['mv', 'temp'+os.sep+filetomove, DynSeries_id+'_Left.mha'], stdout=subprocess.PIPE)
#        proc.wait()
#        
#        # Right
#        cmd = path_rootFolder+os.sep+'dcm23d'+os.sep+'bin'+os.sep+'dcm23d.exe -i '+DicomDirectory+os.sep+DynSeries_id+os.sep+'Right'+' -o '+DicomDirectory+os.sep+'temp'
#        print '\n---- Begin conversion of ' + DynSeries_id + 'Right to mha...' ;
#        p1 = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
#        p1.wait()
#        
#        os.chdir(DicomDirectory+os.sep+'temp')
#        proc = subprocess.Popen('ls -a', stdout=subprocess.PIPE)
#        output = proc.stdout.read()
#        filetomove = output.split('\n')[2]
#        os.chdir(DicomDirectory)
#        proc = subprocess.Popen(['mv', 'temp'+os.sep+filetomove, DynSeries_id+'_Right.mha'], stdout=subprocess.PIPE)
#        proc.wait()
#                
#        # convert T2Series_id
#        cmd = path_rootFolder+os.sep+'dcm23d'+os.sep+'bin'+os.sep+'dcm23d.exe -i '+DicomDirectory+os.sep+T2Series_id+' -o '+DicomDirectory+os.sep+'temp'
#        print '\n---- Begin conversion of ' + T2Series_id + ' to mha...' ;
#        p1 = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
#        p1.wait()
#        
#        os.chdir(DicomDirectory+os.sep+'temp')
#        proc = subprocess.Popen('ls -a', stdout=subprocess.PIPE)
#        output = proc.stdout.read()
#        filetomove = output.split('\n')[2]
#        os.chdir(DicomDirectory)
#        proc = subprocess.Popen(['mv', 'temp'+os.sep+filetomove, T2Series_id+'.mha'], stdout=subprocess.PIPE)
#        proc.wait()
#
#        # remove temporal dirs, always when using  processDicoms.get_LorR_from_bilateral(abspath_PhaseID) create auxiliary Left and Right dirs
#        shutil.rmtree('temp')
        shutil.rmtree(DicomDirectory+os.sep+DynSeries_id+os.sep+'Left')
        shutil.rmtree(DicomDirectory+os.sep+DynSeries_id+os.sep+'Right')
        
        mhaDirectory = DicomDirectory
        moving_path =  DicomDirectory+os.sep+DynSeries_id+'_'+finding_side+'.mha'
        fixed_path =  DicomDirectory+os.sep+T2Series_id+'.mha'
                
        return mhaDirectory, fixed_path, moving_path
Exemplo n.º 2
0
DicomDirectory = img_folder+os.sep+str(int(StudyID))+os.sep+AccessionN
if not os.path.exists(DicomDirectory):
    DicomDirectory = img_folder+os.sep+str(int(StudyID))+os.sep+DicomExamNumber
 
DynSeries_id = MorNMcase['DynSeries_id']
T2Series_id = MorNMcase['T2Series_id']

mhaDirectory = DicomDirectory
fixed_path =  DicomDirectory+os.sep+DynSeries_id+'_'+finding_side+'.mha'
moving_path =  DicomDirectory+os.sep+T2Series_id+'.mha'

path_rootFolder = os.path.dirname(os.path.abspath(__file__))
print path_rootFolder
#[SendNew2DB.T2_pos_pat, SendNew2DB.T2_pos_pat]  = SendNew2DB.DICOM2mha(path_rootFolder, img_folder, StudyID, AccessionN, DicomExamNumber, MorNMcase, finding_side)
[T2_pos_pat, T2_ori_pat] = processDicoms.get_T2_pos_ori(DicomDirectory, T2Series_id)  

SendNew2DB.T2_pos_pat=T2_pos_pat#[-22.39, -150.9, 115]
SendNew2DB.T2_ori_pat=T2_ori_pat#[-0, 1, 0, -0, -0, -1]
ouput_warped_image_elastix = mhaDirectory+os.sep+T2Series_id+'_warped_elastix.mha'

#############################                  
###### 2) Check segmentation accuracy with annotations
#############################       
print "\n Preload volumes and segmentation..."
[series_path, phases_series] = SendNew2DB.preloadSegment(img_folder, lesion_id, StudyID, AccessionN, DynSeries_id, pathSegment, nameSegment)

print "\n Visualize and load..."
SendNew2DB.loadSegment(pathSegment, nameSegment)