def updateImage(self, val): """ Hlavni update metoda. Cinny kod pro gaussovske filtrovani, prahovani, binarni uzavreni a otevreni a vraceni nejvetsich nebo oznacenych objektu. """ if (sys.version_info[0] < 3): import copy self.imgFiltering = copy.copy(self.data) else: self.imgFiltering = self.data.copy() ## Filtrovani ## Zjisteni jakou sigmu pouzit if(self.firstRun == True and self.inputSigma >= 0): sigma = numpy.round(self.inputSigma, 2) else: sigma = numpy.round(self.ssigma.val, 2) sigmaNew = thresholding_functions.calculateSigma(self.voxel, sigma) self.imgFiltering = thresholding_functions.gaussFilter(self.imgFiltering, sigmaNew) del(sigmaNew) ## Prahovani (smin, smax) max_threshold = -1 min_threshold = self.threshold if self.interactivity: self.smin.val = (numpy.round(self.smin.val, 2)) self.smin.valtext.set_text('{}'.format(self.smin.val)) self.smax.val = (numpy.round(self.smax.val, 2)) self.smax.valtext.set_text('{}'.format(self.smax.val)) min_threshold = self.smin.val max_threshold = self.smax.val self.threshold = min_threshold if (self.threshold == -1) and self.firstRun: min_threshold = thresholding_functions.calculateAutomaticThreshold(self.imgFiltering, self.arrSeed) self.imgFiltering = thresholding_functions.thresholding(self.imgFiltering, min_threshold, max_threshold, True, self.interactivity) ## Operace binarni otevreni a uzavreni. ## Nastaveni hodnot slideru. if (self.interactivity == True) : closeNum = int(numpy.round(self.sclose.val, 0)) openNum = int(numpy.round(self.sopen.val, 0)) self.sclose.valtext.set_text('{}'.format(closeNum)) self.sopen.valtext.set_text('{}'.format(openNum)) else: closeNum = self.ICBinaryClosingIterations openNum = self.ICBinaryOpeningIterations self.imgFiltering = thresholding_functions.binaryClosingOpening(self.imgFiltering, closeNum, openNum, True) ## Zjisteni nejvetsich objektu. self.getBiggestObjects() ## Vykresleni dat if (self.interactivity == True): self.drawVisualization() ## Nastaveni kontrolnich hodnot self.firstRun = False garbage.collect() self.debugInfo()
def generate_sample_data(m=1, noise_level=0.005, gauss_sigma=0.1): """ Generate sample vessel system. J. Kunes | Input: | m - output will be (100*m)^3 numpy array | noise_level - noise power, disable noise with -1 | gauss_sigma - gauss filter sigma, disable filter with -1 | Output: | (100*m)^3 numpy array | voxel size = [1,1,1] """ import thresholding_functions data3d = np.zeros((100 * m, 100 * m, 100 * m), dtype=np.int) # size 8 data3d_new = np.ones((100 * m, 100 * m, 100 * m), dtype=np.bool) data3d_new[0:30 * m, 20 * m, 20 * m] = 0 data3d_new[scipy.ndimage.distance_transform_edt(data3d_new) <= 8 * m] = 0 data3d[data3d_new == 0] = 1 # size 7 data3d_new = np.ones((100 * m, 100 * m, 100 * m), dtype=np.bool) data3d_new[31 * m:70 * m, 20 * m, 20 * m] = 0 data3d_new[scipy.ndimage.distance_transform_edt(data3d_new) <= 7 * m] = 0 data3d[data3d_new == 0] = 1 # size 6 data3d_new = np.ones((100 * m, 100 * m, 100 * m), dtype=np.bool) data3d_new[70 * m, 20 * m:50 * m, 20 * m] = 0 data3d_new[31 * m, 20 * m, 20 * m:70 * m] = 0 data3d_new[scipy.ndimage.distance_transform_edt(data3d_new) <= 6 * m] = 0 data3d[data3d_new == 0] = 1 # size 5 data3d_new = np.ones((100 * m, 100 * m, 100 * m), dtype=np.bool) data3d_new[70 * m:95 * m, 20 * m, 20 * m] = 0 data3d_new[31 * m:60 * m, 20 * m, 70 * m] = 0 data3d_new[70 * m:90 * m, 50 * m, 20 * m] = 0 data3d_new[70 * m, 50 * m, 20 * m:50 * m] = 0 data3d_new[31 * m, 20 * m: 45 * m, 20 * m] = 0 data3d_new[scipy.ndimage.distance_transform_edt(data3d_new) <= 5*m] = 0 data3d[data3d_new == 0] = 1 # size 4 data3d_new = np.ones((100*m, 100*m, 100*m), dtype=np.bool) data3d_new[31*m, 20*m:50*m, 70*m] = 0 data3d_new[scipy.ndimage.distance_transform_edt(data3d_new) <= 4*m] = 0 data3d[data3d_new == 0] = 1 # size 3 data3d_new = np.ones((100*m, 100*m, 100*m), dtype=np.bool) data3d_new[31*m:50*m, 50*m, 70*m] = 0 data3d_new[31*m:50*m, 45*m, 20*m] = 0 data3d_new[70*m, 50*m:70*m, 50*m] = 0 data3d_new[70*m:80*m, 50*m, 50*m] = 0 data3d_new[scipy.ndimage.distance_transform_edt(data3d_new) <= 3*m] = 0 data3d[data3d_new == 0] = 1 data3d = data3d*3030 # 3030+5920 = vessel value data3d += 5920 # 5920 = background value if gauss_sigma > 0: sigma = np.round(gauss_sigma, 2) sigmaNew = thresholding_functions.calculateSigma([1, 1, 1], sigma) data3d = thresholding_functions.gaussFilter(data3d, sigmaNew) if noise_level > 0: noise = np.random.normal(1, noise_level, (100*m, 100*m, 100*m)) data3d = data3d*noise return data3d