Skip to content

fix: support 1-channel or 16-bit images in Visualizer#617

Open
tybulewicz wants to merge 5 commits into
masterfrom
ttybulew/support_grayscale
Open

fix: support 1-channel or 16-bit images in Visualizer#617
tybulewicz wants to merge 5 commits into
masterfrom
ttybulew/support_grayscale

Conversation

@tybulewicz

@tybulewicz tybulewicz commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR addresses Visualizer failures when given grayscale (1-channel) or higher-bit-depth (notably 16-bit) images by normalizing inputs into an RGB 8-bit-compatible form before scene generation and rendering, aligning with the behavior expected by downstream PIL operations (e.g., blending).

Fixes #596

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@tybulewicz tybulewicz requested a review from Copilot June 30, 2026 12:28
@tybulewicz tybulewicz requested a review from a team as a code owner June 30, 2026 12:28
@github-actions github-actions Bot added tests Related to tests python python related changes labels Jun 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Visualizer failures when given grayscale (1-channel) or higher-bit-depth (notably 16-bit) images by normalizing inputs into an RGB 8-bit-compatible form before scene generation and rendering, aligning with the behavior expected by downstream PIL operations (e.g., blending).

Changes:

  • Add Visualizer._to_rgb() to convert grayscale inputs to RGB and scale 16-bit / float inputs to 8-bit prior to rendering/showing/saving.
  • Update Visualizer.show(), save(), and render() to consistently route all inputs through _to_rgb().
  • Add extensive unit tests covering grayscale, explicit single-channel arrays, 16-bit arrays/PIL images, and float input scaling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
model_api/src/model_api/visualizer/visualizer.py Adds _to_rgb() normalization and applies it to show/save/render to support grayscale + 16-bit inputs.
model_api/tests/unit/visualizer/test_visualizer.py Adds test coverage for grayscale and 16-bit image handling, plus related blending/stacking expectations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread model_api/src/model_api/visualizer/visualizer.py
Comment thread model_api/src/model_api/visualizer/visualizer.py
Comment thread model_api/tests/unit/visualizer/test_visualizer.py
Comment thread model_api/tests/unit/visualizer/test_visualizer.py
Comment thread model_api/tests/unit/visualizer/test_visualizer.py
Comment thread model_api/tests/unit/visualizer/test_visualizer.py
@tybulewicz tybulewicz force-pushed the ttybulew/support_grayscale branch from fdfab94 to ad1c228 Compare June 30, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python python related changes tests Related to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Visualizer().render fails for 16-bit images

2 participants