示例#1
0
    # Sample points
    sampleIds = get_random_points(model, SAMPLE_RATE)
    progressPoints = [int(len(sampleIds) / 10 * (k + 1)) for k in range(10)
                      ]  # just to get some progress meter action

    # Go through each sample, create features and label for that sample
    for j, sID in enumerate(sampleIds):
        if j in progressPoints:  # print out some progress
            print("About {} percent of {} sample points processed.".format(
                (progressPoints.index(j) + 1) * 10, len(sampleIds)))
        if PATCH_METHOD == "order":
            samplePatch = create_patch(model, modelGraph, idArray, invIdArray,
                                       sID, ORDER)
        elif PATCH_METHOD == "size":
            samplePatch = create_patch_optimised(model, modelGraph, idArray,
                                                 invIdArray, sID, PATCH_SIZE)

        sampleFeatures = get_features(model, samplePatch, FEATURES,
                                      PCA_COMPONENTS, sID)
        sampleLabel = mapScalars.GetValue(sID)
        if PCA_COMPONENTS != None:
            sampleFeatures = sampleFeatures.flatten()
        features.append(sampleFeatures)
        labels.append(sampleLabel)

        if j in progressPoints:
            print(os.path.join(mapLocation, mapFilename))
            print("Got feature {}, labelled {} for this".format(
                sampleFeatures, sampleLabel))
            if PCA_COMPONENTS != None:
                print(sampleFeatures.shape)
示例#2
0
scalars.SetNumberOfValues(model.GetNumberOfPoints())

# For example, set all scalars to 1
for i in range(model.GetNumberOfPoints()):
    scalars.SetValue(i, 1)

# Make some patches at the landmarks, of a certain size
for landmarkSize in range(21):
    # landmarkSize = 16
    landmarkPatches = []
    st = time.time()

    # Iterative way
    for i in landmarkIds:
        landmarkPatches.append(
            create_patch_optimised(model, modelGraph, idArray, invIdArray, i,
                                   landmarkSize))

    # Parallel way
    # Parallel(n_jobs=2)(delayed(create_patch)(model, modelGraph, idArray, invIdArray, i, landmarkSize) for i in landmarkIds)

    t = time.time() - st

    print("Generated {} landmark patches of size {} in {} seconds.".format(
        len(landmarkIds), landmarkSize, t))
    print("Average patch generation time: {} seconds.".format(
        t / len(landmarkIds)))
    print(model.GetNumberOfPoints())

    # Paint the patches
    for patch in landmarkPatches:
        for point in patch:
示例#3
0
subBones = ["Patella", "Tibia", "Femur", ""]
subBone = subBones[1]

# Check to see if it exists
subBoneFilename = meshFilename.split(
    ".")[0] + subBone + "." + meshFilename.split(".")[1]
open(subBoneFilename, 'r')

# Load the mesh model and generate graph
model = read_mesh(subBoneFilename)
modelGraph, idArray, invIdArray = generate_graph(model)

for size in [
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
        20
]:
    i = 1000
    st = time.time()
    patch = create_patch_optimised(model, modelGraph, idArray, invIdArray, i,
                                   size)
    t = time.time() - st
    print(
        "Took {} seconds to create dijkstra patch of size {}, with {} vertices"
        .format(t, size, len(patch)))

# Iterative way
# for i in landmarkIds:
# 	landmarkPatches.append(create_patch(model, modelGraph, idArray, invIdArray, i, landmarkSize))

# Parallel way
# Parallel(n_jobs=2)(delayed(create_patch)(model, modelGraph, idArray, invIdArray, i, landmarkSize) for i in landmarkIds)