def search_cells(self, prediction_mask, img): if self.edge_only: if self.return_mask: cells, prediction_mask = mask_to_cells_edge( prediction_mask, img, self.config, self.r_min, self.frame_data, self.edge_dist, return_mask=self.return_mask) else: cells = mask_to_cells_edge(prediction_mask, img, self.config, self.r_min, self.frame_data, self.edge_dist, return_mask=self.return_mask) else: cells = mask_to_cells(prediction_mask, img, self.config, self.r_min, self.frame_data, self.edge_dist) return prediction_mask, cells
def segmentation(self, img): if len(img.shape) == 3: img = img[:, :, 0] img = (img - np.mean(img)) / np.std(img).astype(np.float32) prob_map = self.unet.predict(img[None, :, :, None])[0, :, :, 0] prediction_mask = prob_map > 0.5 cells = mask_to_cells(prediction_mask, img, self.config, self.r_min, self.frame_data, self.edge_dist) return prediction_mask, cells, prob_map
def load_polygones(cdb, img_o, ny, nx, points, im, config, r_min, frame_data, edge_dist, irr_th=1.06, sol_th=0.96): # Loading ellipses/cells from ClickPoints polygon markers. q_polys = cdb.getPolygons(image=img_o) mask = np.zeros(img_o.getShape()[0:2], dtype=np.uint8) for pol in q_polys: polygon = np.array([pol.points]) if len(polygon[0]) > 5: # Ground Truth may contain accidentally clicked small polygons path = Path(polygon.squeeze()) grid = path.contains_points(points) grid = grid.reshape((ny, nx)) mask += grid cells = mask_to_cells(mask, im, config, r_min, frame_data, edge_dist) cells_filtered = filter_cells(cells, irr_th, sol_th) ellipses = np.array( [[cell["y"], cell["x"], cell["long_axis"], cell["short_axis"], cell["angle"], getStrain(cell)] for cell in cells]) ellipses_filtered = np.array( [[cell["y"], cell["x"], cell["long_axis"], cell["short_axis"], cell["angle"], getStrain(cell)] for cell in cells_filtered]) return mask, ellipses, ellipses_filtered, q_polys
def getMaskEllipse(self, frame): try: mask = self.db.getMask(frame=frame).data im = self.db.getImages(frame=frame)[0] except AttributeError: mask_shape = (self.ny, self.nx) mask = np.zeros(mask_shape, dtype=np.uint8) img_o = self.db.getImage(frame=frame) q_polys = self.db.getPolygons(image=img_o) for pol in q_polys: if np.shape(pol)[0] != 0: polygon = np.array([[pol.points]]) if np.sum( polygon.shape ) > 7: # single point polygon can happen on accident when clicking path = Path(polygon.squeeze()) grid = path.contains_points(self.points) grid = grid.reshape(mask_shape) mask += grid cells = mask_to_cells(mask, im.data, self.config, self.r_min, self.frame_data, self.edge_dist) return mask, cells