コード例 #1
0
ファイル: testpp.py プロジェクト: XiaoweiXu/vasctree
def test_nxvascDijkstra():
    """tests the information gathered using the Dijkstra algorithm"""
    import nxvasc
    import dicom
    import numpy as na
    import fomFuncs
    import costFuncs
    #img=io.readImage("PE00026Filter0_seg.mha", returnITK=False,  imgMode='uchar')
    #mask = na.where(img>0,1,0)
    img=dicom.read_file("data/tree2.dcm")
    array=img.pixel_array
    mask = na.where(array>0, 1, 0)
    vx = nxvasc.nxvasc()
    vx.setMask(mask)
    vx.generateRawFigureOfMeritData()
    vx.setFigureOfMeritF(fomFuncs.fomf1)
    vx.setCostFunction(costFuncs.cf1)
    vx.createMaskDictionary()
    vx.fillFigureOfMerit()
    vx.createNXGraph(verbose=True)
    vx.getDijkstraPaths(verbose=True) #uses the dijkstra algorithm to find paths
    vx.traceBackPaths()
    print("trace back paths")
    vx.pruneSplitPaths()
    print("prune paths")
    vx.showPaths(list(vx.paths.values()))
    input('continue')
    vx.showPaths(vx.splitPaths,label="Orthogonal MIP Images with Centerlines")
    input('continue')
    vx.plotPaths(vx.splitPaths,label="firstPlot",show=True)
    input('continue')
    print("FINISHED")
コード例 #2
0
ファイル: test.py プロジェクト: chapmanbe/vasctree
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')
コード例 #3
0
ファイル: test.py プロジェクト: chapmanbe/vasctree
def test_mipEndPoints():
    import nxvasc
    import dicom
    import fomFuncs
    import costFuncs
    img=dicom.read_file("data/tree2.dcm")
    array=img.pixel_array
    mask = na.where(array>0, 1, 0)
    #mask = createPhantom3()
    vx = nxvasc.nxvasc()
    vx.setOutputFile("testnx.out")
    vx.setMask(mask)
    vx.getMaskMips()
    vx.define3x3_2DEndpointKernels()
    vx.endPointDetection2D()
    vx.viewEndPoints()
    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.traceBackPaths4()
    print("prune paths")
    vx.pruneSplitPaths()
    print("plot paths")
    vx.showPaths(list(vx.paths.values()))
    input('continue')
    vx.showPaths(vx.splitPaths,label="Orthogonal MIP Images with Centerlines")
    input('continue')
    vx.plotPaths(vx.splitPaths,label="firstPlot",show=True)
    input('continue')
コード例 #4
0
ファイル: test.py プロジェクト: chapmanbe/vasctree
def test_nxvasc1():
    """Uses an exhaustive search for determining the bifurcation points"""
    import nxvasc
    import fomFuncs
    import costFuncs
    import dicom   
    img=dicom.read_file("data/tree2.dcm")
    array=img.pixel_array
    mask = na.where(array>0, 1, 0)
    #mask = createPhantom2()
    vx = nxvasc.nxvasc() #calls the class nxvasc and fxn 3x3matrix
    vx.setOutputFile("testnx1.out") #Sets the objects mask to image located in the maskfile
    vx.setMask(mask) 
    vx.generateRawFigureOfMeritData()
    vx.setFigureOfMeritF(fomFuncs.fomf1)
    vx.setCostFunction(costFuncs.cf1)
    vx.createMaskDictionary()
    vx.fillFigureOfMerit()
    vx.createNXGraph(verbose=True)
    vx.getDijkstraPaths(verbose=True)
    temp1 = copy.deepcopy(vx.paths)
    t4_start = time.time()
    vx.traceBackPaths4()
    t4_stop = time.time()
    vx.paths = copy.deepcopy(temp1)
    t2_start = time.time()
    vx.traceBackPaths2()
    t2_stop = time.time()
    vx.paths = copy.deepcopy(temp1)
    t1_start = time.time()
    vx.traceBackPaths1()
    t1_stop = time.time()
    print("time for algorithm4:",t4_stop-t4_start)
    print("time for algorithm2:",t2_stop-t2_start)
    print("time for algorithm1:",t1_stop-t1_start)
