Skip to content

Commit

Permalink
Merge pull request #449 from girder/region-compositing
Browse files Browse the repository at this point in the history
Handle subimages of different component depths.
  • Loading branch information
manthey authored Jun 2, 2020
2 parents 235a891 + ae823c1 commit faf8417
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,12 @@ def getRegion(self, format=(TILE_FORMAT_IMAGE, ), **kwargs):
y0 = 0
subimage = subimage[:min(subimage.shape[0], regionHeight - y0),
:min(subimage.shape[1], regionWidth - x0)]
image[y0:y0 + subimage.shape[0], x0:x0 + subimage.shape[1]] = subimage
if subimage.shape[2] > image.shape[2]:
newimage = numpy.ones((image.shape[0], image.shape[1], subimage.shape[2]))
newimage[:, :, :image.shape[2]] = image
image = newimage
image[y0:y0 + subimage.shape[0], x0:x0 + subimage.shape[1],
:subimage.shape[2]] = subimage
# Scale if we need to
outWidth = int(math.floor(outWidth))
outHeight = int(math.floor(outHeight))
Expand Down
9 changes: 9 additions & 0 deletions test/test_source_gdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest
import six

from large_image import constants
from large_image.exceptions import TileSourceException

import large_image_source_gdal
Expand Down Expand Up @@ -340,3 +341,11 @@ def testInternalMetadata():
source = large_image_source_gdal.GDALFileTileSource(imagePath)
metadata = source.getInternalMetadata()
assert metadata['driverShortName'] == 'GTiff'


def testGetRegionWithProjection():
imagePath = utilities.externaldata('data/landcover_sample_1000.tif.sha512')
ts = large_image_source_gdal.GDALFileTileSource(imagePath, projection='EPSG:3857')
region, _ = ts.getRegion(output=dict(maxWidth=1024, maxHeight=1024),
format=constants.TILE_FORMAT_NUMPY)
assert region.shape == (1024, 1024, 4)

0 comments on commit faf8417

Please sign in to comment.