Пример #1
0
def placePointsInVolumen(points, shape):
    volumen = numpy.zeros(shape)
    points = numpy.maximum(points, numpy.array((0, 0, 0)))
    points = numpy.minimum(points, numpy.array(shape) - 1)
    for point in (numpy.floor(points)).astype(int):
        volumen[point[0], point[1], point[2]] = 1
    return volumen
Пример #2
0
def placePointsInVolumen(points, shape):
    volumen = numpy.zeros(shape)
    points = numpy.maximum(points, numpy.array((0, 0, 0)))
    points = numpy.minimum(points, numpy.array(shape) - 1)
    for point in (numpy.floor(points)).astype(int):
        volumen[point[0], point[1], point[2]] = 1
    return volumen
Пример #3
0
    def testAddEdges(self):
        IV = vigraph.INVALID
        elist = [[1, 3], [1, 5], [5, 7], [3, 4]]

        edges = np.array(elist, dtype=np.uint32)
        nodeIds = np.unique(edges.reshape(-1))

        g = vigraph.listGraph()

        edgeIds = g.addEdges(edges)

        assert g.edgeNum == len(elist)
        assert g.edgeNum == len(edgeIds)
        assert g.nodeNum == len(nodeIds)
        assert g.maxNodeId == nodeIds.max()

        for ui, vi in elist:
            assert g.findEdge(ui, vi) != IV
            assert g.findEdge(g.nodeFromId(ui), g.nodeFromId(vi)) != IV

        for nId in nodeIds:
            nId = int(nId)
            assert g.nodeFromId(nId) != IV

        for eId in edgeIds:
            eId = int(eId)
            assert g.edgeFromId(eId) != IV

        findEdges = g.findEdges(edges)

        assert np.array_equal(findEdges, edgeIds)
Пример #4
0
def test_convolution():
    krnl = gaussianKernel(0.5)
    
    k2_ = Kernel2D()
    k2_.initDisk(10)
    
    #k3 = gaussianDerivativeKernel(sigma, order)
    #guassianDerivative(img, sx,ox,sy,oy,sz,oz)
    #guassianDerivative(img, (sx,sy, sz), (ox, oy,oz))
    
    k2=Kernel2D()
    k2.initExplicitly((-1,-1),(1,1),np.array([[0,1,2],[1,2,3],[2,3,4]],dtype=np.float64))
    res = convolve(img_scalar_f, k2)
Пример #5
0
def test_convolution():
    krnl = gaussianKernel(0.5)
    
    k2_ = Kernel2D()
    k2_.initDisk(10)
    
    #k3 = gaussianDerivativeKernel(sigma, order)
    #guassianDerivative(img, sx,ox,sy,oy,sz,oz)
    #guassianDerivative(img, (sx,sy, sz), (ox, oy,oz))
    
    k2=Kernel2D()
    k2.initExplicitly((-1,-1),(1,1),np.array([[0,1,2],[1,2,3],[2,3,4]],dtype=np.float64))
    res = convolve(img_scalar_f, k2)
Пример #6
0
def nonMaximumSuppressionSeeds(seeds, distanceTrafo):
    """ removes all seeds that have a neigbour that is closer than the the next membrane

    seeds is a list of all seeds, distanceTrafo is array-like
    return is a list of all seeds that are relevant.

    works only for 3d
    """
    seedsCleaned = set()

    # calculate the distances from each seed to the next seeds.
    distances = cdist(seeds, seeds)
    for i in numpy.arange(len(seeds)):
        membraneDistance = distanceTrafo[seeds[i,0], seeds[i,1], seeds[i,2]]
        bestAlternative = findBestSeedCloserThanMembrane(seeds, distances[i,:], distanceTrafo, membraneDistance)
        seedsCleaned.add(tuple(bestAlternative))
    return numpy.array(list(seedsCleaned))
