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

Aleksandra Tarkowska (Staff) A.Tarkowska at dundee.ac.uk
Thu Aug 27 15:34:04 BST 2015


Sorry I forgot to metntion, if you wish to improve our codebase please follow https://github.com/openmicroscopy/openmicroscopy/blob/develop/CONTRIBUTING.md

Kind regards
Ola

From: Aleksandra Tarkowska <a.tarkowska at dundee.ac.uk<mailto:a.tarkowska at dundee.ac.uk>>
Reply-To: OME External Developer List <ome-devel at lists.openmicroscopy.org.uk<mailto:ome-devel at lists.openmicroscopy.org.uk>>
Date: Thu, 27 Aug 2015 14:27:35 +0000
To: OME External Developer List <ome-devel at lists.openmicroscopy.org.uk<mailto:ome-devel at lists.openmicroscopy.org.uk>>
Subject: Re: [ome-devel] Request for functionality on OMERO WebGateway in version 5.1.4

Hi José,

Thanks for your email.

I am not sure if I follow it correctly but as far as I can see webgateway.views.render_image_region already support quality.

https://server/webgateway/render_image_region/IMAGE_ID/PLANE_ID/0/?q=0.5&region=x,y,w,h

see: https://github.com/openmicroscopy/openmicroscopy/blob/dev_5_1/components/tools/OmeroWeb/omeroweb/webgateway/views.py#L742
and https://github.com/openmicroscopy/openmicroscopy/blob/dev_5_1/components/tools/OmeroWeb/omeroweb/webgateway/views.py#L775

Although it is true that quality is not taken to the account in webgateway_cache.

Thanks for letting us know. I have created ticket to fix webgateway_cache in https://trac.openmicroscopy.org/ome/ticket/13011


Kind regards
Ola

From: José Salavert Torres <josator at ebi.ac.uk<mailto:josator at ebi.ac.uk>>
Reply-To: OME External Developer List <ome-devel at lists.openmicroscopy.org.uk<mailto:ome-devel at lists.openmicroscopy.org.uk>>
Date: Thu, 27 Aug 2015 14:46:53 +0100
To: OME External Developer List <ome-devel at lists.openmicroscopy.org.uk<mailto:ome-devel at lists.openmicroscopy.org.uk>>
Subject: [ome-devel] Request for functionality on OMERO WebGateway in version 5.1.4

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


_______________________________________________ ome-devel mailing list ome-devel at lists.openmicroscopy.org.uk<mailto:ome-devel at lists.openmicroscopy.org.uk> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel
The University of Dundee is a registered Scottish Charity, No: SC015096
_______________________________________________ ome-devel mailing list ome-devel at lists.openmicroscopy.org.uk<mailto:ome-devel at lists.openmicroscopy.org.uk> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel
The University of Dundee is a registered Scottish Charity, No: SC015096
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openmicroscopy.org.uk/pipermail/ome-devel/attachments/20150827/37015c48/attachment.html>


More information about the ome-devel mailing list