Esempio n. 1
0
def skeleton_downsize(img, factor=12):
    """Downsize while minizing information lost via skeleton downsize"""
    # perform skeleton
    h, w = img.shape
    skel = skeleton.skeleton(img)

    #downsize
    y_axis = ((np.where(skel == 255))[0] / factor)
    x_axis = ((np.where(skel == 255))[1] / factor)
    ret_h = h / factor
    ret_w = w / factor
    ret = np.zeros((int(ret_h), int(ret_w)))

    # upsample
    for i in range(len(y_axis)):
        ret[int(y_axis[i]), int(x_axis[i])] = 255
    return ret
Esempio n. 2
0
    def __init__(self, black_box=None, decompose='skeleton', eps=1e-9):
        from skeleton import skeleton
        accepted_types = ['svd', 'skeleton']
        if decompose not in accepted_types:
            raise Exception(
                'decompose must be one of the following: {types}'.format(
                    types=accepted_types))

        if black_box == None:
            # Empty constructor
            self.dtype = np.float
            self.n = ()
            self.shape = ()
            self.cores = []
            self.d = 0
            self.r = np.array([])
        elif isinstance(black_box, TensorTrain):
            # Copy constructor
            self.dtype = black_box.dtype
            self.n = black_box.n
            self.shape = ()
            self.d = black_box.d
            self.r = black_box.r
            self.cores = [core.copy() for core in black_box.cores]
        elif isinstance(black_box, BlackBox):
            # Constructor from some "Black Box" tensor from which we can
            # retrieve arbitrary elements
            self.dtype = black_box.dtype
            self.n = black_box.n
            self.shape = black_box.shape
            self.d = black_box.d
            if decompose == 'skeleton':
                self.__init__(skeleton(black_box, cores_only=False, eps=eps),
                              eps=eps)
                #self.cores = skeleton(black_box, cores_only=True, eps=eps)
                #self.r = np.array([1] + [core.shape[2] for core in self.cores])
            elif decompose == 'svd':
                self.tt_svd(black_box, eps=eps)
