Skip to content

Commit

Permalink
Fix scaling small images in the multi source with bicubic smoothing
Browse files Browse the repository at this point in the history
We need a bigger border or some areas are zero.  Also, fix corner
computation.
  • Loading branch information
manthey committed Sep 6, 2024
1 parent 80970f0 commit 0fd5174
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.29.8

### Bug Fixes

- Fix scaling small images in the multi source with bicubic smoothing ([#1627](../../pull/1627))

## 1.29.7

### Improvements
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 @@ -1071,7 +1071,7 @@ def _getTransformedTile(self, ts, transform, corners, scale, frame, crop=None):
# we only need every 1/srcscale pixel.
srcscale = int(2 ** math.log2(max(1, srcscale)))
# Pad to reduce edge effects at tile boundaries
border = int(math.ceil(2 * srcscale))
border = int(math.ceil(4 * srcscale))
region = {
'left': int(max(0, minx - border) // srcscale) * srcscale,
'top': int(max(0, miny - border) // srcscale) * srcscale,
Expand Down Expand Up @@ -1119,8 +1119,8 @@ def _getTransformedTile(self, ts, transform, corners, scale, frame, crop=None):
# Recompute where the source corners will land
destcorners = (np.dot(transform, regioncorners.T).T).tolist()
destShape = [
max(max(math.ceil(c[1]) for c in destcorners), srcImage.shape[0]),
max(max(math.ceil(c[0]) for c in destcorners), srcImage.shape[1]),
max(max(math.ceil(c[1]) for c in destcorners), srcImage.shape[0]),
]
if max(0, -x) or max(0, -y):
transform[0][2] -= max(0, -x)
Expand Down
20 changes: 10 additions & 10 deletions test/test_source_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ def testMultiAffineTransform():
source = large_image_source_multi.open(imagePath)
frameval = [
[243, 243, 49065],
[3920, 3920, 47672],
[13, 13, 49149],
[3943, 3943, 47695],
[246, 246, 49063],
[972, 972, 48785],
[1455, 1455, 48597],
[204, 204, 49059],
[3924, 3924, 47676],
[13, 13, 49148],
[2592, 2592, 48093],
[235, 235, 49062],
[942, 942, 48785],
[1014, 1014, 48872],
[198, 198, 49063],
]
for frame in range(8):
thumbs = {}
Expand All @@ -292,9 +292,9 @@ def testMultiAffineTransform():
r = np.sum(img[:, :, 0] >= 128)
g = np.sum(img[:, :, 1] >= 128)
b = np.sum(img[:, :, 2] >= 128)
assert abs(r - frameval[frame][0]) < 200
assert abs(g - frameval[frame][1]) < 200
assert abs(b - frameval[frame][2]) < 200
assert abs(r - frameval[frame][0]) < 250
assert abs(g - frameval[frame][1]) < 250
assert abs(b - frameval[frame][2]) < 250
assert abs(np.average(thumbs[2048] - thumbs[256])) < 7
assert abs(np.average(thumbs[1024] - thumbs[256])) < 7
assert abs(np.average(thumbs[512] - thumbs[256])) < 7
Expand Down

0 comments on commit 0fd5174

Please sign in to comment.