From fd9189ed45477212e43da0904e793dc19bee182a Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 16 Jun 2022 12:05:22 -0400 Subject: [PATCH] Fix getPixel for single channel sources. --- CHANGELOG.md | 5 +++++ large_image/tilesource/base.py | 5 ++++- test/test_source_base.py | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3871c45b..deaeb85c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## Unreleased + +### Bug Fixes +- Fix getPixel for single channel sources ([875](../../pull/875)) + ## 1.14.5 ### Improvements diff --git a/large_image/tilesource/base.py b/large_image/tilesource/base.py index 6ed628897..0eab16cd9 100644 --- a/large_image/tilesource/base.py +++ b/large_image/tilesource/base.py @@ -2411,7 +2411,10 @@ def getPixel(self, includeTileRecord=False, **kwargs): pixel['tile'] = tile img = tile['tile'] if img.size[0] >= 1 and img.size[1] >= 1: - pixel.update(dict(zip(img.mode.lower(), img.load()[0, 0]))) + if len(img.mode) > 1: + pixel.update(dict(zip(img.mode.lower(), img.load()[0, 0]))) + else: + pixel.update(dict(zip([img.mode.lower()], [img.load()[0, 0]]))) return pixel diff --git a/test/test_source_base.py b/test/test_source_base.py index f595e6354..609161cdb 100644 --- a/test/test_source_base.py +++ b/test/test_source_base.py @@ -157,6 +157,7 @@ def testSourcesTilesAndMethods(source, filename): assert ts.getInternalMetadata() is not None assert ts.getOneBandInformation(1) is not None assert len(ts.getBandInformation()) >= 1 + assert ts.getPixel(region=dict(left=0, top=0)) is not None # Histograms are too slow to test in this way # assert len(ts.histogram()['histogram']) >= 1 # assert ts.histogram(onlyMinMax=True)['min'][0] is not None