示例#1
0
def main():
    #fo = file("../Skeletons/PE00000_edited_skeleton_graphs.pckle","rb")
    fo = file("PE00000_edited_bc_333_skeleton_graphs.pckle", "rb")
    data = cPickle.load(fo)
    ogs = data["orderedGraphs"]
    g = ogs[(0, u'0')]
    oldSize = g.size()
    iter = 0
    while (True):
        prune(g)
        iter += 1
        newSize = g.size()
        if (newSize == oldSize):
            break
        else:
            oldSize = newSize
        print iter, oldSize

    dg = np.array(g.degree().values())
    print dg.max(), dg.min(), dg.mean()
    imgitk = io.readImage("PE00000.mha", returnITK=True, imgMode='sshort')
    img = itk.PyBuffer.ISS3.GetArrayFromImage(imgitk)
    spacing = imgitk.GetSpacing()

    #img2 = img.copy()
    #vimg = insertGraphInImage(g,img2)
    #a3d.call(data = [vimg])
    #for i in range(20):
    #    randomNode = pickRandomNodeOfDegree(g)
    #    h = getNodeSubgraph(g,randomNode)
    #
    #    visualizeXY_MPL(h,img,buffer=20)
    fo = file("PE00000_edited_bc_333_skeleton_graphs_pruned.pckle", "wb")
    cPickle.dump(g, fo)
示例#2
0
def main():
    #fo = file("../Skeletons/PE00000_edited_skeleton_graphs.pckle","rb")
    fo = file("PE00000_edited_bc_333_skeleton_graphs.pckle","rb")
    data = cPickle.load(fo)
    ogs = data["orderedGraphs"]
    g = ogs[(0,u'0')]
    oldSize = g.size()
    iter = 0
    while(True):
        prune(g)
        iter += 1
        newSize =  g.size()
        if( newSize == oldSize ):
            break
        else:
            oldSize = newSize
        print iter, oldSize
        
    dg = np.array(g.degree().values())
    print dg.max(), dg.min(), dg.mean()
    imgitk = io.readImage("PE00000.mha",returnITK=True,imgMode='sshort')
    img = itk.PyBuffer.ISS3.GetArrayFromImage(imgitk)
    spacing = imgitk.GetSpacing()
    
    #img2 = img.copy()
    #vimg = insertGraphInImage(g,img2)
    #a3d.call(data = [vimg])
    #for i in range(20):
    #    randomNode = pickRandomNodeOfDegree(g)
    #    h = getNodeSubgraph(g,randomNode)
    #    
    #    visualizeXY_MPL(h,img,buffer=20)
    fo = file("PE00000_edited_bc_333_skeleton_graphs_pruned.pckle","wb")
    cPickle.dump(g,fo)
示例#3
0
def test_critEnds():
    import nxvasc
    import dicom
    import fomFuncs
    import costFuncs
    import imageTools.ITKUtils.io as io
    #img=dicom.read_file("data/tree2.dcm")
    #array=img.pixel_array
    #mask = na.where(array>0, 1, 0)
    img = io.readImage("data/p16Mask.mha",returnITK=False,imgMode="uchar")
    mask = na.where(img>0,1,0)
    #mask = createPhantom3()
    vx = nxvasc.nxvasc()
    vx.setOutputFile("testnx.out")
    vx.setMask(mask)
    vx.getMaskMips()
    vx.endPointsFromCritPoints("data/ends.pckle")
    vx.generateRawFigureOfMeritData()
    vx.setFigureOfMeritF(fomFuncs.fomf1)
    vx.setCostFunction(costFuncs.cf1)
    vx.createMaskDictionary()
    vx.fillFigureOfMerit()
    vx.createNXGraph(verbose=True)
    vx.getEndPointPaths()
    print("trace back paths")
    vx.traceBackPaths5()
    print("plot paths")
    vx.showPaths(vx.getSGPaths(),label="Orthogonal MIP Images with Centerlines-SG")
    input('continue')
