Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better control dtype on multi sources. #993

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1866,11 +1866,14 @@ def getRegion(self, format=(TILE_FORMAT_IMAGE, ), **kwargs):
if tiled:
return self._encodeTiledImage(image, outWidth, outHeight, iterInfo, **kwargs)
if outWidth != regionWidth or outHeight != regionHeight:
dtype = image.dtype
image = _imageToPIL(image, mode).resize(
(outWidth, outHeight),
getattr(PIL.Image, 'Resampling', PIL.Image).BICUBIC
if outWidth > regionWidth else
getattr(PIL.Image, 'Resampling', PIL.Image).LANCZOS)
if dtype == numpy.uint16 and TILE_FORMAT_NUMPY in format:
image = _imageToNumpy(image)[0].astype(dtype) * 257
maxWidth = kwargs.get('output', {}).get('maxWidth')
maxHeight = kwargs.get('output', {}).get('maxHeight')
if kwargs.get('fill') and maxWidth and maxHeight:
Expand Down
34 changes: 30 additions & 4 deletions sources/multi/large_image_source_multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@
'type': 'integer',
'minimum': 0,
},
'zSet': {
'description': 'Override value for frame',
'type': 'integer',
'minimum': 0,
},
'tSet': {
'description': 'Override value for frame',
'type': 'integer',
'minimum': 0,
},
'xySet': {
'description': 'Override value for frame',
'type': 'integer',
'minimum': 0,
},
'cSet': {
'description': 'Override value for frame',
'type': 'integer',
'minimum': 0,
},
'zValues': {
'description':
'The numerical z position of the different z indices of the '
Expand All @@ -124,10 +144,10 @@
},
'xyValues': {
'description':
'The numerical zy position of the different zy indices of the '
'The numerical xy position of the different xy indices of the '
'source. If only one value is specified, other indices are '
'shifted based on the source. If fewer values are given than '
'zy indices, the last two value given imply a stride for the '
'xy indices, the last two value given imply a stride for the '
'remainder.',
'type': 'array',
'items': {'type': 'number'},
Expand Down Expand Up @@ -533,6 +553,8 @@ def _axisKey(self, source, value, key):
:param key: the axis key. One of frame, c, z, t, xy.
:returns: the axis key (an integer).
"""
if source.get('%sSet' % key) is not None:
return source.get('%sSet' % key)
vals = source.get('%sValues' % key) or []
if not vals:
axisKey = value + source.get(key, 0)
Expand Down Expand Up @@ -868,12 +890,16 @@ def _mergeTiles(self, base, tile, x, y):
base = numpy.zeros((0, 0, tile.shape[2]), dtype=tile.dtype)
base, tile = _makeSameChannelDepth(base, tile)
if base.shape[0] < tile.shape[0] + y:
vfill = numpy.zeros((tile.shape[0] + y - base.shape[0], base.shape[1], base.shape[2]))
vfill = numpy.zeros(
(tile.shape[0] + y - base.shape[0], base.shape[1], base.shape[2]),
dtype=base.dtype)
if base.shape[2] == 2 or base.shape[2] == 4:
vfill[:, :, -1] = 1
base = numpy.vstack((base, vfill))
if base.shape[1] < tile.shape[1] + x:
hfill = numpy.zeros((base.shape[0], tile.shape[1] + x - base.shape[1], base.shape[2]))
hfill = numpy.zeros(
(base.shape[0], tile.shape[1] + x - base.shape[1], base.shape[2]),
dtype=base.dtype)
if base.shape[2] == 2 or base.shape[2] == 4:
hfill[:, :, -1] = 1
base = numpy.hstack((base, hfill))
Expand Down
1 change: 1 addition & 0 deletions test/test_source_ometiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def testStyleAutoMinMax():
output={'maxWidth': 256, 'maxHeight': 256}, format=TILE_FORMAT_NUMPY, frame=1)
imageB = imageB[:, :, :1]
assert numpy.any(image != imageB)
imageB = imageB.astype(numpy.uint16) * 257
assert image.shape == imageB.shape
assert image[128][128][0] < imageB[128][128][0]
assert image[0][128][0] < imageB[0][128][0]
Expand Down