Esempio n. 1
0
def processFrameUV(i, node, outputBase, ofs_U, ofs_V, ar, cw, imgfmt):
    uvframe = hdf5lflib.compute_uvframe(node, ar, cw, ofs_U, ofs_V)

    global gridsize_last
    gridsize_last = uvframe.shape

    if imgfmt == 'png':
        scipy.misc.imsave(outputBase + '-' + str(i) + '.png', uvframe)
    else:
        f = open(outputBase + '-' + str(i) + '.raw', 'wb')
        uvframe.tofile(f)
        f.close()
Esempio n. 2
0
def processFrame(i, node, ar, cw):
    uvframe = hdf5lflib.compute_uvframe(node, ar, cw)

    if PROGRESS_FIGURES:
        plt.figure()
        imgplot = plt.imshow(uvframe, cmap=plt.cm.gray)
        plt.show()

    # Smooth twice
    uvframe = cv2.medianBlur(uvframe, 5)
    uvframe = cv2.medianBlur(uvframe, 5)

    if PROGRESS_FIGURES:
        plt.figure()
        imgplot = plt.imshow(uvframe, cmap=plt.cm.gray)
        plt.show()

    # Threshold
    background_color = uvframe.mean()
    foreground_i = uvframe > background_color
    uvframe[foreground_i] = 255.
    uvframe[numpy.invert(foreground_i)] = 0.

    # Fill holes in "dead" regions of the worm
    uvframe = scipy.ndimage.morphology.binary_fill_holes(uvframe)

    if PROGRESS_FIGURES:
        plt.figure()
        imgplot = plt.imshow(uvframe, cmap=plt.cm.gray)
        plt.show()

    # Annotate with information regarding the nearest edge
    (edgedists, edgedirs) = computeEdgeDistances(uvframe)

    if PROGRESS_FIGURES:
        fig, axes = plt.subplots(ncols = 2)
        axes[0].imshow(uvframe, cmap=plt.cm.gray)
        axes[1].imshow(edgedists)
        plt.show()

    # Determine the backbone
    backbone = poseExtract(uvframe, edgedists, edgedirs)

    # Convert to TSV and output
    printTSV(backbone, edgedists)
Esempio n. 3
0
if __name__ == '__main__':
    filename = sys.argv[1]
    frameNo = int(sys.argv[2])
    bbfilename = sys.argv[3]
    outputfile = None
    if len(sys.argv) >= 5:
        outputfile = sys.argv[4]

    h5file = tables.open_file(filename, mode = "r")
    node = h5file.get_node('/', '/images/' + str(frameNo))
    ar = h5file.get_node('/', '/autorectification')
    try:
        cw = h5file.get_node('/', '/cropwindow')
    except tables.NoSuchNodeError:
        cw = None
    uvframe = hdf5lflib.compute_uvframe(node, ar, cw)

    (points, edgedists) = poselib.bbLoad(bbfilename)
    (spline, bblength) = poselib.bbToSpline(points)
    bbpoints = poselib.bbTraceSpline(spline, bblength, uvframe)

    # Draw the backbone
    #plt.figure()
    #plt.plot(bbpoints[:,0,1], bbpoints[:,0,0], 'o') # (x, y) order
    #plt.axis([0,100,100,0])
    #plt.show()

    restackframe = restackBySpline(bbpoints, uvframe, points, edgedists)

    if outputfile:
        scipy.misc.imsave(outputfile, restackframe)