示例#4
0
def test_critEnds():
    import nxvasc
    import dicom
    import fomFuncs
    import costFuncs
    import imageTools.ITKUtils.io as io
    #img=dicom.read_file("data/tree2.dcm")
    #array=img.pixel_array
    #mask = na.where(array>0, 1, 0)
    img = io.readImage("data/p16Mask.mha", returnITK=False, imgMode="uchar")
    mask = na.where(img > 0, 1, 0)
    #mask = createPhantom3()
    vx = nxvasc.nxvasc()
    vx.setOutputFile("testnx.out")
    vx.setMask(mask)
    vx.getMaskMips()
    vx.endPointsFromCritPoints("data/ends.pckle")
    vx.generateRawFigureOfMeritData()
    vx.setFigureOfMeritF(fomFuncs.fomf1)
    vx.setCostFunction(costFuncs.cf1)
    vx.createMaskDictionary()
    vx.fillFigureOfMerit()
    vx.createNXGraph(verbose=True)
    vx.getEndPointPaths()
    print("trace back paths")
    vx.traceBackPaths5()
    print("plot paths")
    vx.showPaths(vx.getSGPaths(),
                 label="Orthogonal MIP Images with Centerlines-SG")
    input('continue')
示例#5
0
def A_Star():
    img=io.readImage("PE00025Filter0_seg.mha", returnITK=False, imgMode='uchar')
    mask=na.where(img>0,1,0)
    instance=nxvasc.nxvasc()
    instance.setmask(mask)
    indexes=open("Indexes.pckle",'rb')
    inds=pickle.load(indexes)
    graph=open("PE00025NXgraph.pckle",'rb')
    G=pickle.load(graph)
    instance.generateRawFigureOfMerit()
    instance.setFigureOfMeritF(fomFuncs.fom1)
    instance.setCostFunction(costFuncs.cf1)
    instance.GenerateAstarPaths(G, inds)
    path=open("PE00025A_StarPaths.pckle", 'wb')
    pickle.dump(self.paths,  path)
示例#6
0
def GenerateNonEndpointPaths():
    graph=open("PE000026NENXGraph.pckle", "wb") #stores the graph
    #paths=open("PE00026Paths.pckle", "wb") #stores the paths
   #indexes=open("Indexes.pckle", "wb") #stores the index locations for each set of crds.
    endpoints=open("PE00026Nonendpoints.pckle", 'rb')
    inds=pickle.load(endpoints)
    img=io.readImage("PE000026Filter0_seg.mha",  returnITK=False,  imgMode="uchar")
    mask = na.where(img>0, 1, 0)
    instance=VascMask.VascMask()
    instance.setMask(mask)
    instance.setNeighborhoodSize(sz=3)
    instance.getFOM()
    #inds=instance.getInds(crds)
    instance.createNXGraph()
    pickle.dump(inds, indexes)
    pickle.dump(instance.G, graph)
示例#7
0
def GenerateGraph():
    graph=open("PE00025CompleteNXGraph.pckle", "wb") #stores the graph
    img=io.readImage("PE00025Filter0_seg.mha",returnITK=False,imgMode="uchar")
    print("image loaded")
    mask = na.where(img>0, 1, 0)
    print("mask created")
    instance=VascMask.VascMask()
    print("class instance generated")
    instance.setMask(mask)
    print("mask set")
    instance.setNeighborhoodSize(sz=3)
    print("Neighborhood gathered")
    instance.getFOM()
    print("FOM obtained")
    instance.createNXGraph()
    pickle.dump(instance.G, graph)
示例#8
0
def A_Star():
    img = io.readImage("PE00025Filter0_seg.mha",
                       returnITK=False,
                       imgMode='uchar')
    mask = na.where(img > 0, 1, 0)
    instance = nxvasc.nxvasc()
    instance.setmask(mask)
    indexes = open("Indexes.pckle", 'rb')
    inds = pickle.load(indexes)
    graph = open("PE00025NXgraph.pckle", 'rb')
    G = pickle.load(graph)
    instance.generateRawFigureOfMerit()
    instance.setFigureOfMeritF(fomFuncs.fom1)
    instance.setCostFunction(costFuncs.cf1)
    instance.GenerateAstarPaths(G, inds)
    path = open("PE00025A_StarPaths.pckle", 'wb')
    pickle.dump(self.paths, path)