コード例 #5
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')
コード例 #6
0
def test_mipEndPoints():
    import nxvasc
    import dicom
    import fomFuncs
    import costFuncs
    img = dicom.read_file("data/tree2.dcm")
    array = img.pixel_array
    mask = na.where(array > 0, 1, 0)
    #mask = createPhantom3()
    vx = nxvasc.nxvasc()
    vx.setOutputFile("testnx.out")
    vx.setMask(mask)
    vx.getMaskMips()
    vx.define3x3_2DEndpointKernels()
    vx.endPointDetection2D()
    vx.viewEndPoints()
    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.traceBackPaths4()
    print("prune paths")
    vx.pruneSplitPaths()
    print("plot paths")
    vx.showPaths(list(vx.paths.values()))
    input('continue')
    vx.showPaths(vx.splitPaths, label="Orthogonal MIP Images with Centerlines")
    input('continue')
    vx.plotPaths(vx.splitPaths, label="firstPlot", show=True)
    input('continue')
コード例 #7
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)
コード例 #8
0
ファイル: class_test.py プロジェクト: XiaoweiXu/vasctree
 def setUp(self):
     """setUp is called before each test is run, tearDown is called after"""
     self.img = dicom.read_file("data/tree2.dcm")
     self.array = self.img.pixel_array
     self.mask = na.where(self.array > 0, 1, 0)
     self.vx = nxvasc.nxvasc()
     self.vx.setMask(self.mask)
     self.vx.getMaskMips()
     self.vx.define3x3_2DEndpointKernels()
     self.vx.endPointDetection2D()
     self.vx.generateRawFigureOfMeritData()
     self.vx.setFigureOfMeritF(fomFuncs.fomf1)
     self.vx.setCostFunction(costFuncs.cf1)
     self.vx.createMaskDictionary()
     self.vx.fillFigureOfMerit()
     self.vx.createNXGraph(verbose=True)
コード例 #9
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)
コード例 #10
0
ファイル: test.py プロジェクト: chapmanbe/vasctree
def test_nxvasc():
    """Uses sets for determining biforcation points"""
    import nxvasc
    import fomFuncs
    import costFuncs
    import dicom
    vx = nxvasc.nxvasc()
    vx.setOutputFile("testnx.out")
    vx.setMask(mask)
    vx.generateRawFigureOfMeritData()
    vx.setFigureOfMeritF(fomFuncs.fomf1)
    vx.setCostFunction(costFuncs.cf1)
    vx.createMaskDictionary()
    vx.fillFigureOfMerit()
    vx.createNXGraph(verbose=True)
    vx.getDijkstraPaths(verbose=True)
    vx.traceBackPaths()
    vx.pruneSplitPaths()
    vx.plotPaths(label="firstPlot",show=True)
    print("FINISHED")
コード例 #11
0
def test_nxvasc():
    """Uses sets for determining biforcation points"""
    import nxvasc
    import fomFuncs
    import costFuncs
    import dicom
    vx = nxvasc.nxvasc()
    vx.setOutputFile("testnx.out")
    vx.setMask(mask)
    vx.generateRawFigureOfMeritData()
    vx.setFigureOfMeritF(fomFuncs.fomf1)
    vx.setCostFunction(costFuncs.cf1)
    vx.createMaskDictionary()
    vx.fillFigureOfMerit()
    vx.createNXGraph(verbose=True)
    vx.getDijkstraPaths(verbose=True)
    vx.traceBackPaths()
    vx.pruneSplitPaths()
    vx.plotPaths(label="firstPlot", show=True)
    print("FINISHED")
