def loadDcmDir(self): self.statusBar().showMessage('Reading DICOM directory...') QApplication.processEvents() # oseg = self.oseg # if oseg.datapath is None: # oseg.datapath = dcmreader.get_dcmdir_qt(app=True) self.datapath = dcmreader.get_dcmdir_qt(app=True) # if oseg.datapath is None: # self.statusBar().showMessage('No DICOM directory specified!') # return if self.datapath is None: self.statusBar().showMessage('No DICOM directory specified!') return reader = datareader.DataReader() # oseg.data3d, oseg.metadata = reader.Get3DData(oseg.datapath) self.data3d, self.metadata = reader.Get3DData(self.datapath) # oseg.process_dicom_data() self.process_dicom_data() # self.setLabelText(self.text_dcm_dir, oseg.datapath) self.setLabelText(self.text_dcm_dir, self.datapath) self.setLabelText(self.text_dcm_data, self.getDcmInfo()) self.statusBar().showMessage('Ready')
def loadDcmDir(self): self.statusBar().showMessage('Reading DICOM directory...') QApplication.processEvents() if self.dcmdir is None: self.dcmdir = dcmreader.get_dcmdir_qt(app=True) if self.dcmdir is not None: dcr = dcmreader.DicomReader(os.path.abspath(self.dcmdir), qt_app=self) else: self.statusBar().showMessage('No DICOM directory specified!') return if dcr.validData(): self.dcm_3Ddata = dcr.get_3Ddata() self.dcm_metadata = dcr.get_metaData() self.voxel_sizemm = np.array(self.dcm_metadata['voxelsizemm']) self.setVoxelVolume(self.voxel_sizemm) self.setLabelText(self.text_dcm_dir, self.dcmdir) self.setLabelText(self.text_dcm_data, self.getDcmInfo()) self.statusBar().showMessage('Ready') self.setLabelText(self.text_seg_in, 'DICOM reader') else: self.statusBar().showMessage('No DICOM data in direcotry!')
def test_dcmread_get_dcmdir_qt(self): dirpath = dcmr.get_dcmdir_qt() #self.data3d, self.metadata = dcmr.dcm_read_from_dir(self.dcmdir) reader = dcmr.DicomReader(dirpath) self.data3d = reader.get_3Ddata() self.metadata = reader.get_metaData()
def loadDcmDir(self, event=None, filename=None): self.statusBar().showMessage('Loading DICOM data...') QApplication.processEvents() # TODO uninteractive Serie selection #self.data3d, self.metadata = dcmr.dcm_read_from_dir(datadir) datadir = dcmr.get_dcmdir_qt(self.qt_app) # @TODO dialog v qt reader = dcmr.DicomReader(datadir) #, qt_app=self.qt_app) self.data3d = reader.get_3Ddata() self.metadata = reader.get_metaData() self.inps['series_number'] = reader.series_number self.inps['datadir'] = datadir self.statusBar().showMessage('DICOM data loaded')
def loadDcmDir(self, event=None, filename=None): self.statusBar().showMessage('Loading DICOM data...') QApplication.processEvents() # TODO uninteractive Serie selection #self.data3d, self.metadata = dcmr.dcm_read_from_dir(datadir) datadir = dcmr.get_dcmdir_qt(self.qt_app) # @TODO dialog v qt reader = dcmr.DicomReader(datadir)#, qt_app=self.qt_app) self.data3d = reader.get_3Ddata() self.metadata = reader.get_metaData() self.inps['series_number'] = reader.series_number self.inps['datadir'] = datadir self.statusBar().showMessage('DICOM data loaded')
def __init__( self, datapath=None, working_voxelsize_mm=3, series_number=None, autocrop=True, autocrop_margin_mm=[10, 10, 10], manualroi=False, texture_analysis=None, segmentation_smoothing=False, smoothing_mm=4, data3d=None, metadata=None, seeds=None, edit_data=False, segparams={}, roi=None, # iparams=None, output_label=1, slab={}, qt_app=None ): """ Segmentation of objects from CT data. datapath: path to directory with dicom files manualroi: manual set of ROI before data processing, there is a problem with correct coordinates data3d, metadata: it can be used for data loading not from directory. If both are setted, datapath is ignored output_label: label for output segmented volume slab: aditional label system for description segmented data {'none':0, 'liver':1, 'lesions':6} """ self.iparams = {} self.datapath = datapath self.crinfo = [[0, -1], [0, -1], [0, -1]] self.slab = slab self.output_label = output_label self.qt_app = qt_app # TODO uninteractive Serie selection if data3d is None or metadata is None: #if self.iparams.has_key('datapath'): if 'datapath' in self.iparams: datapath = self.iparams['datapath'] #self.data3d, self.metadata = dcmr.dcm_read_from_dir(datapath) if datapath is None: self.process_qt_app() datapath = dcmr.get_dcmdir_qt(self.qt_app) # @TODO dialog v qt #reader = dcmr.DicomReader(datapath) # , qt_app=qt_app) #self.data3d = reader.get_3Ddata() #self.metadata = reader.get_metaData() reader = datareader.DataReader() self.data3d, self.metadata = reader.Get3DData(datapath) self.iparams['series_number'] = self.metadata['series_number'] self.iparams['datapath'] = datapath else: self.data3d = data3d # default values are updated in next line self.metadata = {'series_number': -1, 'voxelsize_mm': 1, 'datapath': None} self.metadata.update(metadata) self.iparams['series_number'] = self.metadata['series_number'] self.iparams['datapath'] = self.metadata['datapath'] self.orig_shape = self.data3d.shape # voxelsize processing if working_voxelsize_mm == 'orig': working_voxelsize_mm = self.metadata['voxelsize_mm'] elif working_voxelsize_mm == 'orig*2': working_voxelsize_mm = np.array(self.metadata['voxelsize_mm']) * 2 elif working_voxelsize_mm == 'orig*4': working_voxelsize_mm = np.array(self.metadata['voxelsize_mm']) * 4 if np.isscalar(working_voxelsize_mm): self.working_voxelsize_mm = ([working_voxelsize_mm] * 3) else: self.working_voxelsize_mm = working_voxelsize_mm self.working_voxelsize_mm = np.array( self.working_voxelsize_mm).astype(float) # if np.isscalar(self.working_voxelsize_mm): # self.working_voxelsize_mm = (np.ones([3]) * #self.working_voxelsize_mm).astype(float) self.iparams['working_voxelsize_mm'] = self.working_voxelsize_mm #self.parameters = {} #self.segparams = {'pairwiseAlpha':2, 'use_boundary_penalties':True, #'boundary_penalties_sigma':50} # for each mm on boundary there will be sum of penalty equal 10 self.segparams = {'pairwise_alpha_per_mm2': 10, 'use_boundary_penalties': False, 'boundary_penalties_sigma': 50} self.segparams = {'pairwise_alpha_per_mm2': 40, 'use_boundary_penalties': False, 'boundary_penalties_sigma': 50} #print segparams # @TODO each axis independent alpha self.segparams.update(segparams) self.segparams['pairwise_alpha'] = \ self.segparams['pairwise_alpha_per_mm2'] / \ np.mean(self.iparams['working_voxelsize_mm']) #self.segparams['pairwise_alpha']=25 # parameters with same effect as interactivity #if iparams is None: # self.iparams= {} #else: # self.set_iparams(iparams) # manualcrop if manualroi is True: # is not None: # @todo opravit souřadný systém v součinnosti s autocrop self.process_qt_app() self.data3d, self.crinfo = qmisc.manualcrop(self.data3d) self.iparams['roi'] = self.crinfo self.iparams['manualroi'] = True #print self.crinfo elif roi is not None: self.data3d = qmisc.crop(self.data3d, roi) self.crinfo = roi self.iparams['roi'] = roi self.iparams['manualroi'] = None if seeds is None: self.iparams['seeds'] = np.zeros(self.data3d.shape, dtype=np.int8) else: if qmisc.isSparseMatrix(seeds): seeds = seeds.todense() self.iparams['seeds'] = seeds self.voxelsize_mm = np.array(self.metadata['voxelsize_mm']) self.autocrop = autocrop self.autocrop_margin_mm = np.array(autocrop_margin_mm) self.autocrop_margin = self.autocrop_margin_mm / self.voxelsize_mm self.texture_analysis = texture_analysis self.segmentation_smoothing = segmentation_smoothing self.smoothing_mm = smoothing_mm self.edit_data = edit_data self.zoom = self.voxelsize_mm / (1.0 * self.working_voxelsize_mm) # def set_iparams(self, iparams): # """ # Set interactivity variables. Make numpy array from scipy sparse # matrix. # """ # # # seeds may be stored in sparse matrix # try: # if qmisc.SparseMatrix.issparse(iparams['seeds']): # iparams['seeds'] = iparams['seeds'].todense() # #import pdb; pdb.set_trace() # except: # # patrne neni SparseMatrix # pass # # self.iparams = iparams # @TODO use logger print 'dir ', self.iparams['datapath'], ", series_number",\ self.iparams['series_number'], 'voxelsize_mm',\ self.voxelsize_mm self.time_start = time.time()
def get_dcmdir_qt(qt_app): # just call function from dcmr return dcmr.get_dcmdir_qt(qt_app)