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

Reduce color fringing in multi source compositing #1456

Merged
merged 1 commit into from
Feb 1, 2024
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 @@ -8,6 +8,7 @@
- Do not create needless alpha bands in the multi source ([#1451](../../pull/1451))
- Infer DICOM file size, when possible ([#1448](../../pull/1448))
- Swap styles faster in the frame viewer ([#1452](../../pull/1452))
- Reduce color fringing in multi source compositing ([#1456](../../pull/1456))

### Bug Fixes
- Fix an issue with compositing sources in the multi source caused by alpha range ([#1453](../../pull/1453))
Expand Down
6 changes: 6 additions & 0 deletions large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,10 @@ def getRegion(self, format: Union[str, Tuple[str]] = (TILE_FORMAT_IMAGE, ), **kw
'width': max(self.tileWidth, 4096),
'height': max(self.tileHeight, 4096)}
kwargs['tile_offset'] = {'auto': True}
resample = True
if 'resample' in kwargs:
kwargs = kwargs.copy()
resample = kwargs.pop('resample', None)
tileIter = TileIterator(self, format=TILE_FORMAT_NUMPY, resample=None, **kwargs)
if tileIter.info is None:
pilimage = PIL.Image.new('RGB', (0, 0))
Expand Down Expand Up @@ -1767,6 +1771,8 @@ def getRegion(self, format: Union[str, Tuple[str]] = (TILE_FORMAT_IMAGE, ), **kw
dtype = cast(np.ndarray, image).dtype
image = _imageToPIL(cast(np.ndarray, image), mode).resize(
(outWidth, outHeight),
getattr(PIL.Image, 'Resampling', PIL.Image).NEAREST
if resample is None else
getattr(PIL.Image, 'Resampling', PIL.Image).BICUBIC
if outWidth > regionWidth else
getattr(PIL.Image, 'Resampling', PIL.Image).LANCZOS)
Expand Down
4 changes: 2 additions & 2 deletions sources/multi/large_image_source_multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ def _getTransformedTile(self, ts, transform, corners, scale, frame, crop=None):
if output['maxWidth'] <= 0 or output['maxHeight'] <= 0:
return None, 0, 0
srcImage, _ = ts.getRegion(
region=region, output=output, frame=frame,
region=region, output=output, frame=frame, resample=None,
format=TILE_FORMAT_NUMPY)
# This is the region we actually took in our source coordinates, scaled
# for if we took a low res version
Expand Down Expand Up @@ -1149,7 +1149,7 @@ def _addSourceToTile(self, tile, sourceEntry, corners, scale):
self.logger.debug('getRegion: ts: %r, region: %r, output: %r', ts, region, output)
sourceTile, _ = ts.getRegion(
region=region, output=output, frame=sourceEntry.get('frame', 0),
format=TILE_FORMAT_NUMPY)
resample=None, format=TILE_FORMAT_NUMPY)
else:
sourceTile, x, y = self._getTransformedTile(
ts, transform, corners, scale, sourceEntry.get('frame', 0),
Expand Down