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 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