Ejemplo n.º 1
0
def point():
    o = PointI()
    populate_shape(o)
    o.cx = rdouble(1.0)
    o.cy = rdouble(2.0)
    o.id = rlong(3L)
    return o
Ejemplo n.º 2
0
 def __init__(self, roicoord=ROICoordinate(), x=0, y=0, width=0, height=0):
     ShapeData.__init__(self)
     self.x = rdouble(x)
     self.y = rdouble(y)
     self.width = rdouble(width)
     self.height = rdouble(height)
     self.setCoord(roicoord)
Ejemplo n.º 3
0
def opt_unit_label(identity_transform):
    o = LabelI()
    populate_shape(o, identity_transform, False)
    o.x = rdouble(1.0)
    o.y = rdouble(2.0)
    o.id = rlong(7)
    return o
Ejemplo n.º 4
0
 def _parse_mnu_roi(self, columns):
     """Parses out ROI from OmeroTables columns for 'MNU' datasets."""
     log.debug("Parsing %s MNU ROIs..." % (len(columns[0].values)))
     image_ids = columns[self.IMAGE_COL].values
     rois = list()
     # Save our file annotation to the database so we can use an unloaded
     # annotation for the saveAndReturnIds that will be triggered below.
     self.file_annotation = self.update_service.saveAndReturnObject(self.file_annotation)
     unloaded_file_annotation = FileAnnotationI(self.file_annotation.id.val, False)
     batch_no = 1
     batches = dict()
     for i, image_id in enumerate(image_ids):
         unloaded_image = ImageI(image_id, False)
         roi = RoiI()
         shape = PointI()
         shape.theZ = rint(0)
         shape.theT = rint(0)
         values = columns[3].values
         shape.cx = rdouble(float(values[i]))
         values = columns[2].values
         shape.cy = rdouble(float(values[i]))
         roi.addShape(shape)
         roi.image = unloaded_image
         roi.linkAnnotation(unloaded_file_annotation)
         rois.append(roi)
         if len(rois) == self.ROI_UPDATE_LIMIT:
             self.thread_pool.add_task(self.update_rois, rois, batches, batch_no)
             rois = list()
             batch_no += 1
     self.thread_pool.add_task(self.update_rois, rois, batches, batch_no)
     self.thread_pool.wait_completion()
     batch_keys = batches.keys()
     batch_keys.sort()
     for k in batch_keys:
         columns[self.ROI_COL].values += batches[k]
Ejemplo n.º 5
0
 def __init__(self, roicoord=ROICoordinate(), x=0, y=0):
     warnings.warn("This module is deprecated as of OMERO 5.3.0",
                   DeprecationWarning)
     ShapeData.__init__(self)
     self.x = rdouble(x)
     self.y = rdouble(y)
     self.setCoord(roicoord)
Ejemplo n.º 6
0
def opt_unit_label():
    o = LabelI()
    populate_shape(o, False)
    o.x = rdouble(1.0)
    o.y = rdouble(2.0)
    o.id = rlong(7L)
    return o
Ejemplo n.º 7
0
 def __init__(self, roicoord=ROICoordinate(), x1=0, y1=0, x2=0, y2=0):
     ShapeData.__init__(self)
     self.x1 = rdouble(x1)
     self.y1 = rdouble(y1)
     self.x2 = rdouble(x2)
     self.y2 = rdouble(y2)
     self.setCoord(roicoord)