Пример #7
0
def nonMaximumSuppressionSeeds(seeds, distanceTrafo):
    """ removes all seeds that have a neigbour that is closer than the the next membrane

    seeds is a list of all seeds, distanceTrafo is array-like
    return is a list of all seeds that are relevant.

    works only for 3d
    """
    seedsCleaned = set()

    # calculate the distances from each seed to the next seeds.
    distances = cdist(seeds, seeds)
    for i in numpy.arange(len(seeds)):
        membraneDistance = distanceTrafo[seeds[i, 0], seeds[i, 1], seeds[i, 2]]
        bestAlternative = findBestSeedCloserThanMembrane(
            seeds, distances[i, :], distanceTrafo, membraneDistance)
        seedsCleaned.add(tuple(bestAlternative))
    return numpy.array(list(seedsCleaned))
Пример #8
0
    def testAddEdges(self):
        IV = vigraph.INVALID
        elist = [
            [1,3],
            [1,5],
            [5,7],
            [3,4]
        ] 

        edges = np.array(elist,dtype=np.uint32)
        nodeIds = np.unique(edges.reshape(-1))


        g = vigraph.listGraph()

        edgeIds = g.addEdges(edges)

        assert g.edgeNum == len(elist)
        assert g.edgeNum == len(edgeIds)
        assert g.nodeNum == len(nodeIds)
        assert g.maxNodeId == nodeIds.max()

        for ui,vi in elist :
            assert g.findEdge(ui,vi)!=IV
            assert g.findEdge(g.nodeFromId(ui),g.nodeFromId(vi))!=IV

        for nId in nodeIds :
            nId = int(nId)
            assert g.nodeFromId(nId)!=IV

        for eId in edgeIds :
            eId = int(eId)
            assert g.edgeFromId(eId)!=IV

        findEdges = g.findEdges(edges)

        assert np.array_equal(findEdges,edgeIds)
Пример #9
0
def prepareMinMap(raw, pmap, sPre=0.8, sInt=5.0, mapInterval=0.5,
                  scaleEw=4.0, ewBeta=0.01,
                  tvWeightSoft=None, isotropicTvSoft=True,
                  tvWeightHard=None, isotropicTvHard=True,
                  sPost=0.6, visu=False
                ):
    """

    """


    print "prepare stuff"
    if tvWeightSoft is None and isotropicTvSoft:
        tvWeightSoft=5.0
    elif tvWeightSoft is None and isotropicTvSoft==False:
        tvWeightSoft=25.0

    if tvWeightHard is None and isotropicTvHard:
        tvWeightHard=0.7
    elif tvWeightHard is None and isotropicTvHard==False:
        tvWeightHard=15.0


    grayData = []
    labelsData = []

    # do minimalistic raw map presmoothing to remove artifacts
    if sPre>0.0001:
        rawG = vigra.filters.gaussianSmoothing(numpy.require(raw ,dtype=numpy.float32), sigma=sPre)
    else :
        rawG = numpy.require(image,dtype=numpy.float32)



    print "pmap integral"
    # get pmap integral
    pmapIntegral = vigra.filters.gaussianSmoothing(numpy.require(pmap, dtype=numpy.float32), sigma=sInt )
    pmapIntegral = numpy.array(pmapIntegral)

    grayData.append([rawG,'rawG'])
    grayData.append([pmapIntegral,'pmapIntegral'])

    if visu:
        addHocViewer(grayData, labelsData, visu=visu)

    # remap integral
    pmapIntegral[pmapIntegral>mapInterval]=mapInterval
    pmapIntegral*=1.0/mapInterval



    print "soft tv"
    # do soft TV smoothing
    pmapTVSoft = denoise.tvBregman(pmap, weight=tvWeightSoft, isotropic=isotropicTvSoft).astype(numpy.float32)


    print "hard tv"
    # do hard heavy TV smoothing
    pmapTVHard = denoise.tvBregman(pmap, weight=tvWeightHard, isotropic=isotropicTvHard).astype(numpy.float32)



    grayData.append([pmapTVSoft,'pmapTVSoft'])
    grayData.append([pmapTVHard,'pmapTVHard'])

    if visu:
        addHocViewer(grayData, labelsData, visu=visu)


    # mix hard and soft according to pmap probability
    mixedPmap = numpy.empty(raw.shape)
    mixedPmap = (1.0 - pmapIntegral)*pmapTVHard  +  pmapIntegral*pmapTVSoft


    print "le min le max",mixedPmap.min(), mixedPmap.max()

    #grayData.append([mixedPmap,'mixedPmap'])
    #addHocViewer(grayData, labelsData, visu=visu)

    # add a tiny portion of eigenvalues of hessian give flat wide boundaries the min at the right position
    # but we only add this at places where the boundary is strong (in a hard fashion)
    aew = vigra.filters.hessianOfGaussianEigenvalues(numpy.require(raw, dtype=numpy.float32), scale=scaleEw).squeeze()
    sew = numpy.sort(aew,axis=3)
    ew = sew[:, :, :, 2]
    ew *= pmap**2
    ew -= ew.min()
    ew /= ew.max()
    ew *= ewBeta

    mixedPmap+=ew


    grayData.append([mixedPmap,'mixedPmapWITHEW'])
    if visu:
        addHocViewer(grayData, labelsData, visu=visu)


    # do minimalistic final smoothing to remove artefacts
    if sPre>0.0001:
        mixedPmapG = vigra.filters.gaussianSmoothing(numpy.require(mixedPmap,dtype=numpy.float32), sigma=sPost)
    else :
        mixedPmapG = numpy.require(mixedPmap,dtype=numpy.float32)

    grayData.append([mixedPmapG,'finalSeedingMap'])
    if visu:
        addHocViewer(grayData, labelsData, visu=visu)


    return mixedPmapG
