def test_graph():

    plant_number = 1
    voxels_size = 16
    voxel_grid = phm_data.voxel_grid(plant_number=plant_number,
                                     voxels_size=voxels_size)
    graph = phm_seg.graph_from_voxel_grid(voxel_grid)
Пример #2
0
def test_graph_1():

    voxels_position = [(0, 0, 0),
                       (0, 0, 1),
                       (0, 1, 0),
                       (1, 1, 1),
                       (1, 1, 2),
                       (2, 1, 2),
                       (1, 2, 1),
                       (2, 2, 2),
                       (5, 5, 5)]

    voxels_size = 1
    voxel_grid = phm_obj.VoxelGrid(voxels_position, voxels_size)
    graph = phm_seg.graph_from_voxel_grid(voxel_grid)

    print("Number of nodes : {nb_nodes}".format(nb_nodes=len(graph.nodes())))

    assert len(voxels_position) == len(graph.nodes())

    for position in voxels_position:
        assert graph.has_node(position)

    l = networkx.dijkstra_path_length(graph,
                                      source=(0, 0, 0),
                                      target=(2, 2, 2),
                                      weight="weight")

    ll = numpy.linalg.norm(numpy.array((0, 0, 0)) - numpy.array((2, 2, 2)))

    assert l == ll
Пример #3
0
def test_maize():

    plant_number = 3
    voxels_size = 4
    voxel_grid = phm_data.voxel_grid(plant_number=plant_number,
                                     voxels_size=voxels_size)

    graph = phm_seg.graph_from_voxel_grid(voxel_grid)
    voxel_skeleton = phm_seg.skeletonize(voxel_grid, graph)
    vms = phm_seg.maize_segmentation(voxel_skeleton, graph)
    vmsi = phm_seg.maize_analysis(vms)
Пример #4
0
def test_maize():

    voxel_grid = phm_data.random_voxel_grid(voxels_size=32)

    graph = phm_seg.graph_from_voxel_grid(voxel_grid)
    voxel_skeleton = phm_seg.skeletonize(voxel_grid, graph)
    vms = phm_seg.maize_segmentation(voxel_skeleton, graph)
    vmsi = phm_seg.maize_analysis(vms)

    # Write
    filename = 'tmp.json'
    vms.write_to_json_gz(filename)
    vms = phm_obj.VoxelSegmentation.read_from_json_gz(filename)
    os.remove(filename)
Пример #5
0
def test_time_graph():

    voxel_grid = phm_data.random_voxel_grid(voxels_size=16)

    number_of_loop = 2
    best_time = float('inf')
    for i in range(number_of_loop):
        t0 = time.time()
        graph = phm_seg.graph_from_voxel_grid(voxel_grid)
        best_time = min(best_time, float(time.time() - t0))

    print("{number_of_loop} loop, best of {number_of_loop}: "
          "{best_time}s per loop".format(best_time=best_time,
                                         number_of_loop=number_of_loop))
Пример #6
0
def test_running():
    plant_number = 1
    voxels_size = 16
    bin_images = phm_data.bin_images(plant_number=plant_number)
    calibrations = phm_data.calibrations(plant_number=plant_number)
    voxel_grid = phm_data.voxel_grid(plant_number=plant_number,
                                     voxels_size=voxels_size)

    graph = phm_seg.graph_from_voxel_grid(voxel_grid)
    voxel_skeleton = phm_seg.skeletonize(voxel_grid, graph)

    image_projection = list()
    for angle in [0, 120, 270]:
        projection = calibrations["side"].get_projection(angle)
        image_projection.append((bin_images["side"][angle], projection))

    voxel_skeleton_reduced = phm_seg.segment_reduction(voxel_skeleton,
                                                       image_projection,
                                                       required_visible=1,
                                                       nb_min_pixel=100)
Пример #7
0
def test_running():

    bin_images = phm_data.bin_images(plant_1_dir)
    calibrations = phm_data.calibrations(plant_1_dir)
    voxel_grid = phm_data.voxel_grid(data_dir, 1, 32)

    # Load images binarize

    graph = phm_seg.graph_from_voxel_grid(voxel_grid)

    voxel_skeleton = phm_seg.skeletonize(voxel_grid, graph)

    image_projection = list()
    for angle in [0, 120, 270]:
        projection = calibrations["side"].get_projection(angle)
        image_projection.append((bin_images["side"][angle], projection))

    voxel_skeleton = phm_seg.segment_reduction(
        voxel_skeleton, image_projection,
        required_visible=1,
        nb_min_pixel=100)
