Пример #1
0
size = 100.
n_points = 11
n_layers = 2
img = sphere_tissue_image(size=size, n_points=n_points, n_layers=n_layers)

world.add(img,"segmented_image",colormap='glasbey',alphamap='constant',bg_id=1,alpha=0.25)

draco = DracoMesh(image=img)
draco.delaunay_adjacency_complex(surface_cleaning_criteria=[])

world.add(draco.triangulation_topomesh,'adjacency_complex')
world['adjacency_complex']['display_3'] = False
world['adjacency_complex']['display_0'] = True
world['adjacency_complex_vertices']['display_colorbar'] = False
world['adjacency_complex_vertices']['polydata_colormap'] = load_colormaps()['glasbey']
world['adjacency_complex_vertices']['point_radius'] = 1.5

draco.adjacency_complex_optimization(n_iterations=3)

world['adjacency_complex']['coef_3'] = 0.9
world['adjacency_complex']['display_3'] = True
world['adjacency_complex_cells']['display_colorbar'] = False
world['adjacency_complex_cells']['polydata_colormap'] = load_colormaps()['grey']
world['adjacency_complex_cells']['intensity_range'] = (-1,0)
world['adjacency_complex_cells']['preserve_faces'] = True
world['adjacency_complex_cells']['x_slice'] = (0,90)

triangular = ['star','remeshed','projected','flat']
image_dual_topomesh = draco.dual_reconstruction(reconstruction_triangulation = triangular, adjacency_complex_degree=3, maximal_edge_length=5.1)
Пример #2
0
    pi_img = image_dict['PI']
    world.add(pi_img,
              'membrane_image' + suffix,
              colormap='Reds',
              voxelsize=microscope_orientation *
              np.array(image_dict[reference_name].voxelsize))
    world['membrane_image']['intensity_range'] = (5000, 30000)

    L1_cells = np.array(list(
        topomesh.wisps(0)))[topomesh.wisp_property('layer', 0).values() == 1]
    non_L1_cells = np.array(list(
        topomesh.wisps(0)))[topomesh.wisp_property('layer', 0).values() != 1]

    world.add(topomesh, "detected_nuclei" + suffix)
    world["detected_nuclei_vertices"]["polydata_colormap"] = load_colormaps(
    )['jet']
    world["detected_nuclei"]["property_name_0"] = "layer"
    world["detected_nuclei_vertices"]["intensity_range"] = (-0.5, 2.5)
    world["detected_nuclei_vertices"]["display_colorbar"] = False
    world['nuclei_image']['x_plane_position'] = 0
    world['nuclei_image']['y_plane_position'] = 0
    world['nuclei_image']['z_plane_position'] = 10
    world['nuclei_image']['cut_planes_alpha'] = 0.5

    user_input = ""
    while user_input != 'next':
        user_input = raw_input("Type 'next' to continue...")

    # Start of post-edition
    edited_L1_points = np.array(
        world["detected_nuclei_vertices"].data.points.values())
                         (3, [])])
        save_ply_property_topomesh(expert_topomesh,
                                   xp_topomesh_fname,
                                   properties_to_save=ppty2ply,
                                   color_faces=False)

# -- Edit 'expert_topomesh' (ground truth) for potential labels at the stack margins:
margin_cells = [
    k for k, v in expert_topomesh.wisp_property('marginal', 0).items() if v
]
non_margin_cells = list(set(expert_topomesh.wisps(0)) - set(margin_cells))
expert_topomesh = filter_topomesh_vertices(expert_topomesh, non_margin_cells)
# --- Update EXPERT topomesh display:
world.add(expert_topomesh, "expert_seeds")
world["expert_seeds"]["property_name_0"] = 'layer'
world["expert_seeds_vertices"]["polydata_colormap"] = load_colormaps(
)['Greens']

# -- Create a 'detected_topomesh' out of L1 cells only:
L1_detected_topomesh = filter_topomesh_vertices(detected_topomesh, "L1")
suffix = "_expert"
# world.add(L1_detected_topomesh,"L1_detected_seed"+suffix)
# world["L1_detected_seed"+ suffix]["property_name_0"] = 'layer'
# world["L1_detected_seed{}_vertices".format(suffix)]["polydata_colormap"] = load_colormaps()['Reds']

