def wsDtSegmentation(pmap, pmin, minMembraneSize, minSegmentSize, sigmaMinima, sigmaWeights, cleanCloseSeeds=True): # get the thresholded pmap binary = numpy.zeros_like(pmap, dtype=numpy.uint32) binary[pmap >= pmin] = 1 # delete small CCs labeled = vigra.analysis.labelVolumeWithBackground(binary) skneuro.oversegmentation.sizeFilterSegInplace(labeled, int(numpy.max(labeled)), int(minMembraneSize), checkAtBorder=True) # use cleaned binary image as mask mask = numpy.zeros_like(binary, dtype=numpy.float32) mask[labeled > 0] = 1. # perform signed dt on mask dt = vigra.filters.distanceTransform3D(mask) dtInv = vigra.filters.distanceTransform3D(mask, background=False) dtInv[dtInv > 0] -= 1 dtSigned = dt.max() - dt + dtInv dtSignedSmoothMinima = vigra.filters.gaussianSmoothing( dtSigned, sigmaMinima) dtSignedSmoothWeights = vigra.filters.gaussianSmoothing( dtSigned, sigmaWeights) seeds = vigra.analysis.localMinima3D(dtSignedSmoothMinima, neighborhood=26, allowAtBorder=True) if cleanCloseSeeds: seeds = nonMaximumSuppressionSeeds(volumeToListOfPoints(seeds), dt) seeds = placePointsInVolumen(seeds, mask.shape).astype(numpy.uint32) seedsLabeled = vigra.analysis.labelVolumeWithBackground(seeds) segmentation = vigra.analysis.watershedsNew(dtSignedSmoothWeights, seeds=seedsLabeled, neighborhood=26)[0] skneuro.oversegmentation.sizeFilterSegInplace(segmentation, int(numpy.max(segmentation)), int(minSegmentSize), checkAtBorder=True) segmentation = vigra.analysis.watershedsNew(dtSignedSmoothWeights, seeds=segmentation, neighborhood=26)[0] return segmentation
def findBestSeedCloserThanMembrane(seeds, distances, distanceTrafo, membraneDistance): """ finds the best seed of the given seeds, that is the seed with the highest value distance transformation.""" closeSeeds = distances <= membraneDistance numpy.zeros_like(closeSeeds) # iterate over all close seeds maximumDistance = -numpy.inf mostCentralSeed = None for seed in seeds[closeSeeds]: if distanceTrafo[seed[0], seed[1], seed[2]] > maximumDistance: maximumDistance = distanceTrafo[seed[0], seed[1], seed[2]] mostCentralSeed = seed return mostCentralSeed
def wsDtSegmentation(pmap, pmin, minMembraneSize, minSegmentSize, sigmaMinima, sigmaWeights, cleanCloseSeeds=True): # get the thresholded pmap binary = numpy.zeros_like(pmap, dtype=numpy.uint32) binary[pmap >= pmin] = 1 # delete small CCs labeled = vigra.analysis.labelVolumeWithBackground(binary) skneuro.oversegmentation.sizeFilterSegInplace(labeled, int(numpy.max(labeled)), int(minMembraneSize), checkAtBorder=True) # use cleaned binary image as mask mask = numpy.zeros_like(binary, dtype = numpy.float32) mask[labeled > 0] = 1. # perform signed dt on mask dt = vigra.filters.distanceTransform3D(mask) dtInv = vigra.filters.distanceTransform3D(mask, background=False) dtInv[dtInv>0] -= 1 dtSigned = dt.max() - dt + dtInv dtSignedSmoothMinima = vigra.filters.gaussianSmoothing(dtSigned, sigmaMinima) dtSignedSmoothWeights = vigra.filters.gaussianSmoothing(dtSigned, sigmaWeights) seeds = vigra.analysis.localMinima3D(dtSignedSmoothMinima, neighborhood=26, allowAtBorder=True) if cleanCloseSeeds: seeds = nonMaximumSuppressionSeeds(volumeToListOfPoints(seeds), dt) seeds = placePointsInVolumen(seeds, mask.shape).astype(numpy.uint32) seedsLabeled = vigra.analysis.labelVolumeWithBackground(seeds) segmentation = vigra.analysis.watershedsNew(dtSignedSmoothWeights, seeds = seedsLabeled, neighborhood=26)[0] skneuro.oversegmentation.sizeFilterSegInplace(segmentation, int(numpy.max(segmentation)), int(minSegmentSize), checkAtBorder=True) segmentation = vigra.analysis.watershedsNew(dtSignedSmoothWeights, seeds = segmentation, neighborhood=26)[0] return segmentation