def test_data_editor(self): """ Funkce provádí změnu vstupních dat - data3d """ #pyed = py3DSeedEditor.py3DSeedEditor(self.data3d, contour = oseg.segmentation) #pyed.show() from seed_editor_qt import QTSeedEditor from PyQt4.QtGui import QApplication import numpy as np im3d = np.random.rand(15,15,15) print ("Select pixels for deletion (it will be setted to 0)") #, QMainWindow app = QApplication(sys.argv) pyed = QTSeedEditor(im3d, mode='draw') pyed.exec_() deletemask = pyed.getSeeds() print ("If it is ok, press 'Return'. If it is wrong, click into image and press 'Return'") # rewrite input data im3d [deletemask != 0] = 0 pyed = QTSeedEditor(im3d) app.exec_() sds = pyed.getSeeds() # if usere select pixel, there will be 1 or 2 in sds self.assertLess(np.max(sds), 1)
def manualSeg(self): if self.dcm_3Ddata is None: self.statusBar().showMessage('No DICOM data!') return pyed = QTSeedEditor(self.dcm_3Ddata, seeds=self.segmentation_data, mode='draw', voxelVolume=self.voxel_volume) pyed.exec_() self.segmentation_data = pyed.getSeeds() self.checkSegData()
def autoSeg(self): if self.dcm_3Ddata is None: self.statusBar().showMessage('No DICOM data!') return igc = pycut.ImageGraphCut(self.dcm_3Ddata, voxelsize=self.voxel_sizemm) pyed = QTSeedEditor(self.dcm_3Ddata, seeds=self.segmentation_seeds, modeFun=igc.interactivity_loop, voxelSize=self.voxel_sizemm) pyed.exec_() self.segmentation_data = pyed.getContours() self.segmentation_seeds = pyed.getSeeds() self.checkSegData()
def autoSeg(self): if self.dcm_3Ddata is None: self.statusBar().showMessage('No DICOM data!') return igc = pycat.ImageGraphCut(self.dcm_3Ddata, voxelsize=self.voxel_sizemm) pyed = QTSeedEditor(self.dcm_3Ddata, seeds=self.segmentation_seeds, modeFun=igc.interactivity_loop, voxelVolume=self.voxel_volume) pyed.exec_() self.segmentation_data = pyed.getContours() self.segmentation_seeds = pyed.getSeeds() self.checkSegData()
def manualSeg(self): oseg = self.oseg # rint 'ms d3d ', oseg.data3d.shape # rint 'ms seg ', oseg.segmentation.shape # rint 'crinfo ', oseg.crinfo if oseg.data3d is None: self.statusBar().showMessage('No DICOM data!') return sgm = oseg.segmentation.astype(np.uint8) pyed = QTSeedEditor(oseg.data3d, seeds=sgm, mode='draw', voxelSize=oseg.voxelsize_mm, volume_unit='ml') pyed.exec_() oseg.segmentation = pyed.getSeeds() self.oseg.processing_time = time.time() - self.oseg.time_start self.checkSegData('manual seg., ')
def data_editor(self, im3d, cval=0): """ Function changes input data - data3d. cval: value is set to deleted data """ from seed_editor_qt import QTSeedEditor from PyQt4.QtGui import QApplication #import numpy as np #, QMainWindow print ("Select voxels for deletion") app = QApplication(sys.argv) pyed = QTSeedEditor(im3d, mode='draw') pyed.exec_() deletemask = pyed.getSeeds() #import pdb; pdb.set_trace() #pyed = QTSeedEditor(deletemask, mode='draw') #pyed.exec_() app.exit() #pyed.exit() del app del pyed im3d[deletemask != 0] = cval #print ("Check output") # rewrite input data #pyed = QTSeedEditor(im3d) #pyed.exec_() #el pyed #import pdb; pdb.set_trace() return im3d
def test_viewer_seeds(self): from seed_editor_qt import QTSeedEditor from PyQt4.QtGui import QApplication import numpy as np img3d = (np.random.rand(30,30,30)*10).astype(np.int16) seeds = (np.zeros(img3d.shape)).astype(np.int8) seeds[3:6, 12:18,9:16] = 1 seeds[3:6,19:22,21:27 ] = 2 #, QMainWindow app = QApplication(sys.argv) pyed = QTSeedEditor(img3d, seeds=seeds) pyed.exec_() deletemask = pyed.getSeeds() #import pdb; pdb.set_trace() #pyed = QTSeedEditor(deletemask, mode='draw') #pyed.exec_() app.exit()
def cropDcm(self): if self.dcm_3Ddata is None: self.statusBar().showMessage('No DICOM data!') return self.statusBar().showMessage('Cropping DICOM data...') QApplication.processEvents() is_reduced = False shape = self.dcm_3Ddata.shape max12 = np.max(shape[:2]) if max12 > 128: is_reduced = True czoom = [128.0 / max12] * 2 if shape[2] > 32: czoom.append(32.0 / shape[2]) else: czoom.append(1.0) czoom = np.array(czoom) reduced_3Ddata = ndimage.zoom(self.dcm_3Ddata, czoom, prefilter=False, mode='nearest') else: reduced_3Ddata = self.dcm_3Ddata pyed = QTSeedEditor(reduced_3Ddata, mode='crop') pyed.exec_() nzs = pyed.getSeeds().nonzero() if nzs is not None: cri = [] for ii in range(3): if nzs[ii].shape[0] == 0: nzs = None break smin, smax = np.min(nzs[ii]), np.max(nzs[ii]) if smin == smax: nzs = None break cri.append((smin, smax)) cri = np.array(cri) if is_reduced and nzs is not None: aux = (cri.T * (1.0 / czoom)).T cri[:,0] = np.floor(aux[:,0]) cri[:,1] = np.ceil(aux[:,1]) if nzs is not None: crop = self.dcm_3Ddata[cri[0][0]:(cri[0][1] + 1), cri[1][0]:(cri[1][1] + 1), cri[2][0]:(cri[2][1] + 1)] self.dcm_3Ddata = np.ascontiguousarray(crop) self.dcm_offsetmm = cri[:,0] * self.voxel_sizemm self.setLabelText(self.text_dcm_data, self.getDcmInfo()) self.statusBar().showMessage('Ready') else: self.statusBar().showMessage('No crop information!')