def __init__( self, image=None, image_file=None, image_cell_vertex_file=None, triangulation_file=None, reconstruction_triangulation=["star", "split", "projected", "flat"], ): """Initialize the DRACO object by providing a segmented image. Image can be passed either as an object of a filename. Cell adjacency information will be extracted from image at initialization, still, some time can always be saved: if previously extracted, it can be read from existing file; if not the extrcted information will be saved in the specified files. Args: image (SpatialImage): a (non-eroded) segmented label image image_file (str): a valid path to an image of readable type (.inr, .inr.gz, .tiff...) : image_cell_vertex_file (str): file to read from if cell-vertices have already been extracted triangulation_file (str): file to load from if an already existing adjacency complex is to be used reconstruction_triangulation (list): default values for dual reconstruction triangulation (see dual_reconstruction for more details) Returns: None """ if image is not None: self.segmented_image = deepcopy(image) else: self.segmented_image = imread(image_file) self.segmented_image[self.segmented_image == 0] = 1 self.resolution = np.array(self.segmented_image.resolution) self.size = np.array(self.segmented_image.shape) self.triangulation_topomesh = None self.image_graph = None if image_cell_vertex_file is not None: try: self.image_cell_vertex = pickle.load(open(image_cell_vertex_file, "rb")) except: self.image_cell_vertex = cell_vertex_extraction(self.segmented_image) pickle.dump(self.image_cell_vertex, open(image_cell_vertex_file, "wb")) else: self.image_cell_vertex = cell_vertex_extraction(self.segmented_image) self.image_cell_vertex_topomesh = None self.positions = None self.cell_layer = None self.image_labels = None self.image_cell_volumes = None self.image_wall_surfaces = None self.point_topomesh = None self.delaunay_topomesh = None self.optimized_delaunay_topomesh = None self.surface_topomesh = None self.reconstruction_triangulation = reconstruction_triangulation self.dual_reconstruction_topomesh = None self.compute_image_adjacency() if triangulation_file is not None: try: topomesh = pickle.load(open(triangulation_file, "rb")) self.triangulation_topomesh = topomesh except: print "Impossible to load adjacency complex topomesh : FileNotFound ", triangulation_file
inputfile = dirname+"/segmented_images/"+filename+".inr.gz" size = 100. #n_points = int((4.*np.power(size/4.,2.))/(np.power(15.,2))) n_points = 21 print size," -> ",n_points img = sphere_tissue_image(size=size, n_points=n_points) imsave(inputfile,img) #inputfile = "/Users/gcerutti/Developpement/openalea/openalea_marsalt/example/time_0_cut_seg_median.inr" img = imread(inputfile) #img[img==0]=1 #img = SpatialImage(np.concatenate([img[:,:,35:],np.ones((img.shape[0],img.shape[1],5))],axis=2).astype(np.uint16),resolution=img.resolution) cell_vertex_file = dirname+"/output_meshes/"+filename+"/image_cell_vertex.dict" triangulation_file = dirname+"/output_meshes/"+filename+"/"+filename+"_draco_adjacency_complex.pkl" from openalea.container import array_dict world.add(img,"segmented_image",colormap='glasbey',alphamap='constant',bg_id=1,alpha=1.0) #draco = DracoMesh(image=img, image_cell_vertex_file=cell_vertex_file, triangulation_file=triangulation_file) #draco = DracoMesh(image_file=inputfile, image_cell_vertex_file=cell_vertex_file) draco = DracoMesh(image=img)
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()
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()
#filename = "segmentation" #filename = "olli01_lti6b_150421_sam01_t000_seg_hmin_2" #filename = "sphere_cells" filename = "yr02_t132_seg" dirname = '/Users/gcerutti/Developpement/openalea/openalea_meshing_data/share/data/' #dirname = shared_data(vplants.meshing_data) #meshing_dirname = dirname.parent.parent import os if not os.path.exists(dirname + "/output_meshes/" + filename): os.makedirs(dirname + "/output_meshes/" + filename) inputfile = dirname + "/segmented_images/" + filename + ".inr.gz" img = imread(inputfile) #img[img==0]=1 #img = SpatialImage(np.concatenate([img[:,:,35:],np.ones((img.shape[0],img.shape[1],5))],axis=2).astype(np.uint16),voxelsize=img.voxelsize) cell_vertex_file = dirname + "/output_meshes/" + filename + "/image_cell_vertex.dict" triangulation_file = dirname + "/output_meshes/" + filename + "/" + filename + "_draco_adjacency_complex.pkl" from openalea.container import array_dict world.add(img, "segmented_image", colormap='glasbey', alphamap='constant', bg_id=1, alpha=1.0)
import numpy as np from openalea.image.serial.all import imread from openalea.cellcomplex.property_topomesh.utils.tissue_analysis_tools import cell_vertex_extraction from openalea.cellcomplex.property_topomesh.property_topomesh_creation import tetrahedra_topomesh from vplants.tissue_analysis.temporal_graph_from_image import graph_from_image from openalea.oalab.colormap.colormap_def import load_colormaps # filename = "/Users/gcerutti/Developpement/d-tk/gnomon-data/0hrs_plant1_seg_small.inr" filename = "/data/Yassin/YR_01_ATLAS_iso/segmentations/t10_segmented_new_clean_2.tif" background_adjacency = False img = imread(filename) if 'world' in dir(): world.add(img, 'segmented_image', colormap='glasbey', alphamap='constant', alpha=0.2) cell_vertex = cell_vertex_extraction(img) tetras = np.array(cell_vertex.keys()) img_graph = graph_from_image( img, spatio_temporal_properties=['barycenter', 'volume'], ignore_cells_at_stack_margins=True) positions = img_graph.vertex_property('barycenter')