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

Support images in BGR and BGRA #2340

Closed
abey79 opened this issue Jun 8, 2023 · 8 comments · Fixed by #7238
Closed

Support images in BGR and BGRA #2340

abey79 opened this issue Jun 8, 2023 · 8 comments · Fixed by #7238
Assignees
Labels
😤 annoying Something in the UI / SDK is annoying to use enhancement New feature or request 🍏 primitives Relating to Rerun primitives 📺 re_viewer affects re_viewer itself user-request This is a pressing issue for one of our users

Comments

@abey79
Copy link
Member

abey79 commented Jun 8, 2023

Describe the annoyance

There is generally no consensus between RGB and BGR image formats. For example, Pillow's PIL.Image.open() yields RGB format (including when the image is converted to a Numpy array). OpenCV's cv2.imread() or VideoCapture instead yield BGR numpy arrays.

rr.log_image() expects RGB and yields false colours otherwise. At the very least, this should be documented. Ideally, some optional format argument should be added so alternative formats may be correctly ingested.

To Reproduce
This code yields false color (e.g. blue skins):

import cv2
import rerun as rr

rr.init("demo")
rr.spawn()
image = cv2.imread("image.jpg")
rr.log_image("image", image)

This is fixed by adding explicit format conversion:

# ... 
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
rr.log_image("image", image)

Ideally, something like that would be possible:

rr.log_image("image", image, format=rr.BGR)
@abey79 abey79 added 😤 annoying Something in the UI / SDK is annoying to use 👀 needs triage This issue needs to be triaged by the Rerun team labels Jun 8, 2023
@abey79 abey79 changed the title rr.log_image silently expects RGB image format rr.log_image only handles RGB image format Jun 8, 2023
@abey79
Copy link
Member Author

abey79 commented Jun 8, 2023

FWIW np.array(mediapipe.Image.create_from_file("image.jpg").numpy_view()) is RGB

@Wumpf Wumpf added enhancement New feature or request 📺 re_viewer affects re_viewer itself and removed 👀 needs triage This issue needs to be triaged by the Rerun team labels Jun 17, 2023
@emilk
Copy link
Member

emilk commented Jun 27, 2023

This is related to adding more semantics to color tensors in general:

@emilk
Copy link
Member

emilk commented Jun 27, 2023

The quick-fix is just to reorder the data into RGB on the SDK side.

The deeper fix is adding a "ColorSemantics" component or similar.

@abey79 abey79 changed the title rr.log_image only handles RGB image format rr.Image only handles RGB image format Nov 6, 2023
@abey79
Copy link
Member Author

abey79 commented Nov 6, 2023

rr.log_image is no more, but the same applies for the rr.Image archetype.

@Wumpf Wumpf added the user-request This is a pressing issue for one of our users label Apr 17, 2024
@Wumpf Wumpf added the 🍏 primitives Relating to Rerun primitives label Apr 17, 2024
@emilk emilk changed the title rr.Image only handles RGB image format Support images in BGR and BGRA Jul 18, 2024
@emilk emilk added this to the 0.18 - Chunks and MHz scalars milestone Jul 18, 2024
@jleibs
Copy link
Member

jleibs commented Aug 1, 2024

Note some places in the code indicate we should change our defaults to BGR.

I do NOT think we should do this. BGR is a bad, legacy choice from opencv. It should not be our default.

@emilk
Copy link
Member

emilk commented Aug 6, 2024

The simple way to implement BGR and BGRA right now is to upload them as RGB(A) textures, and add a swap_red_blue: bool flag to the rectangle.wgsl shader

@emilk emilk added the blocked can't make progress right now label Aug 8, 2024
@emilk
Copy link
Member

emilk commented Aug 8, 2024

@Wumpf Wumpf self-assigned this Aug 16, 2024
@Wumpf Wumpf mentioned this issue Aug 20, 2024
6 tasks
@Wumpf Wumpf removed the blocked can't make progress right now label Aug 20, 2024
@Wumpf
Copy link
Member

Wumpf commented Aug 20, 2024

not blocked by it, we can have bgr ofc without it being editable

@Wumpf Wumpf removed this from the 0.18 - MHz logging milestone Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
😤 annoying Something in the UI / SDK is annoying to use enhancement New feature or request 🍏 primitives Relating to Rerun primitives 📺 re_viewer affects re_viewer itself user-request This is a pressing issue for one of our users
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants