Example #1
0
def create_omero_point(data, image):
    point = PointI()
    point.x = rdouble(get_x(data))
    point.y = rdouble(get_y(data))
    point.theZ = rint(get_z(data, image))
    point.theT = rint(get_t(data, image))
    point.textValue = rstring("point-from-napari")
    return point
    def shapes(self):
        """Create a bunch of unsaved Shapes."""
        rect = RectangleI()
        rect.x = rdouble(10)
        rect.y = rdouble(20)
        rect.width = rdouble(30)
        rect.height = rdouble(40)
        # Only save theT, not theZ
        rect.theT = rint(0)
        rect.textValue = rstring("test-Rectangle")
        rect.fillColor = rint(rgba_to_int(255, 255, 255, 255))
        rect.strokeColor = rint(rgba_to_int(255, 255, 0, 255))

        # ellipse without saving theZ & theT
        ellipse = EllipseI()
        ellipse.x = rdouble(33)
        ellipse.y = rdouble(44)
        ellipse.radiusX = rdouble(55)
        ellipse.radiusY = rdouble(66)
        ellipse.textValue = rstring("test-Ellipse")

        line = LineI()
        line.x1 = rdouble(200)
        line.x2 = rdouble(300)
        line.y1 = rdouble(400)
        line.y2 = rdouble(500)
        line.textValue = rstring("test-Line")

        point = PointI()
        point.x = rdouble(1)
        point.y = rdouble(1)
        point.theZ = rint(1)
        point.theT = rint(1)
        point.textValue = rstring("test-Point")

        polygon = PolygonI()
        polygon.theZ = rint(5)
        polygon.theT = rint(5)
        polygon.fillColor = rint(rgba_to_int(255, 0, 255, 50))
        polygon.strokeColor = rint(rgba_to_int(255, 255, 0))
        polygon.strokeWidth = LengthI(10, UnitsLength.PIXEL)
        points = "10,20, 50,150, 200,200, 250,75"
        polygon.points = rstring(points)

        mask = MaskI()
        mask.setTheC(rint(0))
        mask.setTheZ(rint(0))
        mask.setTheT(rint(0))
        mask.setX(rdouble(100))
        mask.setY(rdouble(100))
        mask.setWidth(rdouble(500))
        mask.setHeight(rdouble(500))
        mask.setTextValue(rstring("test-Mask"))
        mask.setBytes(None)

        return [rect, ellipse, line, point, polygon, mask]
Example #3
0
def point():
    o = PointI()
    populate_shape(o)
    if SCHEMA_VERSION == "2015-01":
        o.cx = rdouble(1.0)
        o.cy = rdouble(2.0)
    else:
        o.x = rdouble(1.0)
        o.y = rdouble(2.0)
    o.id = rlong(3L)
    return o
Example #4
0
def point():
    o = PointI()
    populate_shape(o)
    if SCHEMA_VERSION == '2015-01':
        o.cx = rdouble(1.0)
        o.cy = rdouble(2.0)
    else:
        o.x = rdouble(1.0)
        o.y = rdouble(2.0)
    o.id = rlong(3L)
    return o
Example #5
0
def point(identity_transform):
    o = PointI()
    populate_shape(o, identity_transform)
    if SCHEMA_VERSION == '2015-01':
        o.cx = rdouble(1.0)
        o.cy = rdouble(2.0)
    else:
        o.x = rdouble(1.0)
        o.y = rdouble(2.0)
    o.id = rlong(3)
    return o
def create_points(conn, df, image):

    columns = [
        "Sequence", "Tagged Protein", "Sequence is unique", "Location_X",
        "Location_Y"
    ]
    df2 = pandas.DataFrame(columns=(['Roi'] + columns))
    index = df['Source Name'] == image.getName()
    for (s, tp, u, x, y) in zip(*map(lambda x: df[index][x], columns)):
        p = PointI()
        p.x = rdouble(float(x))
        p.y = rdouble(float(y))
        p.setTextValue(rstring(tp))
        roi = RoiI()
        roi.addShape(p)
        roi.setName(rstring(tp))
        roi.setImage(ImageI(image.getId(), False))
        roi = conn.getUpdateService().saveAndReturnObject(roi)
        df2.loc[len(df2)] = (roi.getId().getValue(), s, tp, u, x, y)
    return df2
    def shapes(self):
        """Create a bunch of unsaved Shapes."""
        rect = RectangleI()
        rect.x = rdouble(10)
        rect.y = rdouble(20)
        rect.width = rdouble(30)
        rect.height = rdouble(40)
        rect.textValue = rstring("test-Rectangle")
        rect.fillColor = rint(rgba_to_int(255, 255, 255, 255))
        rect.strokeColor = rint(rgba_to_int(255, 255, 0, 255))

        ellipse = EllipseI()
        ellipse.x = rdouble(33)
        ellipse.y = rdouble(44)
        ellipse.radiusX = rdouble(55)
        ellipse.radiusY = rdouble(66)
        ellipse.textValue = rstring("test-Ellipse")

        line = LineI()
        line.x1 = rdouble(20)
        line.x2 = rdouble(30)
        line.y1 = rdouble(40)
        line.y2 = rdouble(50)
        line.textValue = rstring("test-Line")

        point = PointI()
        point.x = rdouble(50)
        point.y = rdouble(50)
        point.textValue = rstring("test-Point")

        polygon = PolygonI()
        polygon.fillColor = rint(rgba_to_int(255, 0, 255, 50))
        polygon.strokeColor = rint(rgba_to_int(255, 255, 0))
        polygon.strokeWidth = LengthI(10, UnitsLength.PIXEL)
        points = "10,20, 50,150, 100,100, 150,75"
        polygon.points = rstring(points)

        polyline = PolylineI()
        polyline.points = rstring(points)

        return [rect, ellipse, line, point, polygon, polyline]