Ejemplo n.º 8
0
def create_mask(
        binim, rgba=None, z=None, c=None, t=None, text=None,
        raise_on_no_mask=False):
    """
    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 Exception("Invalid binary image")
    else:
        if raise_on_no_mask:
            raise Exception("No mask found")
        x0 = 0
        w = 0
        y0 = 0
        h = 0
        submask = []

    mask = MaskI()
    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
def roi_from_binary_image(binim, rgba):
    # Find bounding box to minimise size of mask
    xmask = binim.sum(0).nonzero()[0]
    ymask = binim.sum(1).nonzero()[0]
    x0 = min(xmask)
    w = max(xmask) - x0 + 1
    y0 = min(ymask)
    h = max(ymask) - y0 + 1
    submask = binim[y0:(y0 + h), x0:(x0 + w)]
    # print (x0, y0, w, h)

    mask = omero.model.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))

    ch = omero.gateway.ColorHolder.fromRGBA(*rgba)
    mask.setFillColor(rint(ch.getInt()))

    roi = omero.model.RoiI()
    roi.addShape(mask)
    return roi
Ejemplo n.º 10
0
def label():
    o = LabelI()
    populate_shape(o)
    o.x = rdouble(1.0)
    o.y = rdouble(2.0)
    o.id = rlong(7L)
    return o
Ejemplo n.º 11
0
 def __init__(self, roicoord=ROICoordinate(), cx=0, cy=0, rx=0, ry=0):
     ShapeData.__init__(self)
     self.cx = rdouble(cx)
     self.cy = rdouble(cy)
     self.rx = rdouble(rx)
     self.ry = rdouble(ry)
     self.setCoord(roicoord)
Ejemplo n.º 12
0
 def __init__(self, roicoord = ROICoordinate(), cx = 0, cy = 0, rx = 0, ry = 0):
     ShapeData.__init__(self);
     self.cx = rdouble(cx);
     self.cy = rdouble(cy);
     self.rx = rdouble(rx);
     self.ry = rdouble(ry);
     self.setCoord(roicoord);
Ejemplo n.º 13
0
def opt_unit_label():
    o = LabelI()
    populate_shape(o, False)
    o.x = rdouble(1.0)
    o.y = rdouble(2.0)
    o.id = rlong(7L)
    return o
Ejemplo n.º 14
0
 def __init__(self, roicoord = ROICoordinate(), x = 0, y = 0, width = 0, height = 0):
     ShapeData.__init__(self);
     self.x = rdouble(x);
     self.y = rdouble(y);
     self.width = rdouble(width);
     self.height = rdouble(height);
     self.setCoord(roicoord);
Ejemplo n.º 15
0
def point():
    o = PointI()
    populate_shape(o)
    o.cx = rdouble(1.0)
    o.cy = rdouble(2.0)
    o.id = rlong(3L)
    return o
Ejemplo n.º 16
0
 def __init__(self, roicoord = ROICoordinate(), x1 = 0, y1 = 0, x2 = 0, y2 = 0):
     ShapeData.__init__(self);
     self.x1 = rdouble(x1);
     self.y1 = rdouble(y1);
     self.x2 = rdouble(x2);
     self.y2 = rdouble(y2);
     self.setCoord(roicoord);
Ejemplo n.º 17
0
def label():
    o = LabelI()
    populate_shape(o)
    o.x = rdouble(1.0)
    o.y = rdouble(2.0)
    o.id = rlong(7L)
    return o
Ejemplo n.º 18
0
def create_shape_point(x_pos,
                       y_pos,
                       z_pos=None,
                       c_pos=None,
                       t_pos=None,
                       name=None,
                       stroke_color=(255, 255, 255, 255),
                       fill_color=(10, 10, 10, 20),
                       stroke_width=1):
    point = model.PointI()
    point.x = rtypes.rdouble(x_pos)
    point.y = rtypes.rdouble(y_pos)
    if z_pos is not None:
        point.theZ = rtypes.rint(z_pos)
    if c_pos is not None:
        point.theC = rtypes.rint(c_pos)
    if t_pos is not None:
        point.theT = rtypes.rint(t_pos)
    _set_shape_properties(shape=point,
                          name=name,
                          stroke_color=stroke_color,
                          stroke_width=stroke_width,
                          fill_color=fill_color)

    return point
Ejemplo n.º 19
0
 def __init__(self, roicoord = ROICoordinate(), bytes = None, x = 0, y = 0, width = 0, height = 0):
     ShapeData.__init__(self);
     self.x = rdouble(x);
     self.y = rdouble(y);
     self.width = rdouble(width);
     self.height = rdouble(height);
     self.bytesdata = bytes;
     self.setCoord(roicoord);
Ejemplo n.º 20
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 create_roi(im, x, y, t):
    p = omero.model.PointI()
    p.setTheT(rint(t))
    p.setCx(rdouble(x))
    p.setCy(rdouble(y))
    roi = omero.model.RoiI()
    roi.addShape(p)
    roi.setImage(im)
    return roi
Ejemplo n.º 22
0
def ellipse():
    o = EllipseI()
    populate_shape(o)
    o.cx = rdouble(1.0)
    o.cy = rdouble(2.0)
    o.rx = rdouble(3.0)
    o.ry = rdouble(4.0)
    o.id = rlong(1L)
    return o
Ejemplo n.º 23
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
Ejemplo n.º 24
0
def rectangle():
    o = RectangleI()
    populate_shape(o)
    o.x = rdouble(1.0)
    o.y = rdouble(2.0)
    o.width = rdouble(3.0)
    o.height = rdouble(4.0)
    o.id = rlong(2L)
    return o
Ejemplo n.º 25
0
def create_shape_point(x_pos, y_pos, z_pos, t_pos, point_name=None):
    point = model.PointI()
    point.x = rtypes.rdouble(x_pos)
    point.y = rtypes.rdouble(y_pos)
    point.theZ = rtypes.rint(z_pos)
    point.theT = rtypes.rint(t_pos)
    _set_shape_properties(point, name=point_name)

    return point
Ejemplo n.º 26
0
 def __init__(self, roicoord=ROICoordinate(), x1=0, y1=0, x2=0, y2=0):
     warnings.warn("This module is deprecated as of OMERO 5.3.0",
                   DeprecationWarning)
     ShapeData.__init__(self)
     self.x1 = rdouble(x1)
     self.y1 = rdouble(y1)
     self.x2 = rdouble(x2)
     self.y2 = rdouble(y2)
     self.setCoord(roicoord)
Ejemplo n.º 27
0
 def __init__(self, roicoord=ROICoordinate(), bytes=None,
              x=0, y=0, width=0, height=0):
     ShapeData.__init__(self)
     self.x = rdouble(x)
     self.y = rdouble(y)
     self.width = rdouble(width)
     self.height = rdouble(height)
     self.bytesdata = bytes
     self.setCoord(roicoord)
Ejemplo n.º 28
0
def rectangle():
    o = RectangleI()
    populate_shape(o)
    o.x = rdouble(1.0)
    o.y = rdouble(2.0)
    o.width = rdouble(3.0)
    o.height = rdouble(4.0)
    o.id = rlong(2L)
    return o
Ejemplo n.º 29
0
def ellipse():
    o = EllipseI()
    populate_shape(o)
    o.cx = rdouble(1.0)
    o.cy = rdouble(2.0)
    o.rx = rdouble(3.0)
    o.ry = rdouble(4.0)
    o.id = rlong(1L)
    return o
Ejemplo n.º 30
0
def rectangle(identity_transform):
    o = RectangleI()
    populate_shape(o, identity_transform)
    o.x = rdouble(1.0)
    o.y = rdouble(2.0)
    o.width = rdouble(3.0)
    o.height = rdouble(4.0)
    o.id = rlong(2)
    return o
Ejemplo n.º 31
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
Ejemplo n.º 32
0
 def create_roi(self, img):
     roi = omero.model.RoiI()
     point = omero.model.PointI()
     point.setCx(rdouble(1))
     point.setCy(rdouble(2))
     roi.addShape(point)
     roi.setImage(img)
     roi = self.client.getSession().getUpdateService().saveAndReturnObject(
         roi)
     return roi
Ejemplo n.º 33
0
def ellipse_with_annotations():
    o = EllipseI()
    populate_shape(o)
    add_annotations(o)
    o.cx = rdouble(1.0)
    o.cy = rdouble(2.0)
    o.rx = rdouble(3.0)
    o.ry = rdouble(4.0)
    o.id = rlong(1L)
    return o
Ejemplo n.º 34
0
def ellipse_with_annotations():
    o = EllipseI()
    populate_shape(o)
    add_annotations(o)
    o.cx = rdouble(1.0)
    o.cy = rdouble(2.0)
    o.rx = rdouble(3.0)
    o.ry = rdouble(4.0)
    o.id = rlong(1L)
    return o
Ejemplo n.º 35
0
 def create_roi(self, img):
     roi = omero.model.RoiI()
     point = omero.model.PointI()
     point.setX(rdouble(1))
     point.setY(rdouble(2))
     roi.addShape(point)
     roi.setImage(img)
     roi = self.client.getSession().getUpdateService().saveAndReturnObject(
         roi)
     return roi
Ejemplo n.º 36
0
def basic_line(default_id):
    shape = omero.model.LineI()
    shape.id = rlong(default_id)
    shape.x1 = rdouble(0.0)
    shape.y1 = rdouble(1.0)
    shape.x2 = rdouble(2.0)
    shape.y2 = rdouble(3.0)
    # r=17,g=34,b=51,a=255
    shape.strokeColor = rint(ctypes.c_int(0x112233FF).value)
    return shape
Ejemplo n.º 37
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
Ejemplo n.º 38
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
Ejemplo n.º 39
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
Ejemplo n.º 40
0
    def test_objective_settings(self):

        iid = self.create_test_image(size_c=2, session=self.sf).id.val
        conn = omero.gateway.BlitzGateway(client_obj=self.client)
        image = conn.getObject("Image", iid)

        # Create Objective
        update = conn.getUpdateService()
        objective = omero.model.ObjectiveI()
        objective.model = rstring("SuperZoom ABC")
        objective.manufacturer = rstring("ImageCo")
        objective.lensNA = rdouble(1.4)
        objective.nominalMagnification = rdouble(100)
        objective.calibratedMagnification = rdouble(100.1)
        objective.lotNumber = rstring("123")
        objective.serialNumber = rstring("abcdefX")
        objective.iris = rbool(True)

        immersions = list(conn.getEnumerationEntries("ImmersionI"))
        corrections = list(conn.getEnumerationEntries("CorrectionI"))
        objective.correction = corrections[0]._obj
        objective.immersion = immersions[0]._obj
        objective.instrument = update.saveAndReturnObject(
            omero.model.InstrumentI())
        objective = update.saveAndReturnObject(objective)

        settings = omero.model.ObjectiveSettingsI()
        settings.objective = objective
        settings = update.saveAndReturnObject(settings)

        image._obj.objectiveSettings = settings
        update.saveAndReturnObject(image._obj)

        # reload...
        image = conn.getObject("Image", iid)
        json_data = acquisitionMetadataMarshal(image)
        print(json_data)
        assert json_data["objectiveSettings"] == {
            "id": settings.id.val,
            "objective": {
                "id": objective.id.val,
                "model": "SuperZoom ABC",
                "manufacturer": "ImageCo",
                "lensNA": 1.4,
                "nominalMagnification": 100,
                "calibratedMagnification": 100.1,
                "lotNumber": "123",
                "serialNumber": "abcdefX",
                "immersion": immersions[0].value,
                "correction": corrections[0].value,
                "iris": True
            }
        }
Ejemplo n.º 41
0
def basic_ellipse(default_id):
    shape = omero.model.EllipseI()
    shape.id = rlong(default_id)
    shape.x = rdouble(0.0)
    shape.y = rdouble(.1)
    shape.radiusX = rdouble(1.0)
    shape.radiusY = rdouble(.5)
    # r=17,g=34,b=51,a=68
    shape.fillColor = rint(ctypes.c_int(0x11223344).value)
    # r=255,g=254,b=253,a=252 (i.e. negative int value = -66052)
    shape.strokeColor = rint(ctypes.c_int(0xfffefdfc).value)
    return shape
Ejemplo n.º 42
0
    def addRoi(self, request, imageid):
        img = self.getImage0(imageid)
        if img is None:
            return None

        data = json.loads(request.body)
        shapes = data['shapes']
        x = y = l = z = t = -1
        for s in shapes:
            for k in s:
                val = s[k]
                if k == "x":
                    x = int(val)
                elif k == "y":
                    y = int(val)
                elif k == "width":
                    l = int(val)
                elif k == "theZ":
                    z = int(val)
                elif k == "theT":
                    t = int(val)
                elif k == "fillColorAsInt":
                    fill = int(val)
                elif k == "strokeColorAsInt":
                    stroke = int(val)
                elif k == "strokeWidth":
                    strokeWidth = int(val)

        if (x < 0 or y < 0 or z < 0 or t < 0 or l <= 0):
            return None

        updateService = self._connection.getUpdateService()
        roi = RoiI()
        roi.setImage(img._obj)
        rect = RectangleI()
        rect.x = rdouble(x)
        rect.y = rdouble(y)
        rect.width = rdouble(l)
        rect.height = rdouble(l)
        rect.theZ = rint(z)
        rect.theT = rint(t)
        rect.setFillColor(rint(fill))
        strokeLen = LengthI()
        strokeLen.setValue(strokeWidth)
        strokeLen.setUnit(UnitsLength.PIXEL)
        rect.setStrokeWidth(strokeLen)
        rect.setStrokeColor(rint(stroke))
        roi.addShape(rect)

        if (updateService.saveAndReturnObject(roi) is None):
            return None
        return self.get_rois(imageid)
Ejemplo n.º 43
0
    def addRoi(self, request, imageid):
        img = self.getImage0(imageid)
        if img is None:
            return None

        data = json.loads(request.body)
        shapes = data['shapes']
        x = y = l = z = t = -1
        for s in shapes:
            for k in s:
                val = s[k]
                if k == "x":
                    x = int(val)
                elif k == "y":
                    y = int(val)
                elif k == "width":
                    l = int(val)
                elif k == "theZ":
                    z = int(val)
                elif k == "theT":
                    t = int(val)
                elif k == "fillColorAsInt":
                    fill = int(val)
                elif k == "strokeColorAsInt":
                    stroke = int(val)
                elif k == "strokeWidth":
                    strokeWidth = int(val)
        
        if (x < 0 or y < 0 or z < 0 or t < 0 or l <= 0):
            return None
        
        updateService = self._connection.getUpdateService()
        roi = RoiI()
        roi.setImage(img._obj)
        rect = RectangleI()
        rect.x = rdouble(x)
        rect.y = rdouble(y)
        rect.width = rdouble(l)
        rect.height = rdouble(l)
        rect.theZ = rint(z)
        rect.theT = rint(t)
        rect.setFillColor(rint(fill))
        strokeLen = LengthI()
        strokeLen.setValue(strokeWidth)
        strokeLen.setUnit(UnitsLength.PIXEL)
        rect.setStrokeWidth(strokeLen)
        rect.setStrokeColor(rint(stroke))
        roi.addShape(rect)
        
        if (updateService.saveAndReturnObject(roi) is None):
            return None
        return self.get_rois(imageid) 
Ejemplo n.º 44
0
def create_shape_line(x1_pos, y1_pos, x2_pos, y2_pos, z_pos, t_pos,
                      line_name=None, stroke_color=(255, 255, 255, 255), stroke_width=1):
    line = model.LineI()
    line.x1 = rtypes.rdouble(x1_pos)
    line.x2 = rtypes.rdouble(x2_pos)
    line.y1 = rtypes.rdouble(y1_pos)
    line.y2 = rtypes.rdouble(y2_pos)
    line.theZ = rtypes.rint(z_pos)
    line.theT = rtypes.rint(t_pos)
    _set_shape_properties(line, name=line_name,
                          stroke_color=stroke_color,
                          stroke_width=stroke_width)
    return line
Ejemplo n.º 45
0
def create_roi(img, x, y, t, text=None):
    roi = omero.model.RoiI()
    roi.setImage(img._obj)
    rect = omero.model.RectangleI()
    rect.x = rdouble(x)
    rect.y = rdouble(y)
    rect.width = rdouble(W)
    rect.height = rdouble(H)
    if text:
        rect.textValue = rstring(text)
    rect.theZ = rint(0)
    rect.theT = rint(t)
    roi.addShape(rect)
    return roi
Ejemplo n.º 46
0
def addRect(roi, x=10, y=10, w=100, h=50, theZ=0, theT=0, label=None):
    """ create and save a rectangle shape, add it to roi """
    rect = omero.model.RectI()
    rect.x = rdouble(x)
    rect.y = rdouble(y)
    rect.width = rdouble(w)
    rect.height = rdouble(h)
    if theZ is not None:
        rect.theZ = rint(theZ)
    if theT is not None:
        rect.theT = rint(theT)
    if label is not None:
        rect.textValue = wrap(label)
    rect.setRoi(roi)
    roi.addShape(rect)
Ejemplo n.º 47
0
 def testGetAttrWorks(self):
     rbool(True).val
     rdouble(0.0).val
     rfloat(0.0).val
     rint(0).val
     rlong(0).val
     rtime(0).val
     rinternal(None).val
     robject(None).val
     rstring("").val
     rclass("").val
     rarray().val
     rlist().val
     rset().val
     rmap().val
def to_rois(cx_column, cy_column, pixels):
    unloaded_image = ImageI(pixels.image.id, False)
    rois = list()
    for index in range(len(cx_column.values)):
        cx = rdouble(cx_column.values[index])
        cy = rdouble(cy_column.values[index])
        roi = RoiI()
        shape = PointI()
        shape.theZ = rint(0)
        shape.theT = rint(0)
        shape.cx = cx
        shape.cy = cy
        roi.addShape(shape)
        roi.image = unloaded_image
        rois.append(roi)
    return rois
Ejemplo n.º 49
0
def ellipse():
    o = EllipseI()
    populate_shape(o)
    if SCHEMA_VERSION == "2015-01":
        o.cx = rdouble(1.0)
        o.cy = rdouble(2.0)
        o.rx = rdouble(3.0)
        o.ry = rdouble(4.0)
    else:
        o.x = rdouble(1.0)
        o.y = rdouble(2.0)
        o.radiusX = rdouble(3.0)
        o.radiusY = rdouble(4.0)
    o.id = rlong(1L)
    return o
Ejemplo n.º 50
0
 def decode(self, data):
     t = super(AffineTransform201501Decoder, self).decode(data)
     t.setA00(rdouble(data['A00']))
     t.setA10(rdouble(data['A10']))
     t.setA01(rdouble(data['A01']))
     t.setA11(rdouble(data['A11']))
     t.setA02(rdouble(data['A02']))
     t.setA12(rdouble(data['A12']))
     return t
Ejemplo n.º 51
0
def create_roi_for_plane(session, iid, z, c, t, robject=False):
    """
    Create a ROI consisting of an entire single plane

    :param session: An active session
    :param iid: Image ID
    :param z: Z index
    :param c: C index
    :param t: T index
    :param robject: If true return the ROI object, default is to return the ID
    :return: The new ROI
    """
    qs = session.getQueryService()
    us = session.getUpdateService()
    p = omero.sys.ParametersI()
    p.addId(iid)
    im = qs.findByQuery('FROM Image i join fetch i.pixels where i.id=:id', p)
    assert im
    px = im.getPrimaryPixels()

    rect = omero.model.RectI()
    rect.setX(rdouble(0))
    rect.setY(rdouble(0))
    rect.setWidth(rdouble(px.getSizeX().val))
    rect.setHeight(rdouble(px.getSizeY().val))
    rect.setTheZ(rint(z))
    rect.setTheC(rint(c))
    rect.setTheT(rint(t))

    roi = omero.model.RoiI()
    roi.addShape(rect)
    roi.setImage(im)

    roi = us.saveAndReturnObject(roi)
    if robject:
        return roi
    return roi.getId().val
def create_affine_transform(a00, a10, a01, a11, a02, a12):
    t = AffineTransformI()
    t.setA00(rdouble(a00))
    t.setA10(rdouble(a10))
    t.setA01(rdouble(a01))
    t.setA11(rdouble(a11))
    t.setA02(rdouble(a02))
    t.setA12(rdouble(a12))
    return t
Ejemplo n.º 53
0
    def parse(self):
        provider = self.original_file_provider
        data = provider.get_original_file_data(self.original_file)
        try:
            rows = list(csv.reader(data, delimiter=","))
        finally:
            data.close()

        columns = [
            ImageColumn("Image", "", list()),
            RoiColumn("ROI", "", list()),
            StringColumn("Type", "", 12, list()),
        ]

        for row in rows[1:]:
            wellnumber = self.well_name_to_number(row[0])
            image = self.analysis_ctx.\
                image_from_wellnumber(wellnumber)
            #  TODO: what to do with the field?!
            #  field = int(row[1])
            #  image = images[field]
            roi = RoiI()
            shape = PointI()
            shape.cx = rdouble(float(row[2]))
            shape.cy = rdouble(float(row[3]))
            shape.textValue = rstring(row[4])
            roi.addShape(shape)
            roi.image = image.proxy()
            rid = self.update_service\
                .saveAndReturnIds([roi])[0]

            columns[0].values.append(image.id.val)
            columns[1].values.append(rid)
            columns[2].values.append(row[4])

        return MeasurementParsingResult([columns])
Ejemplo n.º 54
0
def identity_transform():
    t = AffineTransformI()
    if SCHEMA_VERSION == "2015-01":
        t.convert_svg_transform("matrix(1 0 0 1 0 0)")
    else:
        t.setA00(rdouble(1))
        t.setA10(rdouble(0))
        t.setA01(rdouble(0))
        t.setA11(rdouble(1))
        t.setA02(rdouble(0))
        t.setA12(rdouble(0))
        t.id = rlong(8L)
    return t
Ejemplo n.º 55
0
def translation_transform():
    t = AffineTransformI()
    if SCHEMA_VERSION == "2015-01":
        t.convert_svg_transform("translate(3 4)")
    else:
        t.setA00(rdouble(1))
        t.setA10(rdouble(0))
        t.setA01(rdouble(0))
        t.setA11(rdouble(1))
        t.setA02(rdouble(3))
        t.setA12(rdouble(4))
        t.id = rlong(8L)
    return t
Ejemplo n.º 56
0
def rotation_transform():
    t = AffineTransformI()
    if SCHEMA_VERSION == "2015-01":
        t.convert_svg_transform("rotate(45 50 100)")
    else:
        t.setA00(rdouble(0.7071067811865476))
        t.setA10(rdouble(0.7071067811865475))
        t.setA01(rdouble(-0.7071067811865475))
        t.setA11(rdouble(0.7071067811865476))
        t.setA02(rdouble(85.35533905932736))
        t.setA12(rdouble(-6.066017177982129))
        t.id = rlong(8L)
    return t
Ejemplo n.º 57
0
def scale_transform():
    t = AffineTransformI()
    if SCHEMA_VERSION == "2015-01":
        t.convert_svg_transform("scale(1.5 2.5)")
    else:
        t.setA00(rdouble(1.5))
        t.setA10(rdouble(0))
        t.setA01(rdouble(0))
        t.setA11(rdouble(2.5))
        t.setA02(rdouble(0))
        t.setA12(rdouble(0))
        t.id = rlong(8L)
    return t
Ejemplo n.º 58
0
    def test_find_rois_for_plane(self, projection):
        def getIds(objs, robject=True):
            if robject:
                return sorted(unwrap(o.getId()) for o in objs)
            return sorted(objs)

        im = self.create_image()
        iid = unwrap(im.getId())

        r1 = utils.create_roi_for_plane(
            self.sess, unwrap(im.getId()), 2, 3, 4, robject=True)
        r2 = utils.create_roi_for_plane(
            self.sess, unwrap(im.getId()), 2, 4, 6, robject=True)

        r3 = utils.create_roi_for_plane(
            self.sess, unwrap(im.getId()), 2, 4, 8, robject=True)
        r3.getShape(0).setWidth(rdouble(1))
        r3 = self.sess.getUpdateService().saveAndReturnObject(r3)

        r4 = utils.create_roi_for_plane(
            self.sess, unwrap(im.getId()), 2, 4, 8, robject=True)
        r4.addShape(omero.model.RectI())
        r4 = self.sess.getUpdateService().saveAndReturnObject(r4)

        rs = utils.find_rois_for_plane(self.sess, iid=iid, z=1000)
        assert rs == []

        rs = utils.find_rois_for_plane(
            self.sess, iid=iid, fullplane=True, projection=projection)
        assert getIds(rs, not projection) == getIds([r1, r2])

        rs = utils.find_rois_for_plane(
            self.sess, iid=iid, singleshape=False, projection=projection)
        assert getIds(rs, not projection) == getIds([r1, r2, r4])

        rs = utils.find_rois_for_plane(
            self.sess, iid=iid, fullplane=False, projection=projection)
        assert getIds(rs, not projection) == getIds([r1, r2, r3])

        rs = utils.find_rois_for_plane(
            self.sess, iid=iid, c=4, fullplane=False, singleshape=False,
            projection=projection)
        assert getIds(rs, not projection) == getIds([r2, r3, r4])
Ejemplo n.º 59
0
 def parse_and_populate_roi(self, columns_as_list):
     # First sanity check our provided columns
     names = [column.name for column in columns_as_list]
     log.debug('Parsing columns: %r' % names)
     cells_expected = [name in names for name in self.CELLS_CG_EXPECTED]
     nuclei_expected = [name in names for name in self.NUCLEI_CG_EXPECTED]
     if (False in cells_expected) and (False in nuclei_expected):
         log.warn("Missing CGs for InCell dataset: %r" % names)
         log.warn('Removing resultant empty ROI column.')
         for column in columns_as_list:
             if RoiColumn == column.__class__:
                 columns_as_list.remove(column)
         return
     # Reconstruct a column name to column map
     columns = dict()
     for column in columns_as_list:
         columns[column.name] = column
     image_ids = columns['Image'].values
     rois = list()
     # Save our file annotation to the database so we can use an unloaded
     # annotation for the saveAndReturnIds that will be triggered below.
     self.file_annotation = \
         self.update_service.saveAndReturnObject(self.file_annotation)
     unloaded_file_annotation = \
         FileAnnotationI(self.file_annotation.id.val, False)
     # Parse and append ROI
     batch_no = 1
     batches = dict()
     for i, image_id in enumerate(image_ids):
         unloaded_image = ImageI(image_id, False)
         if False in nuclei_expected:
             # Cell centre of gravity
             roi = RoiI()
             shape = PointI()
             shape.theZ = rint(0)
             shape.theT = rint(0)
             shape.cx = rdouble(float(columns['Cell: cgX'].values[i]))
             shape.cy = rdouble(float(columns['Cell: cgY'].values[i]))
             roi.addShape(shape)
             roi.image = unloaded_image
             roi.linkAnnotation(unloaded_file_annotation)
             rois.append(roi)
         elif False in cells_expected:
             # Nucleus centre of gravity
             roi = RoiI()
             shape = PointI()
             shape.theZ = rint(0)
             shape.theT = rint(0)
             shape.cx = rdouble(float(columns['Nucleus: cgX'].values[i]))
             shape.cy = rdouble(float(columns['Nucleus: cgY'].values[i]))
             roi.addShape(shape)
             roi.image = unloaded_image
             roi.linkAnnotation(unloaded_file_annotation)
             rois.append(roi)
         else:
             raise MeasurementError('Not a nucleus or cell ROI')
         if len(rois) == self.ROI_UPDATE_LIMIT:
             thread_pool.add_task(self.update_rois, rois, batches, batch_no)
             rois = list()
             batch_no += 1
     thread_pool.add_task(self.update_rois, rois, batches, batch_no)
     thread_pool.wait_completion()
     batch_keys = batches.keys()
     batch_keys.sort()
     for k in batch_keys:
         columns['ROI'].values += batches[k]
Ejemplo n.º 60
0
def create_image(image_id, with_pixels=False):
    image_format = FormatI(1L)
    image_format.value = rstring("PNG")

    image = ImageI()
    image.id = rlong(image_id)
    image.acquisitionDate = rtime(1L)
    image.archived = rbool(False)
    image.description = rstring("image_description_%d" % image_id)
    image.name = rstring("image_name_%d" % image_id)
    image.partial = rbool(False)
    image.series = rint(0)
    image.format = image_format
    if not with_pixels:
        return image
    dimension_order = DimensionOrderI(1L)
    dimension_order.value = rstring("XYZCT")
    pixels_type = PixelsTypeI(1L)
    pixels_type.value = "bit"

    pixels = PixelsI(1L)
    pixels.methodology = rstring("methodology")
    pixels.physicalSizeX = LengthI(1.0, UnitsLength.MICROMETER)
    pixels.physicalSizeY = LengthI(2.0, UnitsLength.MICROMETER)
    pixels.physicalSizeZ = LengthI(3.0, UnitsLength.MICROMETER)
    pixels.sha1 = rstring("61ee8b5601a84d5154387578466c8998848ba089")
    pixels.significantBits = rint(16)
    pixels.sizeX = rint(1)
    pixels.sizeY = rint(2)
    pixels.sizeZ = rint(3)
    pixels.sizeC = rint(4)
    pixels.sizeT = rint(5)
    pixels.timeIncrement = TimeI(1.0, UnitsTime.MILLISECOND)
    pixels.waveIncrement = rdouble(2.0)
    pixels.waveStart = rint(1)
    pixels.dimensionOrder = dimension_order
    pixels.pixelsType = pixels_type
    image.addPixels(pixels)

    contrast_method = ContrastMethodI(8L)
    contrast_method.value = rstring("Fluorescence")
    illumination = IlluminationI(1L)
    illumination.value = rstring("Transmitted")
    acquisition_mode = AcquisitionModeI(1L)
    acquisition_mode.value = rstring("WideField")
    photometric_interpretation = PhotometricInterpretationI(1L)
    photometric_interpretation.value = rstring("RGB")

    channel_1 = ChannelI(1L)
    channel_1.alpha = rint(255)
    channel_1.blue = rint(0)
    channel_1.green = rint(255)
    channel_1.red = rint(0)
    channel_1.lookupTable = rstring("rainbow")
    logical_channel_1 = LogicalChannelI(1L)
    logical_channel_1.emissionWave = LengthI(509.0, UnitsLength.NANOMETER)
    logical_channel_1.excitationWave = LengthI(488.0, UnitsLength.NANOMETER)
    logical_channel_1.fluor = rstring("GFP")
    logical_channel_1.name = rstring("GFP/488")
    logical_channel_1.ndFilter = rdouble(1.0)
    logical_channel_1.pinHoleSize = LengthI(1.0, UnitsLength.NANOMETER)
    logical_channel_1.pockelCellSetting = rint(0)
    logical_channel_1.samplesPerPixel = rint(2)
    logical_channel_1.contrastMethod = contrast_method
    logical_channel_1.illumination = illumination
    logical_channel_1.mode = acquisition_mode
    logical_channel_1.photometricInterpretation = photometric_interpretation
    channel_1.logicalChannel = logical_channel_1

    channel_2 = ChannelI(2L)
    channel_2.alpha = rint(255)
    channel_2.blue = rint(255)
    channel_2.green = rint(0)
    channel_2.red = rint(0)
    channel_2.lookupTable = rstring("rainbow")
    logical_channel_2 = LogicalChannelI(2L)
    logical_channel_2.emissionWave = LengthI(470.0, UnitsLength.NANOMETER)
    logical_channel_2.excitationWave = LengthI(405.0, UnitsLength.NANOMETER)
    logical_channel_2.fluor = rstring("DAPI")
    logical_channel_2.name = rstring("DAPI/405")
    logical_channel_2.ndFilter = rdouble(1.0)
    logical_channel_2.pinHoleSize = LengthI(2.0, UnitsLength.NANOMETER)
    logical_channel_2.pockelCellSetting = rint(0)
    logical_channel_2.samplesPerPixel = rint(2)
    logical_channel_2.contrastMethod = contrast_method
    logical_channel_2.illumination = illumination
    logical_channel_2.mode = acquisition_mode
    logical_channel_2.photometricInterpretation = photometric_interpretation
    channel_2.logicalChannel = logical_channel_2

    pixels.addChannel(channel_1)
    pixels.addChannel(channel_2)
    return image