Exemple #1
0
def vis(*dense_data):
    from mayavi import mlab
    from util3d.mayavi_vis import vis_voxels
    for d in dense_data:
        mlab.figure()
        vis_voxels(d, color=(0, 0, 1), axis_order='xyz')
    mlab.show()
Exemple #2
0
def vis_voxels(model_id, edge_length_threshold, filled, shuffle=False):
    from mayavi import mlab
    from util3d.mayavi_vis import vis_voxels
    from shapenet.core import cat_desc_to_id
    from template_ffd.inference.voxels import get_voxel_dataset
    from template_ffd.data.voxels import get_gt_voxel_dataset
    from template_ffd.model import load_params
    from template_ffd.data.ids import get_example_ids
    cat_id = cat_desc_to_id(load_params(model_id)['cat_desc'])
    gt_ds = get_gt_voxel_dataset(cat_id, filled)
    inf_ds = get_voxel_dataset(model_id, edge_length_threshold)
    example_ids = get_example_ids(cat_id, 'eval')
    if shuffle:
        example_ids = list(example_ids)
        example_ids.shuffle

    with gt_ds:
        with inf_ds:
            for example_id in example_ids:
                gt = gt_ds[example_id].data
                inf = inf_ds[example_id].data
                vis_voxels(gt, color=(0, 0, 1))
                mlab.figure()
                vis_voxels(inf, color=(0, 1, 0))
                mlab.show()
Exemple #3
0
def vis_voxels(model_id, edge_length_threshold, filled, shuffle=False):
    from mayavi import mlab
    from util3d.mayavi_vis import vis_voxels
    from shapenet.core import cat_desc_to_id
    from template_ffd.inference.voxels import get_voxel_dataset
    from template_ffd.data.voxels import get_gt_voxel_dataset
    from template_ffd.model import load_params
    from template_ffd.data.ids import get_example_ids
    cat_id = cat_desc_to_id(load_params(model_id)['cat_desc'])
    gt_ds = get_gt_voxel_dataset(cat_id, filled)
    inf_ds = get_voxel_dataset(model_id, edge_length_threshold)
    example_ids = get_example_ids(cat_id, 'eval')
    if shuffle:
        example_ids = list(example_ids)
        example_ids.shuffle

    with gt_ds:
        with inf_ds:
            for example_id in example_ids:
                gt = gt_ds[example_id].data
                inf = inf_ds[example_id].data
                vis_voxels(gt, color=(0, 0, 1))
                mlab.figure()
                vis_voxels(inf, color=(0, 1, 0))
                mlab.show()
Exemple #4
0
def vis(vox, image, meta):
    from mayavi import mlab
    from util3d.mayavi_vis import vis_voxels
    print(meta)
    image.resize((137 * 4, ) * 2).show()
    mlab.figure()
    vis_voxels(vox, color=(0, 0, 1), scale_factor=0.5, axis_order='xyz')
    mlab.show()
Exemple #5
0
    def vis_voxels():
        from mayavi import mlab
        from util3d.mayavi_vis import vis_voxels
        path = get_voxel_path('eval', 9)
        voxels = load_mat_data(path)

        vis_voxels(voxels, color=(0, 0, 1))
        mlab.show()
Exemple #6
0
def vis(base, frust, image):
    from util3d.mayavi_vis import vis_voxels
    from mayavi import mlab
    from PIL import Image
    frust_data = frust.dense_data()
    frust_flat = np.max(frust_data, axis=-1)
    Image.fromarray(frust_flat.T.astype(np.uint8) * 255).resize(
        (224, 224)).show()

    image.show()
    mlab.figure()
    vis_voxels(base.dense_data(), color=(0, 0, 1))
    mlab.figure()
    vis_voxels(frust_data, color=(0, 1, 0))
    mlab.show()
Exemple #7
0
def vis(image_fp, rle_data, out_dim):
    import numpy as np
    from PIL import Image
    from util3d.voxel.binvox import RleVoxels
    from util3d.mayavi_vis import vis_voxels
    from mayavi import mlab
    im = Image.open(image_fp)
    im.show()
    dense_data = RleVoxels(np.array(rle_data), (out_dim, ) * 3).dense_data()
    sil = np.any(dense_data, axis=-1).T.astype(np.uint8) * 255
    sil = Image.fromarray(sil).resize(im.size)
    sil.show()
    comb = np.array(im) // 2 + np.array(sil)[:, :, np.newaxis] // 2
    Image.fromarray(comb).show()
    vis_voxels(dense_data, color=(0, 0, 1))
    mlab.show()
def vis(cat_desc, regime='e', shuffle=True):
    import matplotlib.pyplot as plt
    from mayavi import mlab
    from util3d.mayavi_vis import vis_point_cloud, vis_voxels

    all_ds = get_ds(cat_desc, regime)
    cat_id = cat_desc_to_id(cat_desc)
    example_ids = list(get_example_ids(cat_id, 'eval'))
    random.shuffle(example_ids)

    def vis_mesh(mesh, include_wireframe=False, **kwargs):
        from util3d.mayavi_vis import vis_mesh as vm
        v, f = (np.array(mesh[k]) for k in ('vertices', 'faces'))
        vm(v, f, include_wireframe=include_wireframe, **kwargs)

    with all_ds:
        for example_id in example_ids:
            print(example_id)
            image, gt_mesh, cloud, mesh, voxels, template_mesh = \
                all_ds[example_id]
            plt.imshow(image)
            mlab.figure()
            vis_mesh(gt_mesh, color=(0, 0, 1))
            mlab.figure()
            vis_mesh(mesh, color=(0, 1, 0))
            mlab.figure()
            vis_mesh(template_mesh, color=(1, 0, 0))
            mlab.figure()
            vis_point_cloud(np.array(cloud),
                            scale_factor=0.01,
                            color=(0, 1, 0))
            mlab.figure()
            vis_voxels(voxels.data, color=(0, 1, 0))

            plt.show(block=False)
            mlab.show()
            plt.close()
Exemple #9
0
def vis(cat_desc, regime='e', shuffle=True):
    import matplotlib.pyplot as plt
    from mayavi import mlab
    from util3d.mayavi_vis import vis_point_cloud, vis_voxels

    all_ds = get_ds(cat_desc, regime)
    cat_id = cat_desc_to_id(cat_desc)
    example_ids = list(get_example_ids(cat_id, 'eval'))
    random.shuffle(example_ids)

    def vis_mesh(mesh, include_wireframe=False, **kwargs):
        from util3d.mayavi_vis import vis_mesh as vm
        v, f = (np.array(mesh[k]) for k in ('vertices', 'faces'))
        vm(v, f, include_wireframe=include_wireframe, **kwargs)

    with all_ds:
        for example_id in example_ids:
            print(example_id)
            image, gt_mesh, cloud, mesh, voxels, template_mesh = \
                all_ds[example_id]
            plt.imshow(image)
            mlab.figure()
            vis_mesh(gt_mesh, color=(0, 0, 1))
            mlab.figure()
            vis_mesh(mesh, color=(0, 1, 0))
            mlab.figure()
            vis_mesh(template_mesh, color=(1, 0, 0))
            mlab.figure()
            vis_point_cloud(
                np.array(cloud), scale_factor=0.01, color=(0, 1, 0))
            mlab.figure()
            vis_voxels(voxels.data, color=(0, 1, 0))

            plt.show(block=False)
            mlab.show()
            plt.close()
Exemple #10
0
 def test_mpl_vis():
     print(voxels.shape)
     v = fast_resize(voxels, 32)
     print(v.shape)
     vis_voxels(v, color=(0, 0, 1), axis_order='xyz')
     mlab.show()
Exemple #11
0
 def test_fast_resize():
     # zoomed = resize(voxels, 64)
     vis_voxels(fast_resize(voxels, 32), color=(0, 0, 1), axis_order='xyz')
     mlab.show()
Exemple #12
0
import os
from mayavi import mlab
from util3d.mayavi_vis import vis_voxels
from util3d.mesh.off import OffObject
from util3d.mesh.geom import triangulated_faces
from util3d.voxel.convert import mesh_to_voxels
from util3d.voxel.binvox import Voxels

folder = os.path.realpath(os.path.dirname(__file__))
vox_path = os.path.join(folder, 'data', 'bunny.binvox')

if not os.path.isfile(vox_path):
    bunny_path = os.path.join(folder, 'data', 'bunny.off')
    bunny = OffObject.from_path(bunny_path)

    vertices = bunny.vertices
    faces = tuple(triangulated_faces(bunny.faces))
    voxels = mesh_to_voxels(vertices, faces, 64)

    with open(os.path.join(folder, 'data', 'bunny.binvox'), 'w') as fp:
        voxels.save_to_file(fp)
    del voxels

with open(vox_path, 'r') as fp:
    voxels = Voxels.from_file(fp)

vis_voxels(voxels.dense_data())
mlab.show()
Exemple #13
0
    inf_ds = get_voxel_dataset(model_id, edge_length_threshold)
    example_ids = get_example_ids(cat_id, 'eval')
    if shuffle:
        example_ids = list(example_ids)
        example_ids.shuffle

    with gt_ds:
        with inf_ds:
            for example_id in example_ids:
                gt = gt_ds[example_id].data
                inf = inf_ds[example_id].data
                vis_voxels(gt, color=(0, 0, 1))
                mlab.figure()
                vis_voxels(inf, color=(0, 1, 0))
                mlab.show()


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('model_id', help='id of model defined in params')
    parser.add_argument('-t',
                        '--edge_length_threshold',
                        type=float,
                        default=0.1)
    parser.add_argument('-s', '--shuffle', action='store_true')
    parser.add_argument('-f', '--filled', action='store_true')
    args = parser.parse_args()
    vis_voxels(args.model_id, args.edge_length_threshold, args.filled,
               args.shuffle)
