コード例 #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
コード例 #2
0
def point():
    o = PointI()
    populate_shape(o)
    o.cx = rdouble(1.0)
    o.cy = rdouble(2.0)
    o.id = rlong(3L)
    return o
コード例 #3
0
ファイル: populate_roi.py プロジェクト: hflynn/openmicroscopy
 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]
コード例 #4
0
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
コード例 #5
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
コード例 #6
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)
        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]
コード例 #7
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]
コード例 #8
0
ファイル: conftest.py プロジェクト: ome/omero-marshal
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
コード例 #9
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
コード例 #10
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])
コード例 #11
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])
コード例 #12
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
コード例 #13
0
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
コード例 #14
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)
コード例 #15
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]
コード例 #16
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:
             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['ROI'].values += batches[k]
コード例 #17
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]
コード例 #18
0
    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
コード例 #19
0
 def createBaseType(self):
     return PointI()
コード例 #20
0
 def createBaseType(self):
     warnings.warn("This module is deprecated as of OMERO 5.3.0",
                   DeprecationWarning)
     return PointI()