def mainFunction(self): # fix random seed from ilastik.core.randomSeed import RandomSeed RandomSeed.setRandomSeed(42) self.testThread = TestThread(self.testProject.unsupervisedMgr, self.testProject.listOfResultOverlays, self.testProject.listOfFilenames, self.testProject.tolerance) QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'), self.finalizeTest) self.testThread.start(self.testProject.inputOverlays) self.numOverlaysBefore = len(self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())
def mainFunction(self): # fix random seed from ilastik.core.randomSeed import RandomSeed RandomSeed.setRandomSeed(42) self.testThread = TestThread(self.testProject.unsupervisedMgr, self.testProject.listOfResultOverlays, self.testProject.listOfFilenames, self.testProject.tolerance) QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'), self.finalizeTest) self.testThread.start(self.testProject.inputOverlays) self.numOverlaysBefore = len(self.testProject.dataMgr[ self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())
def createDefaultColorTable(cls, type, levels=256, transparentValues=set()): typeCap = type.capitalize() colorTab = [] if (typeCap == "GRAY"): for i in range(levels): if i in transparentValues: colorTab.append(0L) else: colorTab.append(OverlayItem.qgray( i, i, i)) # see qGray function in QtGui else: #RGB import numpy from ilastik.core.randomSeed import RandomSeed seed = RandomSeed.getRandomSeed() if seed is not None: numpy.random.seed(seed) for i in range(levels): if i in transparentValues: colorTab.append(0L) else: colorTab.append( OverlayItem.qrgb( numpy.random.randint(255), numpy.random.randint(255), numpy.random.randint( 255))) # see gRGB function in QtGui return colorTab
def createDefault16ColorColorTable(cls): sublist = [] sublist.append(OverlayItem.qrgb(69, 69, 69)) # dark grey sublist.append(OverlayItem.qrgb(255, 0, 0)) sublist.append(OverlayItem.qrgb(0, 255, 0)) sublist.append(OverlayItem.qrgb(0, 0, 255)) sublist.append(OverlayItem.qrgb(255, 255, 0)) sublist.append(OverlayItem.qrgb(0, 255, 255)) sublist.append(OverlayItem.qrgb(255, 0, 255)) sublist.append(OverlayItem.qrgb(255, 105, 180)) #hot pink! sublist.append(OverlayItem.qrgb(102, 205, 170)) #dark aquamarine sublist.append(OverlayItem.qrgb(165, 42, 42)) #brown sublist.append(OverlayItem.qrgb(0, 0, 128)) #navy sublist.append(OverlayItem.qrgb(255, 165, 0)) #orange sublist.append(OverlayItem.qrgb(173, 255, 47)) #green-yellow sublist.append(OverlayItem.qrgb(128,0, 128)) #purple sublist.append(OverlayItem.qrgb(192, 192, 192)) #silver sublist.append(OverlayItem.qrgb(240, 230, 140)) #khaki colorlist = [] colorlist.append(long(0)) colorlist.extend(sublist) import numpy from ilastik.core.randomSeed import RandomSeed seed = RandomSeed.getRandomSeed() if seed is not None: numpy.random.seed(seed) for i in range(17, 256): color = OverlayItem.qrgb(numpy.random.randint(255),numpy.random.randint(255),numpy.random.randint(255)) colorlist.append(color) return colorlist
def __init__(self, image_filename, borderOverlay_filename, groundtruth_filename): self.image_filename = image_filename self.borderOverlay_filename = borderOverlay_filename self.groundtruth_filename = groundtruth_filename self.testdir = ilastikpath[0] + "/testdata/automatic_segmentation/" # fix random seed from ilastik.core.randomSeed import RandomSeed RandomSeed.setRandomSeed(42) # create project self.project = Project('Project Name', 'Labeler', 'Description') self.dataMgr = self.project.dataMgr # create file list and load data path = str(self.testdir + self.image_filename) # the image is not really used since we load the threshold overlay from a file, however, we need it to set the correct dimensions fileList = [] fileList.append(path) self.project.addFile(fileList) # create automatic segmentation manager self.automaticSegmentationMgr = AutomaticSegmentationModuleMgr(self.dataMgr) # setup inputs self.inputOverlays = [] self.inputOverlays.append(self.dataMgr[self.dataMgr._activeImageNumber].overlayMgr["Raw Data"]) # calculate segmentation results # ...import border indicator self.border_indicator_ov = dataImpex.DataImpex.importOverlay(self.dataMgr[self.dataMgr._activeImageNumber], str(self.testdir + borderOverlay_filename), "") self.input = self.border_indicator_ov._data[0,:,:,:,0] # ...normalize it self.input = self.automaticSegmentationMgr.normalizePotential(self.input) # ...invert it twice, this should give us the original again :-) self.input = self.automaticSegmentationMgr.invertPotential(self.input) self.input = self.automaticSegmentationMgr.invertPotential(self.input) # overlay lists and filenames self.listOfResultOverlays = [] self.listOfFilenames = [] self.listOfResultOverlays.append("Auto Segmentation/Segmentation") self.listOfFilenames.append(self.testdir + self.groundtruth_filename)
def decompose(self, features): # features are of dimension NUMVOXELSxNUMFEATURES # sanity checks self.numComponents = self.checkNumComponents(features.shape[1], self.numComponents) # random seed from ilastik.core.randomSeed import RandomSeed seed = RandomSeed.getRandomSeed() if seed is not None: numpy.random.seed(seed) features = features.T numFeatures, numVoxels = features.shape # this should be the shape of features! # initialize result matrices # features/hidden and hidden/pixels FZ = self.normalizeColumn( numpy.random.random((numFeatures, self.numComponents))) ZV = self.normalizeColumn( numpy.random.random((self.numComponents, numVoxels))) # init vars lastChange = 1 / numpy.finfo(float).eps err = 0 iteration = 0 # expectation maximization (EM) algorithm voxelSums = numpy.sum(features, 0) FZV = numpy.dot(FZ, ZV) # pre-calculate while (lastChange > self.minRelGain and iteration < self.maxIterations): if (numpy.mod(iteration, 25) == 0): print "iteration %d" % iteration print "last relative change %f" % lastChange factor = features / (FZV + numpy.finfo(float).eps) ZV = self.normalizeColumn(ZV * numpy.dot(FZ.T, factor)) FZ = self.normalizeColumn(FZ * numpy.dot(factor, ZV.T)) FZV = numpy.dot(FZ, ZV) # pre-calculate # check relative change in least squares model fit model = numpy.tile(voxelSums, (numFeatures, 1)) * FZV error_old = err err = numpy.sum((features - model)**2) lastChange = numpy.abs( (err - error_old) / (numpy.finfo(float).eps + err)) iteration = iteration + 1 return FZ, ZV
def createDefaultColorTable(cls, type, levels = 256, transparentValues = set()): typeCap = type.capitalize() colorTab = [] if(typeCap == "GRAY"): for i in range(levels): if i in transparentValues: colorTab.append(0L) else: colorTab.append(OverlayItem.qgray(i, i, i)) # see qGray function in QtGui else: #RGB import numpy from ilastik.core.randomSeed import RandomSeed seed = RandomSeed.getRandomSeed() if seed is not None: numpy.random.seed(seed) for i in range(levels): if i in transparentValues: colorTab.append(0L) else: colorTab.append(OverlayItem.qrgb(numpy.random.randint(255),numpy.random.randint(255),numpy.random.randint(255))) # see gRGB function in QtGui return colorTab
def decompose(self, features): # features are of dimension NUMVOXELSxNUMFEATURES # sanity checks self.numComponents = self.checkNumComponents(features.shape[1], self.numComponents) # random seed from ilastik.core.randomSeed import RandomSeed seed = RandomSeed.getRandomSeed() if seed is not None: numpy.random.seed(seed) features = features.T numFeatures, numVoxels = features.shape # this should be the shape of features! # initialize result matrices # features/hidden and hidden/pixels FZ = self.normalizeColumn(numpy.random.random((numFeatures, self.numComponents))) ZV = self.normalizeColumn(numpy.random.random((self.numComponents, numVoxels))) # init vars lastChange = 1/numpy.finfo(float).eps err = 0; iteration = 0; # expectation maximization (EM) algorithm voxelSums = numpy.sum(features, 0) FZV = numpy.dot(FZ, ZV) # pre-calculate while(lastChange > self.minRelGain and iteration < self.maxIterations): if(numpy.mod(iteration, 25)==0): print "iteration %d" % iteration print "last relative change %f" % lastChange factor = features / (FZV + numpy.finfo(float).eps) ZV = self.normalizeColumn(ZV * numpy.dot(FZ.T, factor)) FZ = self.normalizeColumn(FZ * numpy.dot(factor, ZV.T)) FZV = numpy.dot(FZ, ZV) # pre-calculate # check relative change in least squares model fit model = numpy.tile(voxelSums, (numFeatures, 1)) * FZV error_old = err; err = numpy.sum((features - model)**2) lastChange = numpy.abs((err - error_old)/(numpy.finfo(float).eps+err)) iteration = iteration + 1; return FZ, ZV
def createDefault16ColorColorTable(cls): sublist = [] sublist.append(OverlayItem.qrgb(69, 69, 69)) # dark grey sublist.append(OverlayItem.qrgb(255, 0, 0)) sublist.append(OverlayItem.qrgb(0, 255, 0)) sublist.append(OverlayItem.qrgb(0, 0, 255)) sublist.append(OverlayItem.qrgb(255, 255, 0)) sublist.append(OverlayItem.qrgb(0, 255, 255)) sublist.append(OverlayItem.qrgb(255, 0, 255)) sublist.append(OverlayItem.qrgb(255, 105, 180)) #hot pink! sublist.append(OverlayItem.qrgb(102, 205, 170)) #dark aquamarine sublist.append(OverlayItem.qrgb(165, 42, 42)) #brown sublist.append(OverlayItem.qrgb(0, 0, 128)) #navy sublist.append(OverlayItem.qrgb(255, 165, 0)) #orange sublist.append(OverlayItem.qrgb(173, 255, 47)) #green-yellow sublist.append(OverlayItem.qrgb(128, 0, 128)) #purple sublist.append(OverlayItem.qrgb(192, 192, 192)) #silver sublist.append(OverlayItem.qrgb(240, 230, 140)) #khaki colorlist = [] colorlist.append(long(0)) colorlist.extend(sublist) import numpy from ilastik.core.randomSeed import RandomSeed seed = RandomSeed.getRandomSeed() if seed is not None: numpy.random.seed(seed) for i in range(17, 256): color = OverlayItem.qrgb(numpy.random.randint(255), numpy.random.randint(255), numpy.random.randint(255)) colorlist.append(color) return colorlist
painter.begin(splashImage) painter.drawText(QtCore.QPointF(270, 110), ilastik.core.readInBuildInfo()) painter.end() splashScreen = QtGui.QSplashScreen(splashImage) splashScreen.show() app.processEvents() ilastik.modules.loadModuleGuis() mainwindow = MainWindow(sys.argv) mainwindow.setStyleSheet("QSplitter::handle { background-color: #CCCCCC;}") mainwindow.show() #On OS X, the window has to be raised in order to be visible directly after starting #the app mainwindow.raise_() splashScreen.finish(mainwindow) randomseed = RandomSeed() app.exec_() print "cleaning up..." if mainwindow.labelWidget is not None: del mainwindow.labelWidget del mainwindow del randomseed del ilastik.core.jobMachine.GLOBAL_WM