Esempio n. 3
0
def main():
    scale = [1, 1, 1]
    try:
        os.mkdir(os.path.join(
            os.path.dirname(__file__),
            'Output'))  #Creates an output folder if there isn't one yet
    except:
        pass
    try:
        FILE_NAME = u.FILE_NAME  #Checks to see if a file name has been set
    except:
        FILE_NAME = ""
    try:
        PRIMITIVE_TYPE = u.PRIMITIVE_TYPE  #Checks to see if a primitive type has been set
    except:
        PRIMITIVE_TYPE = ""
    if FILE_NAME != "":
        #This section retrieves the input file and voxelizes the input STL
        shortName = FILE_NAME[:-4]
        filepath = os.path.join(os.path.dirname(__file__), 'Input', FILE_NAME)
        res = u.RESOLUTION - u.BUFFER * 2
        origShape, objectBox = voxelize(filepath, res, u.BUFFER)
        gridResX, gridResY, gridResZ = origShape.shape
        scale[0] = objectBox[0] / (gridResX - u.BUFFER * 2)
        scale[1] = max(objectBox[1:]) / (gridResY - u.BUFFER * 2)
        scale[2] = scale[1]
    elif PRIMITIVE_TYPE != "":
        #This section generates the desired primitive
        shortName = PRIMITIVE_TYPE
        if PRIMITIVE_TYPE == "Heart":
            x0 = np.linspace(-1.5, 1.5, u.RESOLUTION)
            y0, z0 = x0, x0
            origShape = f.heart(x0, y0, z0, 0, 0, 0)
        elif PRIMITIVE_TYPE == "Egg":
            x0 = np.linspace(-5, 5, u.RESOLUTION)
            y0, z0 = x0, x0
            origShape = f.egg(x0, y0, z0, 0, 0, 0)
            #eggknowledgement to Molly Carton for this feature.
        else:
            x0 = np.linspace(-50, 50, u.RESOLUTION)
            y0, z0 = x0, x0
            if PRIMITIVE_TYPE == "Cube":
                origShape = f.rect(x0, y0, z0, 80, 80, 80)
            elif PRIMITIVE_TYPE == "Silo":
                origShape = f.union(f.sphere(x0, y0, z0, 40),
                                    f.cylinderY(x0, y0, z0, -40, 0, 40))
            elif PRIMITIVE_TYPE == "Cylinder":
                origShape = f.cylinderX(x0, y0, z0, -40, 40, 40)
            elif PRIMITIVE_TYPE == "Sphere":
                origShape = f.sphere(x0, y0, z0, 40)
            else:
                print("Given primitive type has not yet been implemented.")
    else:
        print("Provide either a file name or a desired primitive.")
        return

    #This section cleans up the input object
    rawObject = SDF3D(f.condense(origShape, 2 * u.BUFFER))
    i, j, k = rawObject.shape
    origShape = f.smooth(rawObject, iteration=1)
    print("Object Smoothed")
    if u.OBJ_MESH:
        generateMesh(origShape, scale, modelName=shortName + "Object")
    if u.PLOTTING: multiPlot(origShape, shortName + ' Object', u.SAVE_PLOTS)

    #This section finds the skeleton of the input object
    oSkele = skeleton(origShape, u.GTHRESH, u.STHRESH)
    oSkele = u.skeletonMods(oSkele)
    print("Skeleton Computed")
    if u.PLOTTING: multiPlot(oSkele, shortName + ' Skeleton', u.SAVE_PLOTS)
    if u.SKELE_MESH:
        generateMesh(oSkele, scale, modelName=shortName + "Skeleton")

    #If needed, this section refleshes the skeleton
    if u.COMPOUND_MODIFICATIONS or u.REFLESH_MESH:
        refleshed = f.smooth(reflesh(oSkele, iteration=u.RESOLUTION // 8))
        print("Skeleton Refleshed")
        if u.REFLESH_MESH:
            generateMesh(refleshed, scale, modelName=shortName + "Refleshed")
        if u.COMPOUND_MODIFICATIONS: rawObject = refleshed

    #If needed, this section finds the complemental skeleton
    if u.COMPLEMENTAL_SKELETON:
        flesh = SDF3D(f.subtract(oSkele, rawObject))
        flesh = f.smooth(flesh, iteration=1)
        cSkele = skeleton(flesh, u.GTHRESH, u.STHRESH)
        cSkele = u.complementalSkeletonMods(cSkele)
        print("Complemental Skeleton Computed")
        if u.PLOTTING:
            multiPlot(cSkele, shortName + ' Complemental Skeleton',
                      u.SAVE_PLOTS)
        if u.COMP_SKELE_MESH:
            generateMesh(cSkele,
                         scale,
                         modelName=shortName + "Complemental Skeleton")

        #If needed, this section refleshes the complemental skeleton
        if u.COMP_REFLESH_MESH:
            cRefleshed = reflesh(cSkele, iteration=u.RESOLUTION // 8)
            recreatedObject = f.smooth(
                f.union(f.thicken(SDF3D(oSkele), 2.0), cRefleshed))
            print("Complemental Skeleton Refleshed")
            if u.PLOTTING:
                multiPlot(recreatedObject, shortName + ' Remade', u.SAVE_PLOTS)
            generateMesh(recreatedObject,
                         scale,
                         modelName=shortName + "Remade")
Esempio n. 4
0

#specify folder
usr_input = sys.argv[-1]

#load global parameters
par = yaml.full_load(open(usr_input, "rb"))

cameras = [2, 5]
#cameras = par['cam_id']

#root_dir = '/data/LiftPose3D/fly_tether/cam_angles/cam'
root_dir = '/data/LiftPose3D/fly_tether/cam_angles/grooming_test/cam'

#import
G, color_edge = skeleton()  #skeleton
legtips = [4, 9, 14, 19, 24, 29]

print('making video using cameras' + str(cameras))

#load data / statistics for cameras
out, tar = [], []
for cam in cameras:
    data_dir = root_dir + str(cam)

    #load stats
    tar_mean = torch.load(data_dir + '/stat_3d.pth.tar')['mean']
    tar_std = torch.load(data_dir + '/stat_3d.pth.tar')['std']
    targets_3d = torch.load(data_dir + '/stat_3d.pth.tar')['targets_3d']
    cam_par = torch.load(data_dir + '/stat_3d.pth.tar')['rcams']
    cam_par = list(cam_par.values())
Esempio n. 5
0
 def setUp(self):
     super(TestSkeleton, self).setUp()
     self.skeleton_obj = skeleton.skeleton(self.bot)
Esempio n. 6
0
# required libraries
import socket
import time
import sys
import Queue
import pdb
from skeleton import skeleton
from dialogue import dialogue
from parser import parser

bot = skeleton()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((bot.server, bot.port))

rQueue = Queue.Queue()
sQueue = Queue.Queue()

sQueue.put(bot.senduser())
sQueue.put(bot.sendnick())
#sQueue.put(bot.joinchan("#orpheus", "transmigrationofsouls"))

readbuffer = ""
while True:
    readbuffer = sock.recv(2048)
    temp = str.split(str.strip(readbuffer), "\r\n")
    rQueue.put(temp.pop())
    while (not rQueue.empty()):
        rx = rQueue.get()
        print rx
        rxParsed = parser(rx)
        if (rxParsed.cmdWord == "PING"):