# -- Create a 'L1_expert_topomesh' (L1 ground truth) out of L1 cells only:
L1_expert_topomesh = filter_topomesh_vertices(expert_topomesh, "L1")
world.add(L1_expert_topomesh, "L1_expert_seeds")
world["L1_expert_seeds"]["property_name_0"] = 'layer'
world["L1_expert_seeds_vertices"]["polydata_colormap"] = load_colormaps(
)['Greens']
Пример #4
0
    def _draco_control_changed(self, control_name, old, new):
        print control_name, " changed! : ", new

        control_names = [c['name'] for c in self._controls]
        self._controls[control_names.index(control_name)]['value'] = new

        if control_name == 'img_filename':
            img_file = new
            try:
                img = imread(img_file)
                assert img.ndim == 3
            except:
                print "Image type not recognized! Please choose a different file..."
                set_default_control(self._controls, 'initialize')
            else:
                self.name = os.path.split(img_file)[-1].split('.')[0]
                set_default_control(self._controls,
                                    'initialize',
                                    value=self._init_button_pressed)

        elif control_name == 'display_img':
            if new:
                self.world.add(self.draco.segmented_image,
                               self.name + '_segmented_image',
                               colormap='glasbey',
                               alphamap='constant',
                               bg_id=1)
            else:
                if self.world.has_key(self.name + '_segmented_image'):
                    self.world.remove(self.name + '_segmented_image')

        elif control_name == 'display_cells':
            if new:
                self.world.add(self.draco.point_topomesh,
                               self.name + '_image_cells')
                self.world[self.name + '_image_cells_vertices'].set_attribute(
                    'point_radius', self.draco.segmented_image.max())
                self.world[self.name + '_image_cells_vertices'].set_attribute(
                    'display_colorbar', False)
            else:
                if self.world.has_key(self.name + '_image_cells'):
                    self.world.remove(self.name + '_image_cells')

        elif control_name == 'display_adjacency':
            control_names = [c['name'] for c in self._controls]
            adjacency_complex = self._controls[control_names.index(
                'adjacency_complex')]['value']
            if adjacency_complex in ['delaunay', 'L1-L2']:
                degree = 3
            else:
                degree = 2

            if new:
                self.world.add(self.draco.triangulation_topomesh,
                               self.name + '_adjacency_complex')
                if degree == 3:
                    self.world[self.name +
                               '_adjacency_complex_cells'].set_attribute(
                                   'polydata_colormap',
                                   load_colormaps()['grey'])
                    self.world[self.name +
                               '_adjacency_complex_cells'].set_attribute(
                                   'intensity_range', (-1, 0))
                    self.world[self.name + '_adjacency_complex'].set_attribute(
                        'coef_3', 0.95)
                    self.world[self.name +
                               '_adjacency_complex_cells'].set_attribute(
                                   'display_colorbar', False)
                else:
                    self.world[self.name + '_adjacency_complex'].set_attribute(
                        'display_3', False)
                    self.world[self.name + '_adjacency_complex'].set_attribute(
                        'display_2', True)
                    self.world[self.name +
                               '_adjacency_complex_faces'].set_attribute(
                                   'polydata_colormap',
                                   load_colormaps()['grey'])
                    self.world[self.name +
                               '_adjacency_complex_faces'].set_attribute(
                                   'intensity_range', (-1, 0))
                    self.world[self.name + '_adjacency_complex'].set_attribute(
                        'coef_2', 0.98)
                    self.world[self.name +
                               '_adjacency_complex_faces'].set_attribute(
                                   'display_colorbar', False)
            else:
                if self.world.has_key(self.name + '_adjacency_complex'):
                    self.world.remove(self.name + '_adjacency_complex')

        elif control_name == 'display_dual':
            if new:
                self.world.add(self.draco.dual_reconstruction_topomesh,
                               self.name + '_dual_reconstruction')
            else:
                if self.world.has_key(self.name + '_dual_reconstruction'):
                    self.world.remove(self.name + '_dual_reconstruction')

        elif control_name == 'adjacency_complex':
            if new == '':
                print "Please define a mode for adjacency complex computation"
                set_default_control(self._controls, 'compute_adjacency')
            else:
                set_default_control(
                    self._controls,
                    'compute_adjacency',
                    value=self._compute_adjacency_button_pressed)

        self.refresh_manager()