コード例 #12
0
def test_nxvasc1():
    """Uses an exhaustive search for determining the bifurcation points"""
    import nxvasc
    import fomFuncs
    import costFuncs
    import dicom
    img = dicom.read_file("data/tree2.dcm")
    array = img.pixel_array
    mask = na.where(array > 0, 1, 0)
    #mask = createPhantom2()
    vx = nxvasc.nxvasc()  #calls the class nxvasc and fxn 3x3matrix
    vx.setOutputFile(
        "testnx1.out")  #Sets the objects mask to image located in the maskfile
    vx.setMask(mask)
    vx.generateRawFigureOfMeritData()
    vx.setFigureOfMeritF(fomFuncs.fomf1)
    vx.setCostFunction(costFuncs.cf1)
    vx.createMaskDictionary()
    vx.fillFigureOfMerit()
    vx.createNXGraph(verbose=True)
    vx.getDijkstraPaths(verbose=True)
    temp1 = copy.deepcopy(vx.paths)
    t4_start = time.time()
    vx.traceBackPaths4()
    t4_stop = time.time()
    vx.paths = copy.deepcopy(temp1)
    t2_start = time.time()
    vx.traceBackPaths2()
    t2_stop = time.time()
    vx.paths = copy.deepcopy(temp1)
    t1_start = time.time()
    vx.traceBackPaths1()
    t1_stop = time.time()
    print("time for algorithm4:", t4_stop - t4_start)
    print("time for algorithm2:", t2_stop - t2_start)
    print("time for algorithm1:", t1_stop - t1_start)
コード例 #13
0
import os
import sys
sys.path.append('../')
import nxvasc
import pickle
import numpy as na
import scipy
import math
import imageTools.ITKUtils.io as io
        
#Read in modified .pckle file from 5x5endpointMatch.py
endpoints=open('Modifiedf0MipEndpoints5x5.pckle','rb')
crds=pickle.load(endpoints)
img= io.readImage('PE00026Filter0_seg.mha',  returnITK=False,  imgMode='uchar')
mask = na.where(img>0, 1, 0) #create the mask
instance=nxvasc.nxvasc()#create an instance of the class
output=open("Configuration5x5.pckle", 'wb') #Need to store the output for the 5x5 
instance.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
instance.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
instance.get5x5matrix() #define relationship between neighbors
#get the crds of all pts within the 5x5 neighborhood of index (i) 
Neighbors=[] #to store arrays of neighbors for each point
for crd in crds:  \
    #grab the 5x5x5 neighborhood 
    neighbors = mask[crd[2]-2:crd[2]+3, crd[1]-2:crd[1]+3,  crd[0]-2:crd[0]+3]
    Neighbors.append(neighbors)
pickle.dump([Neighbors, crds],  output) 
コード例 #14
0
the actual endpoint. The output is saved as Configuration7X7.pckle and contains the neighbors of the identified true endpoints, 
whether it is the original point or replaced by a neighbor in endpointMatch.py. Gets the 7X7X7 neighborhood of the neighbors"""

import os
import sys
sys.path.append('../../vasctrees')
import nxvasc
import pickle
import numpy as na
import scipy
import math
import imageTools.ITKUtils.io as io

#Read in modified .pckle file from 7x7endpointMatch.py
endpoints = open('Modifiedf0MipEndpoints.pckle', 'rb')
crds = pickle.load(endpoints)
img = io.readImage('PE00014Filter0_seg.mha', returnITK=False, imgMode='uchar')
mask = na.where(img > 0, 1, 0)  #create the mask
instance = nxvasc.nxvasc()  #create an instance of the class
output = open("Configuration7x7.pckle", 'wb')
instance.setMask(mask)
instance.createMaskDictionary()
instance.get7x7matrix()
#get the crds of all pts within the 7x7 neighborhood of index (i)
Neighbors = []  #to store arrays of neighbors for each point
for crd in crds:
    neighbors = mask[crd[2] - 3:crd[2] + 4, crd[1] - 3:crd[1] + 4,
                     crd[0] - 3:crd[0] + 4]
    Neighbors.append(neighbors)
pickle.dump([Neighbors, crds], output)
コード例 #15
0
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,
                     crd[0] - 2:crd[0] + 3]
    print(neighbors)
    ModifiedSampledPoints.append(neighbors)
for M in ModifiedSampledPoints:
    #print M
コード例 #16
0
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:
        crds=point.get_crds(i)
        print(crds)