Exemple #14
0
def vis(voxels):
    from mayavi import mlab
    from util3d.mayavi_vis import vis_voxels
    vis_voxels(voxels)
    mlab.show()
Exemple #15
0
from mayavi import mlab
from shapenet.core.voxels.config import VoxelConfig
from shapenet.core import cat_desc_to_id, get_example_ids
from util3d.mayavi_vis import vis_voxels

cat_desc = 'plane'
cat_id = cat_desc_to_id(cat_desc)
example_ids = get_example_ids(cat_id)

config = VoxelConfig()
with config.get_dataset(cat_id) as dataset:
    for example_id in example_ids:
        voxels = dataset[example_id]
        vis_voxels(voxels.dense_data(), color=(0, 0, 1))
        mlab.show()
Exemple #16
0
    gt_ds = get_gt_voxel_dataset(cat_id, filled)
    inf_ds = get_voxel_dataset(model_id, edge_length_threshold)
    example_ids = get_example_ids(cat_id, 'eval')
    if shuffle:
        example_ids = list(example_ids)
        example_ids.shuffle

    with gt_ds:
        with inf_ds:
            for example_id in example_ids:
                gt = gt_ds[example_id].data
                inf = inf_ds[example_id].data
                vis_voxels(gt, color=(0, 0, 1))
                mlab.figure()
                vis_voxels(inf, color=(0, 1, 0))
                mlab.show()


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'model_id', help='id of model defined in params')
    parser.add_argument(
        '-t', '--edge_length_threshold', type=float, default=0.1)
    parser.add_argument('-s', '--shuffle', action='store_true')
    parser.add_argument('-f', '--filled', action='store_true')
    args = parser.parse_args()
    vis_voxels(
        args.model_id, args.edge_length_threshold, args.filled, args.shuffle)
Exemple #17
0
    return load_mat_data(get_voxel_path(mode, example_id))


if __name__ == '__main__':
    from path import get_image_path
    mode = 'eval'
    example_id = 9

    def vis_image():
        import matplotlib.pyplot as plt
        from scipy.misc import imread
        image_idx = 0
        image = imread(get_image_path(mode, example_id, image_idx))
        image = image[..., :3]
        plt.imshow(image)
        plt.figure()
        plt.imshow(image[..., -1])
        plt.show()

    def vis_voxels():
        from mayavi import mlab
        from util3d.mayavi_vis import vis_voxels
        path = get_voxel_path('eval', 9)
        voxels = load_mat_data(path)

        vis_voxels(voxels, color=(0, 0, 1))
        mlab.show()

    vis_image()
    vis_voxels()
Exemple #18
0
dim = 32

with get_zipped_voxel_dataset(dataset_id, mode, category, dim) as dataset:
    for example_id in dataset:
        voxels = dataset[example_id]
        dense = voxels.dense_data()
        sparse = voxels.sparse_data()
        contiguous = get_contiguous_regions_2d(voxels.rle_data(), dim)
        reconstructed = np.zeros((dim,)*3, dtype=np.bool)
        for n, c in enumerate(contiguous):
            i = n // dim
            j = n % dim
            for a, b in c:
                reconstructed[i, j, a:b] = True
        print(np.all(dense == reconstructed))
        mlab.figure()
        vis_voxels(dense, color=(0, 0, 1))
        mlab.figure()
        vis_voxels(reconstructed, color=(0, 1, 0))
        mlab.show()

        # print(len(sparse))
        # i = sparse[0][10]
        # j = sparse[1][10]
        # data = np.array(dense[i, j], dtype=np.float32)*2 - 0.5
        # lower, frac = get_interpolated_roots_1d(data)
        # print(data)
        # print(lower)
        # print(frac)
        # exit()
Exemple #19
0
folder = os.path.realpath(os.path.dirname(__file__))
dim = 128
vox_path = os.path.join(folder, 'data', 'bunny%d.binvox' % dim)

if not os.path.isfile(vox_path):
    bunny_path = os.path.join(folder, 'data', 'bunny.off')
    bunny = OffObject.from_path(bunny_path)

    vertices = bunny.vertices
    faces = tuple(triangulated_faces(bunny.faces))
    voxels = mesh_to_voxels(vertices, faces, dim)

    with open(vox_path, 'w') as fp:
        voxels.save_to_file(fp)
    del voxels

with open(vox_path, 'r') as fp:
    voxels = Voxels.from_file(fp)

dense = voxels.dense_data()
filled = np.array(orthographic_filled_voxels(dense))
filled_v0 = v0(dense)
print(np.sum(dense), np.sum(filled), np.all(filled_v0 == filled))
mlab.figure()
# vis_contours(dense, contours=[0.5], color=(0, 0, 1))
vis_voxels(dense, color=(0, 0, 1), axis_order='xyz')
mlab.figure()
vis_voxels(filled, color=(0, 1, 0), axis_order='xyz')
mlab.show()