Пример #5
0
#world.add(draco.segmented_image-(draco.segmented_image==1),'segmented_image',colormap='glasbey',alphamap='constant',bg_id=0)
world.add(draco.point_topomesh,'image_cells')
world['image_cells_vertices'].set_attribute('point_radius',img.max())
world.add(draco.layer_edge_topomesh['L1'],'L1_adjacency')
#world.add(draco.image_cell_vertex_topomesh,'image_cell_vertex')

draco.delaunay_adjacency_complex(surface_cleaning_criteria = [])
#draco.delaunay_adjacency_complex(surface_cleaning_criteria = ['surface','sliver','distance'])

draco.adjacency_complex_optimization(n_iterations=2)

from copy import deepcopy
triangulation_topomesh = deepcopy(draco.triangulation_topomesh)
world.add(triangulation_topomesh,'cell_adjacency_complex')
world['cell_adjacency_complex_cells'].set_attribute('polydata_colormap',load_colormaps()['grey'])
world['cell_adjacency_complex_cells'].set_attribute('intensity_range',(-1,0))
world['cell_adjacency_complex'].set_attribute('coef_3',0.95)#
#world['cell_adjacency_complex_cells'].set_attribute('x_slice',(50,100))
world['cell_adjacency_complex_cells'].set_attribute('display_colorbar',False)

#triangular = ['star','remeshed','regular','projected']
triangular = ['star','split']
image_dual_topomesh = draco.dual_reconstruction(reconstruction_triangulation = triangular, adjacency_complex_degree=3)
#image_dual_topomesh = draco.draco_topomesh(reconstruction_triangulation = triangular)

world.add(image_dual_topomesh ,'dual_reconstuction')

from openalea.mesh.property_topomesh_extraction import epidermis_topomesh

L1_topomesh = epidermis_topomesh(image_dual_topomesh)
Пример #6
0
from openalea.oalab.colormap.colormap_def import load_colormaps

filename = "/Users/gcerutti/Developpement/openalea/openalea_meshing_data/share/data/output_meshes/propTopomesh_withCurv_persoZones_T00/propTopomesh_withCurv_persoZones_T00_star_split_topomesh.pkl"
topomesh = pickle.load(open(filename,'r'))

compute_topomesh_property(topomesh,'triangles',1)
compute_topomesh_property(topomesh,'vertices',1)

topomesh.update_wisp_property('boundary',1,array_dict((np.array(map(len,topomesh.wisp_property('triangles',1).values()))==1).astype(int),list(topomesh.wisps(1))))

world.add(topomesh,"topomesh")
world['topomesh'].set_attribute('display_3',False)
world['topomesh'].set_attribute('property_name_1','boundary')
world['topomesh'].set_attribute('display_1',True)
world['topomesh_edges'].set_attribute('intensity_range',(0,1))
world['topomesh_edges'].set_attribute('polydata_colormap',load_colormaps()['Reds'])
world['topomesh_edges'].set_attribute('linewidth',3)
world['topomesh_edges'].set_attribute('polydata_alpha',0.5)
raw_input()

from scipy.cluster.vq import vq
from time import sleep
distance_threshold = 0.5

boundary_edges = np.array(list(topomesh.wisps(1)))[topomesh.wisp_property('boundary',1).values()==1]
boundary_edge_centers = topomesh.wisp_property('barycenter',0).values(topomesh.wisp_property('vertices',1).values(boundary_edges)).mean(axis=1)
sorted_boundary_edges = boundary_edges[np.argsort(-boundary_edge_centers[:,2])]
sorted_boundary_edge_centers = boundary_edge_centers[np.argsort(-boundary_edge_centers[:,2])]


