ome / omero-web

Django-based OMERO.web client
https://www.openmicroscopy.org/omero
16 stars 29 forks source link

Apply inversion and quantization to proper channels #441

Closed kkoz closed 1 year ago

kkoz commented 1 year ago

Fixes #439. Refactors how inversions and quantizations are applied. In particular, pads out the quantizations so that if channels are missing from the c parameter, the corresponding channel has None as its quantization. Also, if the number of maps provided does not match the number of channels specified in c, a 400 is returned with an error message.

Testing

An IDR image is used here but any 3-channel image should work with the same query parameters. Similar to the issue, before the change the following URLs will yield different results, but with the change they should yield the same result: https://idr.openmicroscopy.org/webgateway/render_image_region/14000763/0/0/?m=c&z=1&t=1&format=jpeg&c=-1|C0:255$FF0000,2|C0:255$00FF00,3|C0:255$0000FF&tile=1,2,3,1024,1024&maps=[{},{%22inverted%22:{%22enabled%22:true},%22quantization%22:{%22family%22:%22polynomial%22,%22coefficient%22:1.9}},{}] https://idr.openmicroscopy.org/webgateway/render_image_region/14000763/0/0/?m=c&z=1&t=1&format=jpeg&c=2|C0:255$00FF00,3|C0:255$0000FF&tile=1,2,3,1024,1024&maps=[{%22inverted%22:{%22enabled%22:true},%22quantization%22:{%22family%22:%22polynomial%22,%22coefficient%22:1.9}},{}]

snoopycrimecop commented 1 year ago

Conflicting PR. Removed from build OMERO-python-superbuild-push#135. See the console output for more details. Possible conflicts:

--conflicts

jburel commented 1 year ago
omeroweb/webgateway/views.py:953:13: F821 undefined name 'log'
test/unit/test_webgateway.py:431:26: E712 comparison to True should be 'if cond is True:' or 'if cond:'
test/unit/test_webgateway.py:441:26: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
test/unit/test_webgateway.py:451:26: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
will-moore commented 1 year ago

In the sample URLs from the description, first request has:

c=-1,2,3
maps=[{},{"inverted":{"enabled":true},"quantization":{"family":"polynomial","coefficient":1.9}},{}]

2nd one has:

c=2,3
maps=[{"inverted":{"enabled":true},"quantization":{"family":"polynomial","coefficient":1.9}},{}]]

Testing locally now, these give identical rendering settings (quantization is applied to 2nd channel which is also inverted)

?c=2,3&maps=[{"inverted":{"enabled":true},"quantization":{"family":"polynomial","coefficient":1.9}},{}]
?c=-1,2,3&maps=[{},{"inverted":{"enabled":true},"quantization":{"family":"polynomial","coefficient":1.9}},{}]

However, this doesn't throw any errors as expected when c and maps are different lengths:

?c=2,3&maps=[{},{"inverted":{"enabled":true},"quantization":{"family":"polynomial","coefficient":1.9}},{}]

whereas if the maps is shorter than c:

?c=1,2,3&maps=[{"inverted":{"enabled":true},"quantization":{"family":"polynomial","coefficient":1.9}},{}]
?c=-1,2,3&maps=[{"inverted":{"enabled":true},"quantization":{"family":"polynomial","coefficient":1.9}},{}]

both give:

Traceback (most recent call last):
  File "/Users/wmoore/opt/anaconda3/envs/omeroweb/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/wmoore/opt/anaconda3/envs/omeroweb/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/wmoore/Desktop/WEB/omero-web/omeroweb/decorators.py", line 544, in wrapped
    retval = f(request, *args, **kwargs)
  File "/Users/wmoore/Desktop/WEB/omero-web/omeroweb/webgateway/views.py", line 1102, in render_image
    pi = _get_prepared_image(request, iid, server_id=server_id, conn=conn)
  File "/Users/wmoore/Desktop/WEB/omero-web/omeroweb/webgateway/views.py", line 917, in _get_prepared_image
    if not img.setActiveChannels(requestedChannels, windows, colors, invert_flags):
  File "/Users/wmoore/opt/anaconda3/envs/omeroweb/lib/python3.9/site-packages/omero/gateway/__init__.py", line 7955, in wrapped
    return f(self, *args, **kwargs)
  File "/Users/wmoore/opt/anaconda3/envs/omeroweb/lib/python3.9/site-packages/omero/gateway/__init__.py", line 8873, in setActiveChannels
    return self.set_active_channels(channels, windows, colors,
  File "/Users/wmoore/opt/anaconda3/envs/omeroweb/lib/python3.9/site-packages/omero/gateway/__init__.py", line 7955, in wrapped
    return f(self, *args, **kwargs)
  File "/Users/wmoore/opt/anaconda3/envs/omeroweb/lib/python3.9/site-packages/omero/gateway/__init__.py", line 8846, in set_active_channels
    invertMaps[idx] is not None):
snoopycrimecop commented 1 year ago

Conflicting PR. Removed from build OMERO-python-superbuild-push#136. See the console output for more details. Possible conflicts:

--conflicts

snoopycrimecop commented 1 year ago

Conflicting PR. Removed from build OMERO-python-superbuild-push#1344. See the console output for more details. Possible conflicts:

--conflicts

will-moore commented 1 year ago

Retesting URLs above, e.g. webclient/render_image/4472202/?c=2&maps=[{"inverted":{"enabled":true},"quantization":{"family":"polynomial","coefficient":1.9}},{}] now give the expected 400 error:

Must provide the same number of maps and channels or no maps

snoopycrimecop commented 1 year ago

Conflicting PR. Removed from build OMERO-python-superbuild-push#137. See the console output for more details. Possible conflicts:

--conflicts

snoopycrimecop commented 1 year ago

Conflicting PR. Removed from build OMERO-python-superbuild-push#138. See the console output for more details. Possible conflicts:

--conflicts Conflict resolved in build OMERO-python-superbuild-push#144. See the console output for more details.