Esempio n. 1
0
def mask():
    o = MaskI()
    populate_shape(o)
    o.x = rdouble(0.0)
    o.y = rdouble(0.0)
    o.width = rdouble(1.0)
    o.height = rdouble(2.0)
    o.id = rlong(8L)
    return o
Esempio n. 2
0
def mask(identity_transform):
    o = MaskI()
    populate_shape(o, identity_transform)
    o.x = rdouble(0.0)
    o.y = rdouble(0.0)
    o.width = rdouble(1.0)
    o.height = rdouble(2.0)
    o.id = rlong(8)
    return o
Esempio n. 3
0
 def __init__(self, maskShape=None):
     ShapeData.__init__(self)
     if(maskShape is None):
         self.setValue(MaskI())
         self.setX(0)
         self.setY(0)
         self.setWidth(0)
         self.setHeight(0)
         self.setBytes(None)
     else:
         self.setValue(maskShape)
Esempio n. 4
0
def make_mask(x, y, h, w):
    mask = MaskI()
    mask.x = rdouble(x)
    mask.y = rdouble(y)
    mask.height = rdouble(h)
    mask.width = rdouble(w)
    mask.bytes = make_circle(h, w)

    roi = RoiI()
    roi.description = rstring("created by overlapping-masks.py")
    roi.addShape(mask)
    roi.image = image
    roi = update_service.saveAndReturnObject(roi)
    print(f"Roi:{roi.id.val}")
Esempio n. 5
0
    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]
Esempio n. 6
0
def mask_from_binary_image(binim,
                           rgba=None,
                           z=None,
                           c=None,
                           t=None,
                           text=None,
                           raise_on_no_mask=True):
    """
    Create a mask shape from a binary image (background=0)

    :param numpy.array binim: Binary 2D array, must contain values [0, 1] only
    :param rgba int-4-tuple: Optional (red, green, blue, alpha) colour
    :param z: Optional Z-index for the mask
    :param c: Optional C-index for the mask
    :param t: Optional T-index for the mask
    :param text: Optional text for the mask
    :param raise_on_no_mask: If True (default) throw an exception if no mask
           found, otherwise return an empty Mask
    :return: An OMERO mask
    :raises NoMaskFound: If no labels were found
    :raises InvalidBinaryImage: If the maximum labels is greater than 1
    """

    # Find bounding box to minimise size of mask
    xmask = binim.sum(0).nonzero()[0]
    ymask = binim.sum(1).nonzero()[0]
    if any(xmask) and any(ymask):
        x0 = min(xmask)
        w = max(xmask) - x0 + 1
        y0 = min(ymask)
        h = max(ymask) - y0 + 1
        submask = binim[y0:(y0 + h), x0:(x0 + w)]
        if not np.array_equal(np.unique(submask),
                              [0, 1]) and not np.array_equal(
                                  np.unique(submask), [1]):
            raise InvalidBinaryImage()
    else:
        if raise_on_no_mask:
            raise NoMaskFound()
        x0 = 0
        w = 0
        y0 = 0
        h = 0
        submask = []

    mask = MaskI()
    # BUG in older versions of Numpy:
    # https://github.com/numpy/numpy/issues/5377
    # Need to convert to an int array
    # mask.setBytes(np.packbits(submask))
    mask.setBytes(np.packbits(np.asarray(submask, dtype=int)))
    mask.setWidth(rdouble(w))
    mask.setHeight(rdouble(h))
    mask.setX(rdouble(x0))
    mask.setY(rdouble(y0))

    if rgba is not None:
        ch = ColorHolder.fromRGBA(*rgba)
        mask.setFillColor(rint(ch.getInt()))
    if z is not None:
        mask.setTheZ(rint(z))
    if c is not None:
        mask.setTheC(rint(c))
    if t is not None:
        mask.setTheT(rint(t))
    if text is not None:
        mask.setTextValue(rstring(text))

    return mask
Esempio n. 7
0
 def createBaseType(self):
     return MaskI()
Esempio n. 8
0
 def createBaseType(self):
     warnings.warn("This module is deprecated as of OMERO 5.3.0",
                   DeprecationWarning)
     return MaskI()
Esempio n. 9
0
idr.connect()
local.connect()

query_service = idr.getQueryService()
update_service = local.getUpdateService()

query = "FROM Mask WHERE roi.image.id = :id"

params = ParametersI()
params.addId(image_id_src)

count = 0

for mask_src in query_service.findAllByQuery(query, params):
    mask_dst = MaskI()
    mask_dst.x = mask_src.x
    mask_dst.y = mask_src.y
    mask_dst.width = mask_src.width
    mask_dst.height = mask_src.height
    mask_dst.theZ = mask_src.theZ
    mask_dst.theC = mask_src.theC
    mask_dst.theT = mask_src.theT
    mask_dst.bytes = mask_src.bytes
    mask_dst.fillColor = mask_src.fillColor
    mask_dst.transform = mask_src.transform
    roi_dst = RoiI()
    roi_dst.description = rstring(
        "created by copy-masks script for original mask #{}".format(
            mask_src.id.val))
    roi_dst.image = ImageI(image_id_dst, False)