def _interactivity_end(self, igc): """ This is called after processing step. All data are rescaled to original resolution. """ logger.debug('_interactivity_end()') self.__resize_to_orig(igc.seeds) self.organ_interactivity_counter = igc.interactivity_counter logger.debug("org inter counter " + str(self.organ_interactivity_counter)) logger.debug('nonzero segm ' + str(np.nonzero(self.segmentation))) # if False: if False: # TODO dodělat postprocessing PV import segmentation outputSegmentation = segmentation.vesselSegmentation( # noqa self.data3d, self.segmentation, threshold=-1, inputSigma=0.15, dilationIterations=10, nObj=1, biggestObjects=False, seeds=(self.segmentation > 0).astype(np.int8), useSeedsOfCompactObjects=True, interactivity=True, binaryClosingIterations=2, binaryOpeningIterations=0) self._segmentation_postprocessing() # rint 'autocrop', self.autocrop if self.autocrop is True: # rint # mport pdb; pdb.set_trace() tmpcrinfo = qmisc.crinfo_from_specific_data( self.segmentation, self.autocrop_margin) self.crop(tmpcrinfo) if self.texture_analysis not in (None, False): import texture_analysis # doplnit nějaký kód, parametry atd # elf.orig_scale_segmentation = # texture_analysis.segmentation(self.data3d, # self.orig_scale_segmentation, params = self.texture_analysis) self.segmentation = texture_analysis.segmentation( self.data3d, self.segmentation, self.voxelsize_mm ) # set label number # !! pomaly!!! # @TODO make faster self.segmentation[self.segmentation == 1] = self.output_label # logger.debug('self.slab') logger.debug(str(self.slab)) self.processing_time = ( datetime.datetime.now() - self.time_start).total_seconds() logger.debug('processing_time = ' + str(self.processing_time))
def _interactivity_end(self, igc): logger.debug('_interactivity_end') #print "sh3", self.data3d.shape # import pdb; pdb.set_trace() # scipy.ndimage.zoom( # self.segmentation, # 1.0 / self.zoom, # output=segm_orig_scale, # mode='nearest', # order=0 # ) segm_orig_scale = scipy.ndimage.zoom( self.segmentation, 1.0 / self.zoom, mode='nearest', order=0 ).astype(np.int8) seeds = scipy.ndimage.zoom( igc.seeds, 1.0 / self.zoom, mode='nearest', order=0 ) #print np.sum(self.segmentation)*np.prod(self.voxelsize_mm) # @TODO odstranit hack pro oříznutí na stejnou velikost # v podstatě je to vyřešeno, ale nechalo by se to dělat elegantněji v zoom # tam je bohužel patrně bug shp = [ np.min([segm_orig_scale.shape[0], self.data3d.shape[0]]), np.min([segm_orig_scale.shape[1], self.data3d.shape[1]]), np.min([segm_orig_scale.shape[2], self.data3d.shape[2]]), ] #self.data3d = self.data3d[0:shp[0], 0:shp[1], 0:shp[2]] self.segmentation = np.zeros(self.data3d.shape, dtype=np.int8) self.segmentation[ 0:shp[0], 0:shp[1], 0:shp[2]] = segm_orig_scale[0:shp[0], 0:shp[1], 0:shp[2]] del segm_orig_scale self.iparams['seeds'] = np.zeros(self.data3d.shape, dtype=np.int8) self.iparams['seeds'][ 0:shp[0], 0:shp[1], 0:shp[2]] = seeds[0:shp[0], 0:shp[1], 0:shp[2]] # if self.segmentation_smoothing: self.segm_smoothing(self.smoothing_mm) #print 'crinfo: ', self.crinfo #print 'autocrop', self.autocrop if self.autocrop is True: #print #import pdb; pdb.set_trace() tmpcrinfo = self._crinfo_from_specific_data( self.segmentation, self.autocrop_margin) self.segmentation = self._crop(self.segmentation, tmpcrinfo) self.data3d = self._crop(self.data3d, tmpcrinfo) self.crinfo = qmisc.combinecrinfo(self.crinfo, tmpcrinfo) if self.texture_analysis not in (None, False): import texture_analysis # doplnit nějaký kód, parametry atd #self.orig_scale_segmentation = # texture_analysis.segmentation(self.data3d, # self.orig_scale_segmentation, params = self.texture_analysis) self.segmentation = texture_analysis.segmentation( self.data3d, self.segmentation, self.voxelsize_mm ) # set label number self.segmentation[self.segmentation == 1] = self.output_label # self.processing_time = time.time() - self.time_start
def _interactivity_end(self, igc): logger.debug('_interactivity_end()') # @TODO remove old code in except part try: # rint 'pred vyjimkou' # aise Exception ('test without skimage') # rint 'za vyjimkou' import skimage import skimage.transform # Now we need reshape seeds and segmentation to original size segm_orig_scale = skimage.transform.resize( self.segmentation, self.data3d.shape, order=0) seeds = skimage.transform.resize( igc.seeds, self.data3d.shape, order=0) self.segmentation = segm_orig_scale self.seeds = seeds except: segm_orig_scale = scipy.ndimage.zoom( self.segmentation, 1.0 / self.zoom, mode='nearest', order=0 ).astype(np.int8) seeds = scipy.ndimage.zoom( igc.seeds, 1.0 / self.zoom, mode='nearest', order=0 ) self.organ_interactivity_counter = igc.interactivity_counter logger.debug("org inter counter " + str(self.organ_interactivity_counter)) # @TODO odstranit hack pro oříznutí na stejnou velikost # v podstatě je to vyřešeno, ale nechalo by se to dělat elegantněji v zoom # tam je bohužel patrně bug # rint 'd3d ', self.data3d.shape # rint 's orig scale shape ', segm_orig_scale.shape shp = [ np.min([segm_orig_scale.shape[0], self.data3d.shape[0]]), np.min([segm_orig_scale.shape[1], self.data3d.shape[1]]), np.min([segm_orig_scale.shape[2], self.data3d.shape[2]]), ] # elf.data3d = self.data3d[0:shp[0], 0:shp[1], 0:shp[2]] # mport ipdb; ipdb.set_trace() # BREAKPOINT self.segmentation = np.zeros(self.data3d.shape, dtype=np.int8) self.segmentation[ 0:shp[0], 0:shp[1], 0:shp[2]] = segm_orig_scale[0:shp[0], 0:shp[1], 0:shp[2]] del segm_orig_scale self.seeds[ 0:shp[0], 0:shp[1], 0:shp[2]] = seeds[0:shp[0], 0:shp[1], 0:shp[2]] if self.segmentation_smoothing: self.segm_smoothing(self.smoothing_mm) # rint 'autocrop', self.autocrop if self.autocrop is True: # rint # mport pdb; pdb.set_trace() tmpcrinfo = qmisc.crinfo_from_specific_data( self.segmentation, self.autocrop_margin) self.crop(tmpcrinfo) # seg = self # rint 'ms d3d ', oseg.data3d.shape # rint 'ms seg ', oseg.segmentation.shape # rint 'crinfo ', oseg.crinfo # elf.segmentation = qmisc.crop(self.segmentation, tmpcrinfo) # elf.data3d = qmisc.crop(self.data3d, tmpcrinfo) # elf.crinfo = qmisc.combinecrinfo(self.crinfo, tmpcrinfo) if self.texture_analysis not in (None, False): import texture_analysis # doplnit nějaký kód, parametry atd # elf.orig_scale_segmentation = # texture_analysis.segmentation(self.data3d, # self.orig_scale_segmentation, params = self.texture_analysis) self.segmentation = texture_analysis.segmentation( self.data3d, self.segmentation, self.voxelsize_mm ) # set label number # !! pomaly!!! # @TODO make faster self.segmentation[self.segmentation == 1] = self.output_label # self.processing_time = time.time() - self.time_start