Пример #10
0
def volumeToListOfPoints(seedsVolume, threshold=0.):
    return numpy.array(numpy.where(seedsVolume > threshold)).transpose()
Пример #11
0
 def constructSampleFeatureVector(self, f1, f2, pluginManager):
     featVec = pluginManager.applyTransitionFeatureVectorConstructionPlugins(f1, f2, self.selectedFeatures)
     return np.array(featVec)
Пример #12
0
    adjListGraph = graphs.listGraph()
    gridGraph = graphs.gridGraph(shape)
    rag = graphs.regionAdjacencyGraph(gridGraph, labels)
    rag.writeHDF5("bla.h5", "dset")

else:

    # load the region adjacency graph
    rag = graphs.loadGridRagHDF5("bla.h5", "dset")

print rag.labels.shape, rag.labels.dtype, type(rag.labels)

print "accumulate edge and node features"

edgeCuesMean = rag.accumulateEdgeFeatures(iEdgeMap(rag.baseGraph, data))
edgeCuesMean = numpy.array([edgeCuesMean, edgeCuesMean]).T

nodeCuesMean = rag.accumulateNodeFeatures(data)
nodeCuesMean = numpy.array([nodeCuesMean, nodeCuesMean]).T

mergeGraph = graphs.mergeGraph(rag)

featureManager = graphs.NeuroDynamicFeatures(rag, mergeGraph)

# assign features
print "edgeCuesShape", edgeCuesMean.shape

featureManager.assignEdgeCues(edgeCuesMean)
featureManager.assignNodeCues(nodeCuesMean)
featureManager.assignEdgeSizes(rag.edgeLengths())
featureManager.assignNodeSizes(rag.nodeSize())
Пример #13
0
    rag = graphs.regionAdjacencyGraph(gridGraph, labels)
    rag.writeHDF5("bla.h5", "dset")

else :

    # load the region adjacency graph
    rag = graphs.loadGridRagHDF5("bla.h5","dset")

print rag.labels.shape, rag.labels.dtype ,type(rag.labels)


print "accumulate edge and node features"


edgeCuesMean = rag.accumulateEdgeFeatures( iEdgeMap(rag.baseGraph, data) )
edgeCuesMean = numpy.array([edgeCuesMean, edgeCuesMean]).T

nodeCuesMean = rag.accumulateNodeFeatures(data)
nodeCuesMean = numpy.array([nodeCuesMean, nodeCuesMean]).T



mergeGraph = graphs.mergeGraph(rag)


featureManager = graphs.NeuroDynamicFeatures(rag, mergeGraph)

# assign features
print "edgeCuesShape", edgeCuesMean.shape

