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

Adjust scaling when generating lossless pyramidal files. #772

Merged
merged 1 commit into from
Feb 3, 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
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