boundary_vertices = list(np.unique(topomesh.wisp_property('vertices',1).values(boundary_edges)))
Пример #7
0
    def _draco_control_changed(self, control_name, old, new):
        print control_name," changed! : ",new

        control_names = [c['name'] for c in self._controls]
        self._controls[control_names.index(control_name)]['value'] = new

        if control_name == 'img_filename':
            img_file = new
            try:
                img = imread(img_file)
                assert img.ndim == 3
            except:
                print "Image type not recognized! Please choose a different file..."
                set_default_control(self._controls,'initialize')
            else:
                self.name = os.path.split(img_file)[-1].split('.')[0]
                set_default_control(self._controls,'initialize',value=self._init_button_pressed)
        
        elif control_name == 'display_img':
            if new:
                self.world.add(self.draco.segmented_image,self.name+'_segmented_image',colormap='glasbey',alphamap='constant',bg_id=1)
            else:
                if self.world.has_key(self.name+'_segmented_image'):
                    self.world.remove(self.name+'_segmented_image')

        elif control_name == 'display_cells':
            if new:
                self.world.add(self.draco.point_topomesh,self.name+'_image_cells')
                self.world[self.name+'_image_cells_vertices'].set_attribute('point_radius',self.draco.segmented_image.max())
                self.world[self.name+'_image_cells_vertices'].set_attribute('display_colorbar',False)
            else:
                if self.world.has_key(self.name+'_image_cells'):
                    self.world.remove(self.name+'_image_cells')

        elif control_name == 'display_adjacency':
            control_names = [c['name'] for c in self._controls]
            adjacency_complex = self._controls[control_names.index('adjacency_complex')]['value']
            if adjacency_complex in ['delaunay','L1-L2']:
                degree = 3
            else:
                degree = 2

            if new:
                self.world.add(self.draco.triangulation_topomesh,self.name+'_adjacency_complex')
                if degree == 3:
                    self.world[self.name+'_adjacency_complex_cells'].set_attribute('polydata_colormap',load_colormaps()['grey'])
                    self.world[self.name+'_adjacency_complex_cells'].set_attribute('intensity_range',(-1,0))
                    self.world[self.name+'_adjacency_complex'].set_attribute('coef_3',0.95)
                    self.world[self.name+'_adjacency_complex_cells'].set_attribute('display_colorbar',False)
                else:
                    self.world[self.name+'_adjacency_complex'].set_attribute('display_3',False)
                    self.world[self.name+'_adjacency_complex'].set_attribute('display_2',True)
                    self.world[self.name+'_adjacency_complex_faces'].set_attribute('polydata_colormap',load_colormaps()['grey'])
                    self.world[self.name+'_adjacency_complex_faces'].set_attribute('intensity_range',(-1,0))
                    self.world[self.name+'_adjacency_complex'].set_attribute('coef_2',0.98)
                    self.world[self.name+'_adjacency_complex_faces'].set_attribute('display_colorbar',False)
            else:
                if self.world.has_key(self.name+'_adjacency_complex'):
                    self.world.remove(self.name+'_adjacency_complex')

        elif control_name == 'display_dual':
            if new:
                self.world.add(self.draco.dual_reconstruction_topomesh,self.name+'_dual_reconstruction')
            else:
                if self.world.has_key(self.name+'_dual_reconstruction'):
                    self.world.remove(self.name+'_dual_reconstruction')


        elif control_name == 'adjacency_complex':
            if new == '':
                print "Please define a mode for adjacency complex computation"
                set_default_control(self._controls,'compute_adjacency')
            else:
                set_default_control(self._controls,'compute_adjacency',value=self._compute_adjacency_button_pressed)

        self.refresh_manager()
Пример #8
0
primordia_colors[-1] = "#0065ff"
primordia_colors[0] = "#64bca4"
primordia_colors[1] = "#e30d00"
primordia_colors[2] = "#ffa200"
primordia_colors[3] = "#cccccc"
primordia_colors[4] = "#dddddd"
primordia_colors[5] = "#eeeeee"

clv3_color = "#c94389"

