Skip to content

Commit

Permalink
Merge pull request #772 from girder/lossless-conversion-option
Browse files Browse the repository at this point in the history
Adjust scaling when generating lossless pyramidal files.
  • Loading branch information
manthey authored Feb 3, 2022
2 parents e921b1f + e65f43a commit cb2625f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Make annotation schema more uniform ([#763](../../pull/763))
- Improve TileSource class repr ([#765](../../pull/765))
- Improve frame slider response with base quads ([#771](../../pull/771))
- Default to nearest-neighbor scaling in lossless image conversion ([#772](../../pull/772))

## Version 1.10.0

Expand Down
7 changes: 7 additions & 0 deletions large_image/tilesource/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def _vipsParameters(forTiled=True, defaultCompression=None, **kwargs):
:param level: compression level for zstd, 1-22 (default is 10).
:param predictor: one of 'none', 'horizontal', or 'float' used for lzw and
deflate.
:param shrinkMode: one of vips's VipsRegionShrink strings.
:returns: a dictionary of parameters.
"""
if not forTiled:
Expand All @@ -293,6 +294,12 @@ def _vipsParameters(forTiled=True, defaultCompression=None, **kwargs):
'Q': 90,
'predictor': 'horizontal',
}
# For lossless modes, make sure pixel values in lower resolutions are
# values that exist in the upper resolutions.
if convertParams['compression'] in {'none', 'lzw'}:
convertParams['region_shrink'] = 'nearest'
if kwargs.get('shrinkMode') and kwargs['shrinkMode'] != 'default':
convertParams['region_shrink'] = kwargs['shrinkMode']
for vkey, kwkeys in {
'tile_width': {'tileSize'},
'tile_height': {'tileSize'},
Expand Down
7 changes: 7 additions & 0 deletions utilities/converter/large_image_converter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ def get_parser():
help='JP2K peak signal to noise ratio. 0 for lossless.')
parser.add_argument(
'--cr', type=int, help='JP2K compression ratio. 1 for lossless.')
parser.add_argument(
'--shrink-mode', '--shrink', '--reduce', dest='shrinkMode',
default=None,
choices=['mean', 'median', 'mode', 'max', 'min', 'nearest', 'default'],
help='When producing lower resolution images, use this method for '
'computing pixels. This defaults to median for lossy images and '
'nearest for lossless images.')
parser.add_argument(
'--only-associated', dest='_keep_associated', action='append',
help='Only keep associated images with the specified keys. The value '
Expand Down

0 comments on commit cb2625f

Please sign in to comment.