Esempio n. 1
0
 def display_bounding_box(self, txn):
     box = neuroglancer.AxisAlignedBoundingBoxAnnotation()
     box.point_a = self.box_coords[0]
     box.point_b = self.box_coords[1]
     box.id = "selection"
     txn.layers["selection"] = neuroglancer.AnnotationLayer(
         annotations=[box])
Esempio n. 2
0
def show_bbox(pointa, pointb, name):
    global viewer
    global res
    pointa = np.asarray(pointa)
    pointb = np.asarray(pointb)
    with viewer.txn() as s:
        s.layers.append(name='bb_' + name,
                        layer=neuroglancer.AnnotationLayer(voxelSize=res))
        s.layers[-1].annotations.append(
            neuroglancer.AxisAlignedBoundingBoxAnnotation(
                id=0, point_a=(pointa)[::-1], point_b=(pointb)[::-1]))
Esempio n. 3
0
    def display(self):
        if self.img_path.startswith("precomputed:"):
            img = self.img_path
        else:
            img = load_image(self.img_path, self.x0, self.x1, self.y0, self.y1,
                             self.z0, self.z1)
        if self.alt_img_path is not None:
            if self.alt_img_path.startswith("precomputed:"):
                alt_img = self.alt_img_path
            else:
                alt_img = load_image(self.alt_img_path, self.x0, self.x1,
                                     self.y0, self.y1, self.z0, self.z1)
        if self.seg_path is not None:
            seg = load_image(self.seg_path, self.x0, self.x1,
                             self.y0, self.y1, self.z0, self.z1)
        with self.viewer.txn() as txn:
            layer(txn, "image", img, gray_shader, self.multiplier,
                  self.x0, self.y0, self.z0)
            if self.alt_img_path is not None:
                layer(txn, "alt-image", alt_img, green_shader,
                      self.alt_multiplier,
                      self.x0, self.y0, self.z0)
            if self.seg_path is not None:
                seglayer(txn, "segmentation", seg, self.x0, self.y0, self.z0)
            self.display_points(txn, self.points, "annotation", COLOR_POINTS)
            if self.detected_points is not None:
                self.display_points(txn, self.detected_points, "detected",
                                    COLOR_DETECTED_POINTS)
            elif has_layer(txn, "detected"):
                del txn.layers["detected"]
            if self.deleting_points is not None:
                self.display_points(txn, self.deleting_points, "deleting",
                                    COLOR_DELETING_POINTS)
            elif has_layer(txn, "deleting"):
                del txn.layers["deleting"]

            if self.box_coords is not None:
                self.display_bounding_box(txn)
            if self.bounding_box is not None:
                box = neuroglancer.AxisAlignedBoundingBoxAnnotation()
                box.point_a = self.bounding_box[0]
                box.point_b = self.bounding_box[1]
                box.id = "bounding-box"
                txn.layers["bounding-box"] = neuroglancer.AnnotationLayer(
                    annotations=[box])
                txn.position.voxel_coordinates = \
                    [(a + b) / 2 for a, b in zip(*self.bounding_box)]

            elif has_layer(txn, "selection"):
                del txn.layers["selection"]
        if self.bounding_box is None:
            self.center()
Esempio n. 4
0
def bboxlayer(txn, name, x0, x1, y0, y1, z0, z1):
    """Add a bounding box layer

    :param txn: the neuroglancer viewer transaction context
    :param name: the name of the layer
    :param x0: the leftmost edge of the box
    :param x1: the rightmost edge of the box
    :param y0: the topmost edge of the box
    :param y1: the bottommoste edge of the box
    :param z0: the most shallow depth of the box
    :param z1: the deepest edge of the box
    """
    box = neuroglancer.AxisAlignedBoundingBoxAnnotation()
    box.point_a = [x0, y0, z0]
    box.point_b = [x1, y1, z1]
    box.id = name
    txn.layers[name] = neuroglancer.AnnotationLayer(annotations=[box])
Esempio n. 5
0
def make_annotations_from_mask(mask, block_size):
    result = []
    for level, position_counts in enumerate(mask.blocks):
        full_count = _full_count_for_level(level)
        eff_block_size = block_size * 2**level
        for position in position_counts:
            count = position_counts[position]
            if count != full_count:
                continue
            position = np.array(position, dtype=np.int64)
            box_start = eff_block_size * position
            box_end = box_start + eff_block_size
            result.append(
                neuroglancer.AxisAlignedBoundingBoxAnnotation(
                    point_a=box_start,
                    point_b=box_end,
                    id=uuid.uuid4().hex,
                ))
    return result
Esempio n. 6
0
 def display_points(self):
     with self.viewer.txn() as txn:
         pointlayer(txn, "points", self.points[:, 0], self.points[:, 1],
                    self.points[:, 2], self.color)
         if self.deleting_points is not None:
             pointlayer(txn, "delete-points",
                        self.deleting_points[:, 0],
                        self.deleting_points[:, 1],
                        self.deleting_points[:, 2],
                        "red")
         if self.box_coords is not None:
             box = neuroglancer.AxisAlignedBoundingBoxAnnotation()
             box.point_a = self.box_coords[0]
             box.point_b = self.box_coords[1]
             box.id = "selection"
             txn.layers["selection"] = neuroglancer.AnnotationLayer(
                 annotations=[box])
         elif "selection" in txn.layers:
             del txn.layers["selection"]
Esempio n. 7
0
 def display_points_txn(self, txn):
     pointlayer(txn, self.name, self.points[:, 2], self.points[:, 1],
                self.points[:, 0], self.color,
                voxel_size=self.voxel_size)
     if self.deleting_points is not None:
         pointlayer(txn, "delete-%s" % self.name,
                    self.deleting_points[:, 2],
                    self.deleting_points[:, 1],
                    self.deleting_points[:, 0],
                    "red",
                    voxel_size=self.voxel_size)
     if self.box_coords is not None:
         box = neuroglancer.AxisAlignedBoundingBoxAnnotation()
         box.point_a = self.box_coords[0]
         box.point_b = self.box_coords[1]
         box.id = "selection"
         txn.layers["selection"] = neuroglancer.AnnotationLayer(
             annotations=[box])
     elif "selection" in txn.layers:
         del txn.layers["selection"]