Пример #8
0
def test_time_graph():

    plant_number = 1
    voxels_size = 16
    voxel_grid = phm_data.voxel_grid(plant_number=plant_number,
                                     voxels_size=voxels_size)
    # print(voxel_grid.voxels_position)
    voxels_size = int(voxel_grid.voxels_size)
    voxels_position = map(tuple, list(voxel_grid.voxels_position))
    voxel_grid = phm_obj.VoxelGrid(voxels_position, voxels_size)

    number_of_loop = 2
    best_time = float('inf')
    for i in range(number_of_loop):
        t0 = time.time()
        graph = phm_seg.graph_from_voxel_grid(voxel_grid)
        best_time = min(best_time, float(time.time() - t0))

    print("{number_of_loop} loop, best of {number_of_loop}: "
          "{best_time}s per loop".format(best_time=best_time,
                                         number_of_loop=number_of_loop))
Пример #9
0
def test_graph():

    voxel_grid = phm_data.random_voxel_grid(voxels_size=16)

    graph = phm_seg.graph_from_voxel_grid(voxel_grid)
def segmentation(row):

    bin_images = dc.get_bin_images(row)
    calibrations = dc.get_calibrations(row)

    refs_angle_list = [_routine_select_ref_angle(bin_images["side"])]

    image_views = list()
    for id_camera in bin_images:
        for angle in bin_images[id_camera]:
            projection = calibrations[id_camera].get_projection(angle)

            image_ref = None
            if id_camera == "side" and angle in refs_angle_list:
                image_ref = bin_images[id_camera][angle]

            inclusive = False
            if id_camera == "top":
                inclusive = True

            image_views.append(
                phm_obj.ImageView(bin_images[id_camera][angle],
                                  projection,
                                  inclusive=inclusive,
                                  image_ref=image_ref))

    # ### 2.2 Do multi-view reconstruction
    voxels_size = 16  # mm
    error_tolerance = 0
    voxel_grid = phm_mvr.reconstruction_3d(image_views,
                                           voxels_size=voxels_size,
                                           error_tolerance=error_tolerance)

    #phm_display_notebook.show_voxel_grid(voxel_grid, size=1)

    # ## 4. Skeletonization
    #
    # ### 4.1 Compute Graph and the skeleton
    # Compute the skeleton of the plant voxelgrid

    # In[12]:

    graph = phm_seg.graph_from_voxel_grid(voxel_grid, connect_all_point=True)
    voxel_skeleton = phm_seg.skeletonize(voxel_grid, graph)

    # ### 2.3 Clean skeleton (filter small elements)

    # In[14]:

    # Select images
    image_projection = list()
    for angle in bin_images["side"]:
        projection = calibrations["side"].get_projection(angle)
        image_projection.append((bin_images["side"][angle], projection))

    voxel_skeleton_denoised = phm_seg.segment_reduction(voxel_skeleton,
                                                        image_projection,
                                                        required_visible=5,
                                                        nb_min_pixel=400)

    #phm_display_notebook.show_skeleton(voxel_skeleton_denoised, size=1)

    # ## 5. Maize Segmentation
    #
    # ### 5.1 Process
    #
    # Voxel skeleton are segmented in several label "stem", "mature_leaf", "growing_leaf" and "unknow"

    # In[16]:

    vms = phm_seg.maize_segmentation(voxel_skeleton_denoised, graph)
    vmsi = phm_seg.maize_analysis(vms)
    return vmsi
Пример #11
0
#!/usr/bin/env python

import sys
import openalea.phenomenal.display as phm_display
import openalea.phenomenal.mesh as phm_mesh
import openalea.phenomenal.object as phm_obj
import openalea.phenomenal.segmentation as phm_seg

from funcs import *

voxel_grid = phm_obj.VoxelGrid.read(sys.argv[1])

graph = phm_seg.graph_from_voxel_grid(voxel_grid, connect_all_point=True)
voxel_skeleton = phm_seg.skeletonize(voxel_grid, graph)

Пример #12
0
import openalea.phenomenal.segmentation as phm_seg
# import openalea.phenomenal.display as phm_display
# ==============================================================================

plant_number = 2
voxels_size = 8
bin_images = phm_data.bin_images(plant_number=plant_number)
calibrations = phm_data.calibrations(plant_number=plant_number)
voxel_grid = phm_data.voxel_grid(plant_number=plant_number,
                                 voxels_size=voxels_size)

init_start = time.time()
# ==============================================================================

start = time.time()
graph = phm_seg.graph_from_voxel_grid(voxel_grid)
print("time processing , graph_from_voxel_grid : {}".format(time.time() -
                                                            start))

start = time.time()
voxel_skeleton = phm_seg.skeletonize(voxel_grid, graph)
print("time processing , skeletonize : {}".format(time.time() - start))

start = time.time()
image_projection = list()
for angle in range(0, 360, 30):
    projection = calibrations["side"].get_projection(angle)
    image_projection.append((bin_images["side"][angle], projection))
print("time processing , image_projection : {}".format(time.time() - start))

print("len(voxel_skeleton_reduced.segments) : {}".format(