コード例 #1
0
 def load_DICOMseries_using_headers(self, H_REC=re.compile('^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\.([0-9]+\.[0-9]+\.[0-9]+)\.([0-9]+\.[0-9]+\.[0-9]+)$')):
     'Load in one of the dicoms (prefering smaller ones) and use the information inside to construct a dicom_series_info object, which it returns'
     dicomlist = os.listdir(self.path)
     self.numdicoms = len(dicomlist)
     dicompath = None
     if self.numdicoms == 0:
         return None
     elif self.numdicoms == 2:
         for dicom in dicomlist:
             result = H_REC.match(dicom)
             if result != None:
                 tupple = result.groups()
                 if tupple[1] == r'5.24.5':
                     dicompath = os.path.join(self.path, dicom)
                     break
     if dicompath == None:
         dicompath = os.path.join(self.path, dicomlist[0])
     dicom_series = DICOMseries(subid=self.image.visit.subject.subid, visid=self.image.visit.visid, series=self.image.series, sorted_files=self.numdicoms)
     try:
         pydicomobject = pydicom.read_file(dicompath, stop_before_pixels=True)
         dicom_series.set_from_pydicom(pydicomobject)
     except Exception:
         dicom_reader = dcm2txt()
         series_dict = dicom_reader.make_dict(dicompath)
         dicom_series.set_from_dict(series_dict)
     if self.SeriesInstanceUID != dicom_series.SeriesInstanceUID:
         raise Exception, "File {0} does not have same SeriesInstanceUID as folder\n{1}".format(dicompath, self.path)
     if self.SeriesNumber != dicom_series.SeriesNumber:
         raise Exception, "File {0} does not have same SeriesNumber as folder\n{1}".format(dicompath, self.path)
     return dicom_series
コード例 #2
0
 def load_DICOMseries_using_headers(
     self,
     H_REC=re.compile(
         '^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\.([0-9]+\.[0-9]+\.[0-9]+)\.([0-9]+\.[0-9]+\.[0-9]+)$'
     )):
     'Load in one of the dicoms (prefering smaller ones) and use the information inside to construct a dicom_series_info object, which it returns'
     dicomlist = os.listdir(self.path)
     self.numdicoms = len(dicomlist)
     dicompath = None
     if self.numdicoms == 0:
         return None
     elif self.numdicoms == 2:
         for dicom in dicomlist:
             result = H_REC.match(dicom)
             if result != None:
                 tupple = result.groups()
                 if tupple[1] == r'5.24.5':
                     dicompath = os.path.join(self.path, dicom)
                     break
     if dicompath == None:
         dicompath = os.path.join(self.path, dicomlist[0])
     dicom_series = DICOMseries(subid=self.image.visit.subject.subid,
                                visid=self.image.visit.visid,
                                series=self.image.series,
                                sorted_files=self.numdicoms)
     try:
         pydicomobject = pydicom.read_file(dicompath,
                                           stop_before_pixels=True)
         dicom_series.set_from_pydicom(pydicomobject)
     except Exception:
         dicom_reader = dcm2txt()
         series_dict = dicom_reader.make_dict(dicompath)
         dicom_series.set_from_dict(series_dict)
     if self.SeriesInstanceUID != dicom_series.SeriesInstanceUID:
         raise Exception, "File {0} does not have same SeriesInstanceUID as folder\n{1}".format(
             dicompath, self.path)
     if self.SeriesNumber != dicom_series.SeriesNumber:
         raise Exception, "File {0} does not have same SeriesNumber as folder\n{1}".format(
             dicompath, self.path)
     return dicom_series