[ome-devel] Request for functionality on OMERO WebGateway in version 5.1.4

José Salavert Torres josator at ebi.ac.uk
Thu Aug 27 14:46:53 BST 2015


Dear all,

We requested in a meeting some time ago in a meeting a new functionality in the render_image_region on the web gateway of omero web.

Concretely we want to have the possibility to select the quality of the jpeg sent by the server. This is the code we currently added to achieve that:

On web gateway openmicroscopy/components/tools/OmeroWeb/omeroweb/webgateway/urls.py file:

render_image_region_quality = ( r'^render_image_region_quality/(?P<iid>[^/]+)/(?P<z>[^/]+)/(?P<t>[^/]+)/(?P<q>[^/]+)/$',
                                                     'webgateway.views.render_image_region_quality')
"""
Returns a jpeg of the OMERO image, rendering only a region specified in query string as
region=x,y,width,height. E.g. region=0,512,256,256. If the image is much bigger than the
indicated baseline size, it is resized with Pillow. See L{views.render_image_region_quality}. 
Rendering settings can be specified in the request parameters.
Params in render_image/<iid>/<z>/<t>/<q>/ are:
- iid: Image ID
- z: Z index
- t: T index
- q: JPEG quality of the returned image
“”"

On web gateway openmicroscopy/components/tools/OmeroWeb/omeroweb/webgateway/views.py file (notice the small differences with the original render_image_region call, we add the quality in the ctx parameter of the web gateway_cache and the value of float(q) / 100.0 in the compression parameter of the renderJpegRegion function):

@login_required()
def render_image_region_quality(request, iid, z, t, q, conn=None, **kwargs):
    """
    Returns a jpeg of the OMERO image, rendering only a region specified in query string as
    region=x,y,width,height and resizing it. E.g. region=0,512,256,256
    Rendering settings can be specified in the request parameters.

    @param request:     http request
    @param iid:         image ID
    @param z:           Z index
    @param t:           T index
    @param q:           Jpeg compression quality
    @param conn:        L{omero.gateway.BlitzGateway} connection
    @return:            http response wrapping jpeg
    """
    server_id = request.session['connector'].server_id
    # if the region=x,y,w,h is not parsed correctly to give 4 ints then we simply provide whole image plane.
    # alternatively, could return a 404?
    #if h == None:
    #    return render_image (request, iid, z, t, server_id=None, _conn=None, **kwargs)
    pi = _get_prepared_image(request, iid, server_id=server_id, conn=conn)

    if pi is None:
        raise Http404
    img, compress_quality = pi

    tile = request.REQUEST.get('tile', None)
    region = request.REQUEST.get('region', None)
    level = None

    if tile:
        try:
            img._prepareRenderingEngine()
            w, h = img._re.getTileSize()
            levels = img._re.getResolutionLevels() - 1

            zxyt = tile.split(",")
            #w = int(zxyt[3])
            #h = int(zxyt[4])
            level = levels-int(zxyt[0])

            x = int(zxyt[1])*w
            y = int(zxyt[2])*h
        except:
            logger.debug("render_image_region_quality: tile=%s" % tile)
            logger.debug(traceback.format_exc())
            
    elif region:
        try:
            xywh = region.split(",")

            x = int(xywh[0])
            y = int(xywh[1])
            w = int(xywh[2])
            h = int(xywh[3])
        except:
            logger.debug("render_image_region_quality: region=%s" % region)
            logger.debug(traceback.format_exc())

    # region details and quality in request are used as key for caching.
    jpeg_data = webgateway_cache.getImage(request, server_id, img, z, t, ctx=q)
    jpeg_quality = float(q) / 100.0
    if jpeg_data is None:
        """
        jpeg_data_orig = img.renderJpegRegion(z,t,x,y,w,h,level=level, compression=jpeg_quality)
        pillow_img = Image.open(StringIO(jpeg_data_orig))
        pillow_img = pillow_img.convert(mode="L")
        rv = StringIO()
        pillow_img.save(rv, 'jpeg', quality=int(10))
        jpeg_data = rv.getvalue()
        """
        jpeg_data = img.renderJpegRegion(z,t,x,y,w,h,level=level, compression=jpeg_quality)
        if jpeg_data is None:
            raise Http404
        webgateway_cache.setImage(request, server_id, img, z, t, jpeg_data, ctx=q)

    rsp = HttpResponse(jpeg_data, content_type='image/jpeg')
    return rsp


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openmicroscopy.org.uk/pipermail/ome-devel/attachments/20150827/997080cb/attachment.html>


More information about the ome-devel mailing list