def test_acc(img, grid): prob = edt_prob(img)[::grid[0],::grid[1]] dist = star_dist(img, n_rays=32, mode="cpp")[::grid[0],::grid[1]] points, probi, disti = non_maximum_suppression(dist, prob, grid = grid, prob_thresh=0.4) img2 = polygons_to_label(disti, points, shape=img.shape) m = matching(img, img2) acc = m.accuracy print("accuracy {acc:.2f}".format(acc=acc)) assert acc > 0.9
def test_bbox_search(img): prob = edt_prob(img) dist = star_dist(img, n_rays=32, mode="cpp") coord = dist_to_coord(dist) nms_a = non_maximum_suppression( coord, prob, prob_thresh=0.4, verbose=False, max_bbox_search=False) nms_b = non_maximum_suppression( coord, prob, prob_thresh=0.4, verbose=False, max_bbox_search=True) check_similar(nms_a, nms_b)
def test_acc(img): prob = edt_prob(img) dist = star_dist(img, n_rays=32, mode="cpp") coord = dist_to_coord(dist) points = non_maximum_suppression(coord, prob, prob_thresh=0.4) img2 = polygons_to_label(coord, prob, points, shape=img.shape) m = matching(img, img2) acc = m.accuracy print("accuracy {acc:.2f}".format(acc=acc)) assert acc > 0.9
def get_objectprobs(self, labels): objectprobs = np.zeros((1, labels.shape[1], labels.shape[2]), dtype="float32") for i in range(labels.shape[0]): objectprobs += edt_prob(labels[i].astype("int32")) objectprobs[:, labels.sum(axis=0) > 1.5] = -1 return objectprobs
def test_acc_old(img, grid): from stardist.geometry.geom2d import _polygons_to_label_old, _dist_to_coord_old from stardist.nms import _non_maximum_suppression_old prob = edt_prob(img)[::grid[0],::grid[1]] dist = star_dist(img, n_rays=32, mode="cpp")[::grid[0],::grid[1]] coord = _dist_to_coord_old(dist, grid = grid) points = _non_maximum_suppression_old(coord, prob, prob_thresh=0.4, grid=grid) img2 = _polygons_to_label_old(coord, prob, points, shape=img.shape) m = matching(img, img2) acc = m.accuracy print("accuracy {acc:.2f}".format(acc=acc)) assert acc > 0.9
def test_bbox_search_old(img): from stardist.geometry.geom2d import _polygons_to_label_old, _dist_to_coord_old from stardist.nms import _non_maximum_suppression_old prob = edt_prob(img) dist = star_dist(img, n_rays=32, mode="cpp") coord = _dist_to_coord_old(dist) points_a = _non_maximum_suppression_old(coord, prob, prob_thresh=0.4, verbose=False, max_bbox_search=False) points_b = _non_maximum_suppression_old(coord, prob, prob_thresh=0.4, verbose=False, max_bbox_search=True) img2_a = _polygons_to_label_old(coord, prob, points_a, shape=img.shape) img2_b = _polygons_to_label_old(coord, prob, points_b, shape=img.shape) check_similar(points_a, points_b) check_similar(img2_a, img2_b)
def __getitem__(self, idx): assert self.raw_files[idx] == self.target_files[idx] img_name = os.path.join(self.root_dir, 'images', self.raw_files[idx]) image = io.imread(img_name) image = normalize(image, 1, 99.8, axis=(0, 1)) image = np.expand_dims(image, 0) target_name = os.path.join(self.root_dir, 'masks', self.target_files[idx]) target = io.imread(target_name) distances = star_dist(target, self.n_rays, opencl=False) if self.max_dist: distances[distances > self.max_dist] = self.max_dist distances = np.transpose(distances, (2, 0, 1)) obj_probabilities = edt_prob(target) obj_probabilities = np.expand_dims(obj_probabilities, 0) if self.transform: image = self.transform(image) if self.target_transform: distances = self.target_transform(distances) obj_probabilities = self.target_transform(obj_probabilities) return image, obj_probabilities, distances