Example #1
0
def get_polygons_from_rois(conn, image):
    """ 
    Returns a list of (x, y, width, height), one for each ROI with rectangle shape

    @param conn:        BlitzGateway connection
    @param imageId:     Image ID
    """

    # Using the underlying ROI service & omero.model objects (no ROI support in Blitz Gateway yet)
    roiService = conn.getRoiService()
    imageId = image.getId()
    result = roiService.findByImage(imageId, None)
    updateService = conn.getUpdateService()
    polygons = []
    rects = []
    for roi in result.rois:
        # go through all the shapes of the ROI
        roi_id = roi.getId().getValue()
        for shape in roi.copyShapes():
            if shape.__class__.__name__ == 'PolygonI':
                poly = PolygonData(shape)
                rect = poly.getBoundingRectangle()
                points = poly.fromPoints("points")
                print 'points', type(points)
                print 'rect', rect
                x = rect[0][0]
                y = rect[0][1]
                w = rect[1][0] - rect[0][0]
                h = rect[1][1] - rect[0][1]
                rects.append((x, y, w, h, roi_id))
                polygons.append(poly)
                break

    return rects, polygons
def get_polygons_from_rois(conn, image):
    """ 
    Returns a list of (x, y, width, height), one for each ROI with rectangle shape

    @param conn:        BlitzGateway connection
    @param imageId:     Image ID
    """

    # Using the underlying ROI service & omero.model objects (no ROI support in Blitz Gateway yet)
    roiService = conn.getRoiService()
    imageId = image.getId()
    result = roiService.findByImage(imageId, None)
    updateService = conn.getUpdateService()
    polygons = []
    rects = []
    for roi in result.rois:
        # go through all the shapes of the ROI
        roi_id = roi.getId().getValue()
        for shape in roi.copyShapes():
            if shape.__class__.__name__ == 'PolygonI':
                poly = PolygonData(shape)
                rect = poly.getBoundingRectangle()
                points = poly.fromPoints("points")
                print 'points',type(points)
                print 'rect',rect
                x = rect[0][0]
                y = rect[0][1]
                w = rect[1][0] - rect[0][0]
                h = rect[1][1] - rect[0][1] 
                rects.append( (x,y,w,h,roi_id) )
                polygons.append(poly)
                break

    return rects,polygons
def get_rects_from_rois(conn, imageId):
    """ 
    Returns a list of (x, y, width, height), one for each ROI with rectangle shape

    @param conn:        BlitzGateway connection
    @param imageId:     Image ID
    """

    # Using the underlying ROI service & omero.model objects (no ROI support in Blitz Gateway yet)
    roiService = conn.getRoiService()
    result = roiService.findByImage(imageId, None)
    parent_image = conn.getObject("Image", imageId)
    sizeX = parent_image.getSizeX()
    sizeY = parent_image.getSizeY()
    print "image size x, y: ", sizeX, sizeY
    rects = []
    polygons = []
    for roi in result.rois:
        # go through all the shapes of the ROI
        roi_id = roi.getId().getValue()
        for shape in roi.copyShapes():
            name = shape.__class__.__name__
            if name == 'RectI':
                x = shape.getX().getValue(
                )  # Need getValue() for omero.model rtypes
                y = shape.getY().getValue()
                w = shape.getWidth().getValue()
                h = shape.getHeight().getValue()

                if x < 0:
                    x = 0
                if y < 0:
                    y = 0
                if x > sizeX:
                    x = sizeX
                if y > sizeY:
                    y = sizeY
                if (x + w) > sizeX:
                    w = sizeX - x
                if (y + h) > sizeY:
                    h = sizeY - y
                print "roi x, y, w, h: ", x, y, w, h
                rects.append((x, y, w, h, roi_id, name))
                break  # Only use the first Rect we find per ROI
            if name == 'PolygonI':
                poly = PolygonData(shape)
                rect = poly.getBoundingRectangle()
                x = rect[0][0]
                y = rect[0][1]
                w = rect[1][0] - rect[0][0]
                h = rect[1][1] - rect[0][1]

                if x < 0:
                    x = 0
                if y < 0:
                    y = 0
                if x > sizeX:
                    x = sizeX
                if y > sizeY:
                    y = sizeY
                if (x + w) > sizeX:
                    w = sizeX - x
                if (y + h) > sizeY:
                    h = sizeY - y
                print "roi x, y, w, h: ", x, y, w, h
                rects.append((x, y, w, h, roi_id, name))
                polygons.append(poly)
                break

    return rects, polygons
def get_rects_from_rois(conn, imageId):
    """ 
    Returns a list of (x, y, width, height), one for each ROI with rectangle shape

    @param conn:        BlitzGateway connection
    @param imageId:     Image ID
    """

    # Using the underlying ROI service & omero.model objects (no ROI support in Blitz Gateway yet)
    roiService = conn.getRoiService()
    result = roiService.findByImage(imageId, None)
    parent_image = conn.getObject("Image",imageId)
    sizeX = parent_image.getSizeX()
    sizeY = parent_image.getSizeY()
    print "image size x, y: ", sizeX,sizeY
    rects = []
    polygons = []
    for roi in result.rois:
        # go through all the shapes of the ROI
        roi_id = roi.getId().getValue()
        for shape in roi.copyShapes():
            name = shape.__class__.__name__
            if name == 'RectI':
                x = shape.getX().getValue()     # Need getValue() for omero.model rtypes
                y = shape.getY().getValue()
                w = shape.getWidth().getValue()
                h = shape.getHeight().getValue()
                
                if x < 0:
                    x = 0
                if y < 0:
                    y = 0
                if x > sizeX:
                    x = sizeX
                if y > sizeY:
                    y = sizeY
                if (x + w) > sizeX:
                    w = sizeX - x
                if (y + h) > sizeY:
                    h = sizeY - y
                print "roi x, y, w, h: ",x,y,w,h    
                rects.append( (x,y,w,h,roi_id,name) )
                break    # Only use the first Rect we find per ROI 
            if name == 'PolygonI':
                poly = PolygonData(shape)
                rect = poly.getBoundingRectangle()
                x = rect[0][0]
                y = rect[0][1]
                w = rect[1][0] - rect[0][0]
                h = rect[1][1] - rect[0][1] 
                
                if x < 0:
                    x = 0
                if y < 0:
                    y = 0
                if x > sizeX:
                    x = sizeX
                if y > sizeY:
                    y = sizeY
                if (x + w) > sizeX:
                    w = sizeX - x
                if (y + h) > sizeY:
                    h = sizeY - y
                print "roi x, y, w, h: ",x,y,w,h     
                rects.append( (x,y,w,h,roi_id,name) )
                polygons.append(poly)
                break         
                 
    return rects, polygons