featureManager.assignEdgeCues(edgeCuesMean)
Пример #14
0
def prepareMinMap(raw,
                  pmap,
                  sPre=0.8,
                  sInt=5.0,
                  mapInterval=0.5,
                  scaleEw=4.0,
                  ewBeta=0.01,
                  tvWeightSoft=None,
                  isotropicTvSoft=True,
                  tvWeightHard=None,
                  isotropicTvHard=True,
                  sPost=0.6,
                  visu=False):
    """

    """

    print "prepare stuff"
    if tvWeightSoft is None and isotropicTvSoft:
        tvWeightSoft = 5.0
    elif tvWeightSoft is None and isotropicTvSoft == False:
        tvWeightSoft = 25.0

    if tvWeightHard is None and isotropicTvHard:
        tvWeightHard = 0.7
    elif tvWeightHard is None and isotropicTvHard == False:
        tvWeightHard = 15.0

    grayData = []
    labelsData = []

    # do minimalistic raw map presmoothing to remove artifacts
    if sPre > 0.0001:
        rawG = vigra.filters.gaussianSmoothing(numpy.require(
            raw, dtype=numpy.float32),
                                               sigma=sPre)
    else:
        rawG = numpy.require(image, dtype=numpy.float32)

    print "pmap integral"
    # get pmap integral
    pmapIntegral = vigra.filters.gaussianSmoothing(numpy.require(
        pmap, dtype=numpy.float32),
                                                   sigma=sInt)
    pmapIntegral = numpy.array(pmapIntegral)

    grayData.append([rawG, 'rawG'])
    grayData.append([pmapIntegral, 'pmapIntegral'])

    if visu:
        addHocViewer(grayData, labelsData, visu=visu)

    # remap integral
    pmapIntegral[pmapIntegral > mapInterval] = mapInterval
    pmapIntegral *= 1.0 / mapInterval

    print "soft tv"
    # do soft TV smoothing
    pmapTVSoft = denoise.tvBregman(pmap,
                                   weight=tvWeightSoft,
                                   isotropic=isotropicTvSoft).astype(
                                       numpy.float32)

    print "hard tv"
    # do hard heavy TV smoothing
    pmapTVHard = denoise.tvBregman(pmap,
                                   weight=tvWeightHard,
                                   isotropic=isotropicTvHard).astype(
                                       numpy.float32)

    grayData.append([pmapTVSoft, 'pmapTVSoft'])
    grayData.append([pmapTVHard, 'pmapTVHard'])

    if visu:
        addHocViewer(grayData, labelsData, visu=visu)

    # mix hard and soft according to pmap probability
    mixedPmap = numpy.empty(raw.shape)
    mixedPmap = (1.0 - pmapIntegral) * pmapTVHard + pmapIntegral * pmapTVSoft

    print "le min le max", mixedPmap.min(), mixedPmap.max()

    #grayData.append([mixedPmap,'mixedPmap'])
    #addHocViewer(grayData, labelsData, visu=visu)

    # add a tiny portion of eigenvalues of hessian give flat wide boundaries the min at the right position
    # but we only add this at places where the boundary is strong (in a hard fashion)
    aew = vigra.filters.hessianOfGaussianEigenvalues(numpy.require(
        raw, dtype=numpy.float32),
                                                     scale=scaleEw).squeeze()
    sew = numpy.sort(aew, axis=3)
    ew = sew[:, :, :, 2]
    ew *= pmap**2
    ew -= ew.min()
    ew /= ew.max()
    ew *= ewBeta

    mixedPmap += ew

    grayData.append([mixedPmap, 'mixedPmapWITHEW'])
    if visu:
        addHocViewer(grayData, labelsData, visu=visu)

    # do minimalistic final smoothing to remove artefacts
    if sPre > 0.0001:
        mixedPmapG = vigra.filters.gaussianSmoothing(numpy.require(
            mixedPmap, dtype=numpy.float32),
                                                     sigma=sPost)
    else:
        mixedPmapG = numpy.require(mixedPmap, dtype=numpy.float32)

    grayData.append([mixedPmapG, 'finalSeedingMap'])
    if visu:
        addHocViewer(grayData, labelsData, visu=visu)

    return mixedPmapG
Пример #15
0
def volumeToListOfPoints(seedsVolume, threshold=0.):
    return numpy.array(numpy.where(seedsVolume > threshold)).transpose()
 def constructSampleFeatureVector(self, f1, f2, pluginManager):
     featVec = pluginManager.applyTransitionFeatureVectorConstructionPlugins(f1, f2, self.selectedFeatures)
     return np.array(featVec)