コード例 #1
0
def process_row(row, x, y, roi, end_type, parent_id=-1):
    """
    Convert each row into a line shape.
    Add the identifier of the parent shape if applicable.
    """
    frame = int(row[0])
    top = int(row[1]) + y
    bottom = int(row[2]) + y
    # Create the line
    line = LineI()
    line.x1 = rdouble(x)
    line.x2 = rdouble(x)
    line.y1 = rdouble(top)
    line.y2 = rdouble(bottom)
    line.theT = rint(frame)
    name = end_type
    if parent_id > -1:
        name += ", come from shapeID:%s" % parent_id
    line.textValue = rstring(name)
    # Use yellow
    line.strokeColor = rint(
        int.from_bytes([255, 0, 0, 255], byteorder='big', signed=True))
    roi.addShape(line)
    return frame
コード例 #2
0
def create_omero_shape(shape_type, data, image):
    # "line", "path", "polygon", "rectangle", "ellipse"
    # NB: assume all points on same plane.
    # Use first point to get Z and T index
    z_index = get_z(data[0], image)
    t_index = get_t(data[0], image)
    shape = None
    if shape_type == "line":
        shape = LineI()
        shape.x1 = rdouble(get_x(data[0]))
        shape.y1 = rdouble(get_y(data[0]))
        shape.x2 = rdouble(get_x(data[1]))
        shape.y2 = rdouble(get_y(data[1]))
        shape.textValue = rstring("line-from-napari")
    elif shape_type == "path" or shape_type == "polygon":
        shape = PolylineI() if shape_type == "path" else PolygonI()
        # points = "10,20, 50,150, 200,200, 250,75"
        points = ["%s,%s" % (get_x(d), get_y(d)) for d in data]
        shape.points = rstring(", ".join(points))
        shape.textValue = rstring("polyline-from-napari") if shape_type == "path" else rstring("polygon-from-napari")
    elif shape_type == "rectangle" or shape_type == "ellipse":
        # corners go anti-clockwise starting top-left
        x1 = get_x(data[0])
        x2 = get_x(data[1])
        x3 = get_x(data[2])
        x4 = get_x(data[3])
        y1 = get_y(data[0])
        y2 = get_y(data[1])
        y3 = get_y(data[2])
        y4 = get_y(data[3])
        print(x1,x2)
        if shape_type == "rectangle":
            
            # Rectangle not rotated
            if x1 == x2:
                shape = RectangleI()
                # TODO: handle 'updside down' rectangle x3 < x1
                shape.x = rdouble(x1)
                shape.y = rdouble(y1)
                shape.width = rdouble(x3 - x1)
                shape.height = rdouble(y2 - y1)
            else:
                # Rotated Rectangle - save as Polygon
                shape = PolygonI()
                points = "%s,%s, %s,%s, %s,%s, %s,%s" % (
                    x1, y1, x2, y2, x3, y3, x4, y4
                )
                shape.points = rstring(points)
            shape.textValue = rstring("rectangle-from-napari")
        elif shape_type == "ellipse":
            
            # Ellipse not rotated (ignore floating point rouding)
            if int(x1) == int(x2):
                shape = EllipseI()
                shape.x = rdouble((x1 + x3) / 2)
                shape.y = rdouble((y1 + y2) / 2)
                shape.radiusX = rdouble(abs(x3 - x1) / 2)
                shape.radiusY = rdouble(abs(y2 - y1) / 2)
            else:
                # TODO: Need to calculate transformation matrix
                print("Rotated Ellipse not yet supported!")
            shape.textValue = rstring("ellipse-from-napari")

    if shape is not None:
        shape.theZ = rint(z_index)
        shape.theT = rint(t_index)
    return shape