def thinning(skeleton, ogml):
        assert skeleton.flags["C_CONTIGUOUS"]
        itime = time.time()

        xi, n, m = Cffi.to_double_pointer_copy(skeleton)
        yi = ffi.cast('int*', skeleton.ctypes.data)

        lib.thinning(xi, yi, n, m, ogml['min_x'], ogml['max_x'], ogml['min_y'],
                     ogml['max_y'])
        Print.art_print("Thinning time: " + str(time.time() - itime),
                        Print.BLUE)
        return skeleton
Example #2
0
    def thinning(skeleton, ogml):
        x = [np.array(v, dtype='int32') for v in skeleton]
        xi = ffi.new(("int* [%d]") % (len(x)))
        for i in range(len(x)):
            xi[i] = ffi.cast("int *", x[i].ctypes.data)

        y = [np.array(v, dtype='int32') for v in skeleton]
        yi = ffi.new(("int* [%d]") % (len(y)))
        for i in range(len(y)):
            yi[i] = ffi.cast("int *", y[i].ctypes.data)

        itime = time.time()
        br_c = lib.thinning(xi, yi, len(x), len(x[0]), ogml['min_x'],
                            ogml['max_x'], ogml['min_y'], ogml['max_y'])
        Print.art_print(
            "Pure skeletonization time: " + str(time.time() - itime),
            Print.BLUE)
        # TODO: Must be faster!
        itime = time.time()
        for i in range(skeleton.shape[0]):
            for j in range(skeleton.shape[1]):
                skeleton[i][j] = yi[i][j]
        Print.art_print(
            "Skeletonization final copy: " + str(time.time() - itime),
            Print.BLUE)
        return skeleton
    def thinning(skeleton, ogml):

        x = [np.array(v, dtype='int32') for v in skeleton]
        xi = ffi.new(("int* [%d]") % (len(x)))
        for i in range(len(x)):
            xi[i] = ffi.cast("int *", x[i].ctypes.data)

        y = [np.array(v, dtype='int32') for v in skeleton]
        yi = ffi.new(("int* [%d]") % (len(y)))
        for i in range(len(y)):
            yi[i] = ffi.cast("int *", y[i].ctypes.data)

        lib.thinning(xi, yi, len(x), len(x[0]), ogml['min_x'], ogml['max_x'], ogml['min_y'], ogml['max_y'])
        skeleton = cp_thinning(skeleton, yi, skeleton.shape[0], skeleton.shape[1])

        return skeleton