cmaps = {}
for cmap_name in [
        '1Flashy_green', '1Flashy_purple', '1Flashy_orange',
        '1Flashy_turquoise', '1Flashy_red', 'geo_jet', 'curvature'
]:
    cmap = load_colormaps()[cmap_name]

    color_dict = dict(red=[], green=[], blue=[])
    for p in np.sort(cmap._color_points.keys()):
        for k, c in enumerate(['red', 'green', 'blue']):
            color_dict[c] += [(p, cmap._color_points[p][k],
                               cmap._color_points[p][k])]
    for c in ['red', 'green', 'blue']:
        color_dict[c] = tuple(color_dict[c])
    cm.register_cmap(cmap_name,
                     mpl.colors.LinearSegmentedColormap(cmap.name, color_dict))

    color_dict = dict(red=[], green=[], blue=[])
    for p in np.sort(cmap._color_points.keys()):
        for k, c in enumerate(['red', 'green', 'blue']):
            color_dict[c] = [
Пример #9
0
image_dual_topomesh = draco.dual_reconstruction(
    reconstruction_triangulation=triangular,
    adjacency_complex_degree=3,
    maximal_edge_length=5.1)
#image_dual_topomesh = draco.draco_topomesh(reconstruction_triangulation = triangular)

from openalea.cellcomplex.property_topomesh.property_topomesh_optimization import property_topomesh_vertices_deformation
#property_topomesh_vertices_deformation(image_dual_topomesh,iterations=15)

world.add(image_dual_topomesh, 'dual_reconstuction')

draco_file = dirname + "/output_meshes/" + filename + "/" + filename + "_DRACO_mesh.ply"
save_ply_property_topomesh(image_dual_topomesh,
                           draco_file,
                           color_faces=True,
                           colormap=load_colormaps()['glasbey'])

optimized_dual_topomesh = optimize_topomesh(
    image_dual_topomesh,
    omega_forces={
        'regularization': 0.00,
        'neighborhood': 0.65,
        'taubin_smoothing': 0.65,
        'laplacian': 0.7,
        'planarization': 0.27,
        'epidermis_planarization': 0.05,
        'convexity': 0.06
    },
    omega_regularization_max=0.01,
    edge_flip=True,
    cell_vertex_motion=True,
Пример #10
0
    'layer', 0).values() == 1]
non_L1_cells = np.array(list(seed_topomesh.wisps(0)))[
    seed_topomesh.wisp_property('layer', 0).values() != 1]
# from copy import deepcopy
# ## L1-seed :
# L1_seed_topomesh = deepcopy(seed_topomesh)
# L1_seed_cells = np.array(list(L1_seed_topomesh.wisps(0)))[L1_seed_topomesh.wisp_property('layer',0).values()==1]
# non_L1_seed_cells = [c for c in L1_seed_topomesh.wisps(0) if not c in L1_seed_cells]
# for c in non_L1_seed_cells:
#     L1_seed_topomesh.remove_wisp(0,c)
# for property_name in L1_seed_topomesh.wisp_property_names(0):
#     d_ppty = dict(zip(list(L1_seed_topomesh.wisps(0)), L1_seed_topomesh.wisp_property(property_name,0).values(list(L1_seed_topomesh.wisps(0)))))
#     L1_seed_topomesh.update_wisp_property(property_name,0,d_ppty)

world.add(seed_topomesh, "detected_seed")
world["detected_seed_vertices"]["polydata_colormap"] = load_colormaps()['jet']
world["detected_seed"]["property_name_0"] = "layer"
world["detected_seed_vertices"]["intensity_range"] = (-0.5, 2.5)
world["detected_seed_vertices"]["display_colorbar"] = False

world.add(L1_corrected_topomesh, "L1_corrected_nuclei" + suffix)
world["L1_corrected_nuclei"]["property_name_0"] = 'layer'
world["L1_corrected_nuclei_vertices"]["polydata_colormap"] = load_colormaps(
)['Greens']

# evaluation = evaluate_nuclei_detection(seed_topomesh, eq_seed_topomesh, max_matching_distance=2.0, outlying_distance=4.0, max_distance=np.linalg.norm(size*voxelsize))
# print(evaluation)

# Create a seed image from the nuclei barycenters:
seed_img = seed_image_from_points(img.shape,
                                  img.voxelsize,