def compute_cells(self, params, image_manager, segments_manager): """Creates a cell list that is stored on self.cells as a dict, where each cell id is a key of the dict. Also creates an overlay of the cells edges over both the base and fluor image. Requires the loading of the images and the computation of the segments""" self.cell_regions_from_labels(segments_manager.labels) rotations = cp.rotation_matrices(params.axial_step) self.compute_box_axes(rotations, image_manager.mask.shape) self.original_cells = deepcopy(self.cells) for k in self.cells.keys(): try: c = self.cells[k] if len(c.neighbours) > 0: bestneigh = max(c.neighbours.iterkeys(), key=(lambda key: c.neighbours[key])) bestinterface = c.neighbours[bestneigh] cn = self.cells[str(int(bestneigh))] if cp.check_merge(c, cn, rotations, bestinterface, image_manager.mask, params): self.merge_cells(c.label, cn.label, params, segments_manager, image_manager) except KeyError: print "Cell was already merged and deleted" for k in self.cells.keys(): cp.assign_cell_color(self.cells[k], self.cells, self.cell_colors) self.overlay_cells(image_manager)
def split_cells(self, label_c1, params, segments_manager, image_manager): """Splits a previously merged cell.""" merged_cells = self.cells[str(label_c1)].merged_list merged_cells.append(label_c1) del self.cells[str(label_c1)] rotations = cp.rotation_matrices(params.axial_step) for id in merged_cells: id = int(id) self.cells[str(id)] = deepcopy(self.original_cells[str(id)]) self.cells[str(id)].compute_axes(rotations, image_manager.mask.shape) self.cells[str(id)].recompute_outline(segments_manager.labels) if len(self.cells[str(id)].merged_list) == 0: self.cells[str(id)].merged_with = "No" for k in self.cells.keys(): cp.assign_cell_color(self.cells[k], self.cells, self.cell_colors)
def compute_cells(self, params, image_manager, segments_manager): """Creates a cell list that is stored on self.cells as a dict, where each cell id is a key of the dict. Also creates an overlay of the cells edges over both the base and fluor image. Requires the loading of the images and the computation of the segments""" self.cell_regions_from_labels(segments_manager.labels, params.imageloaderparams.pixel_size) rotations = cp.rotation_matrices( params.cellprocessingparams.axial_step) self.compute_box_axes(rotations, image_manager.mask.shape, params.imageloaderparams.pixel_size) self.original_cells = deepcopy(self.cells) for k in list(self.cells.keys()): try: c = self.cells[k] if len(c.neighbours) > 0: bestneigh = max(list(iter(c.neighbours.keys())), key=(lambda key: c.neighbours[key])) bestinterface = c.neighbours[bestneigh] cn = self.cells[str(int(bestneigh))] if cp.check_merge(c, cn, rotations, bestinterface, image_manager.mask, params.cellprocessingparams): self.merge_cells(c.label, cn.label, params, segments_manager, image_manager) except KeyError: print("Cell was already merged and deleted") for k in self.cells.keys(): cp.assign_cell_color(self.cells[k], self.cells, self.cell_colors, params.imageloaderparams.pixel_size) self.overlay_cells(image_manager)