Skip to content

Commit

Permalink
Merge pull request #1456 from girder/reduce-fringing
Browse files Browse the repository at this point in the history
Reduce color fringing in multi source compositing
  • Loading branch information
manthey authored Feb 1, 2024
2 parents 0ba587c + 7188ec5 commit 6e5394b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
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

0 comments on commit 6e5394b

Please sign in to comment.