Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a singleBand option to the multisource specification #1416

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

### Improvements
- Remove NaN values from band information ([#1414](../../pull/1414))
- Add a singleBand option to the multi-source specification ([#1416](../../pull/1416))

## 1.26.3

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 @@ -1560,7 +1560,9 @@
if hasattr(sc, 'styleIndex'):
del sc.styleIndex
sc.output = self._applyStyleFunction(sc.output, sc, 'main')
if sc.dtype == 'uint16':
if sc.dtype == 'uint8':
sc.output = sc.output.astype(np.uint8)

Check warning on line 1564 in large_image/tilesource/base.py

View check run for this annotation

Codecov / codecov/patch

large_image/tilesource/base.py#L1564

Added line #L1564 was not covered by tests
elif sc.dtype == 'uint16':
sc.output = (sc.output * 65535 / 255).astype(np.uint16)
elif sc.dtype == 'float':
sc.output /= 255
Expand Down
9 changes: 8 additions & 1 deletion sources/multi/large_image_source_multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@
'layout and size, assume all sources are so similar',
'type': 'boolean',
},
'singleBand': {
'description':
'If true, output only the first band of compositied results',
'type': 'boolean',
},
'axes': {
'description': 'A list of additional axes that will be parsed. '
'The default axes are z, t, xy, and c. It is '
Expand Down Expand Up @@ -761,7 +766,7 @@
self._nativeMagnification[key] or tsMag.get(key))
numChecked += 1
tsMeta = ts.getMetadata()
if 'bands' in tsMeta:
if 'bands' in tsMeta and self._info.get('singleBand') is not True:
if not hasattr(self, '_bands'):
self._bands = {}
self._bands.update(tsMeta['bands'])
Expand Down Expand Up @@ -1200,6 +1205,8 @@
tile = np.full((self.tileHeight, self.tileWidth, len(colors)),
colors,
dtype=getattr(self, '_firstdtype', np.uint8))
if self._info.get('singleBand'):
tile = tile[:, :, 0]

Check warning on line 1209 in sources/multi/large_image_source_multi/__init__.py

View check run for this annotation

Codecov / codecov/patch

sources/multi/large_image_source_multi/__init__.py#L1209

Added line #L1209 was not covered by tests
# We should always have a tile
return self._outputTile(tile, TILE_FORMAT_NUMPY, x, y, z,
pilImageAllowed, numpyAllowed, **kwargs)
Expand Down