[feat] util img: dedicated function for converting RGB data to RGB8#3259
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new utility function projectYXC2RGB8 to handle RGB/RGBA image projection with intensity range mapping and tinting, refactoring existing inline code in the stream projection module.
- Adds
projectYXC2RGB8function inimg.pyfor converting YXC-format RGB/RGBA data to uint8 RGB with intensity range and tint support - Refactors
_projectTilemethod in_projection.pyto use the new function instead of inline tint handling - Adds comprehensive test coverage for the new function including RGB, RGBA, different data types, and tint scenarios
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/odemis/util/img.py | Adds projectYXC2RGB8 function with support for RGB/RGBA conversion, intensity range mapping, and tinting; adds Optional to type imports |
| src/odemis/acq/stream/_projection.py | Refactors _projectTile to use projectYXC2RGB8 for cleaner RGB tile processing |
| src/odemis/util/test/img_test.py | Adds TestProjectYXC2RGB8 test class with comprehensive coverage for various input types and tint scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughRGB tile projection in the acquisition stream now produces a new DataArray containing RGB data instead of mutating the input tile: it obtains an intensity range via Sequence Diagram(s)mermaid Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used🧬 Code graph analysis (1)src/odemis/acq/stream/_projection.py (4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/odemis/acq/stream/_projection.py(1 hunks)src/odemis/util/img.py(2 hunks)src/odemis/util/test/img_test.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/odemis/acq/stream/_projection.py (3)
src/odemis/acq/stream/_base.py (2)
_getDisplayIRange(972-986)_find_metadata(988-1028)src/odemis/util/img.py (2)
ensureYXC(702-732)projectYXC2RGB8(489-578)src/odemis/model/_dataflow.py (1)
DataArray(42-95)
src/odemis/util/test/img_test.py (1)
src/odemis/util/img.py (1)
projectYXC2RGB8(489-578)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: CodeQL analysis (python)
- GitHub Check: lint
- GitHub Check: build (ubuntu-24.04)
- GitHub Check: build (ubuntu-22.04)
4322ba5 to
d3f4182
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
src/odemis/util/img.py (1)
489-489: Broaden the type hint forirangeto support numeric types.The type hint
Optional[Tuple[int, int]]is too restrictive. At line 524,irangeis cast todata.dtype, which can be float or other numeric types. The hint should reflect this flexibility.Apply this diff:
-def projectYXC2RGB8(data: numpy.ndarray, irange: Optional[Tuple[int, int]] = None, +def projectYXC2RGB8(data: numpy.ndarray, irange: Optional[Tuple[float, float]] = None, tint: Tuple[int, int, int] = (255, 255, 255)) -> numpy.ndarray:Based on past review comments (Copilot's feedback on type hints).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/odemis/acq/stream/_projection.py(1 hunks)src/odemis/util/img.py(3 hunks)src/odemis/util/test/img_test.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- src/odemis/util/test/img_test.py
- src/odemis/acq/stream/_projection.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build (ubuntu-22.04)
- GitHub Check: build (ubuntu-24.04)
Converting from RGB to RGB should be simple... and it used to be handled by essentially copying the data. Just a basic code to handle tint. However, this works well only if the data is already uint8. For uint16, this didn't work. Also, the range wasn't computed. => introduce projectYXC2RGB8() to handle explicitly such method, and use in when the data is in "YXC" format. In particular, this helps opening Tescan RGB 16-bits images.
d3f4182 to
463fd3e
Compare
Converting from RGB to RGB should be simple... and it used to be handled
by essentially copying the data. Just a basic code to handle tint.
However, this works well only if the data is already uint8.
For uint16, this didn't work. Also, the range wasn't computed.
=> introduce projectYXC2RGB8() to handle explicitly such method, and use
in when the data is in "YXC" format.
In particular, this helps opening Tescan RGB 16-bits images.