Example #8
0
def main(conn, argv):

    parser = argparse.ArgumentParser()
    parser.add_argument("image", help="Image ID")
    args = parser.parse_args(argv)

    image_id = args.image

    data = swc.read(
        "20200628-ftp/RL_35_guassian_4_4_80.tif_x94_y327_z241_app2_(GSBT).swc"
    ).data_block

    # img_name = 'FADU_tumour_Lectin_substack_deconvolved_RL_35iters_guassian_psf_4_4_80.tif'
    image = conn.getObject("Image", image_id)

    # delete existing ROIs
    roi_service = conn.getRoiService()
    result = roi_service.findByImage(image.id, None)
    roi_ids = [roi.id.val for roi in result.rois]
    if roi_ids:
        print("Deleting ROIs...")
        conn.deleteObjects("Roi", roi_ids, wait=True)

    size_y = image.getSizeY()
    paths = parse_swc(data, size_y)
    red_int = int.from_bytes([255, 0, 0, 255], byteorder="big", signed=True)

    for count, path in enumerate(paths):
        points = []
        for zyx in path:
            z, y, x = zyx
            point = PointI()
            point.x = rdouble(x)
            point.y = rdouble(y)
            point.theZ = rint(round(z))
            point.strokeColor = rint(red_int)
            points.append(point)
        print(f"{count}/{len(paths)} Creating ROI with {len(points)} points")
        create_roi(image, points)
    def test_save_rois(self, conn, django_client):
        """Save new ROIs to an Image"""
        image = self.make_image(client=conn.c)
        roi = RoiI()
        roi.name = rstring("roi_name")
        roi.setImage(ImageI(image.id.val, False))
        point = PointI()
        point.x = rdouble(1)
        point.y = rdouble(2)

        encoder = get_encoder(point.__class__)
        point_json = encoder.encode(point)
        unsaved_id = "-1:-1"
        point_json['oldId'] = unsaved_id
        persist_url = reverse('omero_iviewer_persist_rois')
        data = {
            'imageId': image.id.val,
            'rois': {
                'count': 1,
                'new': [point_json]
            }
        }
        rsp = post_json(django_client, persist_url, data)
        print('rsp', rsp)
        # {"ids": {"-1:-1": "225504:416603"}}
        assert "ids" in rsp
        new_ids = rsp["ids"].values()
        assert len(new_ids) == 1
        new_id = rsp["ids"][unsaved_id]
        roi_id = int(new_id.split(':')[0])
        shape_id = int(new_id.split(':')[1])

        # Add Tag to ROI and Shape
        tag = TagAnnotationWrapper(conn)
        tag.setValue("ROI/Shape Tag")
        tag.save()
        roi = conn.getObject("Roi", roi_id)
        roi.linkAnnotation(tag)
        shape = conn.getObject("Shape", shape_id)
        shape.linkAnnotation(tag)
        # check...
        assert len(list(conn.getAnnotationLinks(
            "Shape", parent_ids=[shape_id]))) == 1

        # Load Shape
        rois_url = reverse('api_rois', kwargs={'api_version': 0})
        rois_url += '?image=%s' % image.id.val
        rsp = get_json(django_client, rois_url)
        assert len(rsp['data']) == 1

        # Edit Shape
        point_json = rsp['data'][0]['shapes'][0]
        point_json["X"] = 100
        point_json["Y"] = 200
        # iviewer wants to know ROI:Shape ID
        point_json["oldId"] = new_id
        # Unload details
        del point_json["omero:details"]
        data = {
            'imageId': image.id.val,
            'rois': {
                'count': 1,
                'modified': [point_json]
            }
        }
        rsp = post_json(django_client, persist_url, data)
        # IDs shouldn't have changed, e.g.
        # {"ids": {"225504:416603": "225504:416603"}}
        print('post rsp', rsp)
        assert rsp["ids"][new_id] == new_id

        # Check annotations not lost
        roi = conn.getObject("Roi", roi_id)
        assert len(list(roi.listAnnotations())) == 1
        assert len(list(conn.getAnnotationLinks(
            "Shape", parent_ids=[shape_id]))) == 1