Пример #1
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]
Пример #2
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
Пример #3
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]
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 _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]
 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]
Пример #7
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]