Skip to content

Commit

Permalink
Reduce memory allocation during some styling operations
Browse files Browse the repository at this point in the history
Specifically, when we apply a style, in some instances the tile or
region is converted from one dtype to a float in order to preserve some
of the transform properties through the process.  We had been using
`float`, which internally is `np.float64`.  But, `np.float32` gives
sufficient accuracy for our styles.  With this change, `np.float32` is
used unless the base datatype is `float64`, in which we do not reduce
the precision.
  • Loading branch information
manthey committed Aug 14, 2023
1 parent b6a49a5 commit 1679f5a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Add an endpoint to make it easier to replace thumbnails ([#1253](../../pull/1253))
- Presets from Large Image Configuration file ([#1248](../../pull/1248), [#1256](../../pull/1256))
- Reduce memory allocation during some region tiling operations ([#1261](../../pull/1261))
- Reduce memory allocation during some styling operations ([#1262](../../pull/1262))

### Changes
- Minor code changes based on suggestions from ruff linting ([#1257](../../pull/1257))
Expand Down
4 changes: 3 additions & 1 deletion large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,9 @@ def _applyStyle(self, image, style, x, y, z, frame=None): # noqa
if not style or ('icc' in style and len(style) == 1):
sc.output = image
else:
sc.output = np.zeros((image.shape[0], image.shape[1], 4), float)
sc.output = np.zeros(
(image.shape[0], image.shape[1], 4),
np.float32 if image.dtype != np.float64 else image.dtype)
image = self._applyStyleFunction(image, sc, 'pre')
for eidx, entry in enumerate(sc.style['bands']):
sc.styleIndex = eidx
Expand Down

0 comments on commit 1679f5a

Please sign in to comment.