示例#9
0
def GenerateGraph():
    graph = open("PE00025CompleteNXGraph.pckle", "wb")  #stores the graph
    img = io.readImage("PE00025Filter0_seg.mha",
                       returnITK=False,
                       imgMode="uchar")
    print("image loaded")
    mask = na.where(img > 0, 1, 0)
    print("mask created")
    instance = VascMask.VascMask()
    print("class instance generated")
    instance.setMask(mask)
    print("mask set")
    instance.setNeighborhoodSize(sz=3)
    print("Neighborhood gathered")
    instance.getFOM()
    print("FOM obtained")
    instance.createNXGraph()
    pickle.dump(instance.G, graph)
示例#10
0
def main2():
    #fo = file("../Skeletons/PE00000_edited_skeleton_graphs_pruned.pckle","rb")
    fo = file("PE00000_edited_bc_333_skeleton_graphs_pruned.pckle", "rb")
    #fo = file("PE00000_edited_bc_333_skeleton_graphs.pckle","rb")
    g = cPickle.load(fo)

    oldSize = g.size()
    iter = 0

    #print "drop short edges"
    #pruner(g,prune)
    #while(True):
    #    pruneTwosers(g)
    #    iter += 1
    #    newSize =  g.size()
    #    if( newSize == oldSize ):
    #        break
    #    else:
    #        oldSize = newSize
    #    print iter, oldSize
    #raw_input('continue')

    imgitk = io.readImage("PE00000_edited_bc_333.mha",
                          returnITK=True,
                          imgMode='sshort')
    img = itk.PyBuffer.ISS3.GetArrayFromImage(imgitk)
    spacing = imgitk.GetSpacing()
    #viewImg(img,[1,1,1], [1,],g)
    #viewImg(img,spacing, [1,])
    print "eliminate degree two nodes"
    pruner(g, pruneTwosers)
    nodes = [(94, 301, 275), (58, 221, 168), (76, 300, 183), (97, 270, 118),
             (341, 319, 256)]
    for i in range(20):
        randomNode = pickRandomNodeOfDegree(g)
        #for randomNode in nodes:
        print "randomly selected node is", randomNode
        h = getNodeSubgraph(g, randomNode)

        visualizeXY_MPL(h, img, randomNode, spacing, buffer=20)
示例#11
0
def main2():
    #fo = file("../Skeletons/PE00000_edited_skeleton_graphs_pruned.pckle","rb")
    fo = file("PE00000_edited_bc_333_skeleton_graphs_pruned.pckle","rb")
    #fo = file("PE00000_edited_bc_333_skeleton_graphs.pckle","rb")
    g = cPickle.load(fo)
    
    oldSize = g.size()
    iter = 0

    #print "drop short edges"
    #pruner(g,prune)
    #while(True):
    #    pruneTwosers(g)
    #    iter += 1
    #    newSize =  g.size()
    #    if( newSize == oldSize ):
    #        break
    #    else:
    #        oldSize = newSize
    #    print iter, oldSize
    #raw_input('continue')

    imgitk = io.readImage("PE00000_edited_bc_333.mha",returnITK=True,imgMode='sshort')
    img = itk.PyBuffer.ISS3.GetArrayFromImage(imgitk)
    spacing = imgitk.GetSpacing()
    #viewImg(img,[1,1,1], [1,],g)
    #viewImg(img,spacing, [1,])
    print "eliminate degree two nodes"
    pruner(g,pruneTwosers)
    nodes = [(94, 301, 275), (58, 221, 168),(76, 300, 183),(97, 270, 118),(341, 319, 256)]
    for i in range(20):
        randomNode = pickRandomNodeOfDegree(g)
    #for randomNode in nodes:
        print "randomly selected node is",randomNode
        h = getNodeSubgraph(g,randomNode)
        
        visualizeXY_MPL(h,img,randomNode, spacing, buffer=20)
示例#12
0
    pyplot.title("mipy")
    pyplot.subplot(223)
    pyplot.title("mipx")
    pyplot.imshow(slice2,  interpolation = 'nearest')
    figure = pyplot.show()
    input('continue')
 
#Read in modified .pckle file
endpoints=open('Modifiedf0MipEndpoints.pckle','rb')
#endpoints=sys.argv[1]
#fo = open(endpoints,'rb')
#crds=cPickle.load(fo)
crds = pickle.load(endpoints)
#Read in image
#img= io.readImage(str(sys.argv[2]),  returnITK=False,  imgMode='uchar')
img= io.readImage('PE00026Filter0_seg.mha',  returnITK=False,  imgMode='uchar')
mask = na.where(img>0, 1, 0) #create the mask
point=nxvasc.nxvasc() #create an instance of the class
point.setMask(mask) #Set the mask using the numpy image mask. In addition to
#reading the mask, the 1D indicies into the 3D image are generate and stored
point.createMaskDictionary() #Create dictionary that maps the index into the 3D
#volume to an index into the mask. The 1D array into the 3D volume is the key &
#the ordinal position of the index is the value
point.get3x3matrix() #define relationship between neighbors
inds=point.getInds(crds)#get corresponding indexes
#get the crds of all pts within the 3x3 or 26-point neighborhood of index (i) 
for crd in crds:
    #grab the 3x3 neighborhood of i and convert to list
    neighbors = mask[crd[2]-1:crd[2]+2, crd[1]-1:crd[1]+2,  crd[0]-1:crd[0]+2]  
    #plot=showPoints(point, neighbors)
#    get the orthogonal (x,y,z) MIPS of the mask.
#5x5identifyNonEndpoints.py
import os
import sys
"""Goes and grabs the 5x5 neighborhoods of the non endpoints"""
sys.path.append("../vasctrees")
import numpy as na
import random
import pickle
import imageTools.ITKUtils.io as io
import nxvasc
from sliceOrientation import OrientMask

img = io.readImage("PE00001Filter0_seg.mha", returnITK=False, imgMode="uchar")
nonPoints = open("PE00001NonEndpoints.pckle", 'rb')
nonendpoints = pickle.load(
    nonPoints)  #points from ModifiedGenerateNonEndpoints.py
output2 = open("PE00001NeighborsNonPoints5x5.pckle",
               'wb')  #store 5x5 neighborhood
#Must create the mask so we can identify the points that are not endpoints
mask = na.where(img > 0, 1, 0)
point = nxvasc.nxvasc()
point.setMask(mask)
point.createMaskDictionary()
point.get5x5matrix()
crds = point.get_crds(nonendpoints)
ModifiedSampledPoints = []
ModifiedPoints = []
for crd in crds:
    print(crd)
    #get the neighbors to add up the neighborhood
    neighbors = mask[crd[2] - 2:crd[2] + 3, crd[1] - 2:crd[1] + 3,
"""The purpose of this code is to perform random sampling of non-endpoints
and grab the 7x7 neighborhoods"""
import os
import sys
sys.path.append("../vasctrees")
import nxvasc
from sliceOrientation import OrientMask
import imageTools.ITKUtils.io as io
import scipy.ndimage as ndi
import numpy as na
import pickle

fle=open("PE00001NonEndpoints.pckle",'wb')
output2=open("PE00001NeighborsNonPoints7x7.pckle", 'wb')
img=io.readImage("PE00001Filter0_seg.mha", returnITK=False, imgMode="uchar")
#Must create the mask so we can identify the points that are not endpoints
mask=na.where(img>0, 1, 0)
point=nxvasc.nxvasc()
point.setMask(mask)
point.createMaskDictionary()
point.get7x7matrix()
f1=ndi.distance_transform_cdt(img)
surface=na.where(f1==1,1,0)
indsSurface =na.nonzero(surface.flat==1)[0]
length=len(indsSurface)
print("length",length)
ModifiedSampledPoints=[]
ModifiedPoints=[]
points=[]
for i in indsSurface:
    if len(ModifiedPoints)<112: