Skip to content

Expose hsv_to_rgb and rgb_to_hsv #8179

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

Open
rehno-lindeque opened this issue Dec 20, 2023 · 2 comments
Open

Expose hsv_to_rgb and rgb_to_hsv #8179

rehno-lindeque opened this issue Dec 20, 2023 · 2 comments

Comments

@rehno-lindeque
Copy link

rehno-lindeque commented Dec 20, 2023

🚀 The feature

Expose torchvision.transforms.functional.hsv_to_rgb and torchvision.transforms.functional.rgb_to_hsv in the public api.

Motivation, pitch

There is already a private _hsv_to_rgb and _rgb_to_hsv (and the older _hsv2rgb, _rgb2hsv).

I'd like to use hsv_to_rgb directly in my project in order to visualize complex number fields.

Alternatives

There exists matplotlib.colors.hsv_to_rgb, and PIL.Image.Image.convert.

However there are numerous advantages to working directly with the pytorch tensors instead of converting back and forth.

Additional context

This should also help with implementing other custom transforms on top of HSV.

@rehno-lindeque rehno-lindeque changed the title Expose hsv_to_rgb and rb Expose hsv_to_rgb and rgb_to_hsv Dec 20, 2023
@rehno-lindeque rehno-lindeque changed the title Expose hsv_to_rgb and rgb_to_hsv Expose hsv_to_rgb and rgb_to_hsv Dec 21, 2023
@NicolasHug
Copy link
Member

NicolasHug commented Jan 2, 2024

Thank you for the feature request @rehno-lindeque . There was also #4029 opened in the past. So far, we've preferred not exposing such conversion utils in torchvision (see e.g. #4029 (comment)), mainly because every single transform and model in torchvision assumes images are RGB (or grayscale).

We do not have a way to tell distinguish between an RGB and HSV images and that could lead to wrong transformations being applied. (It is technically possible to distinguish via meta-data, but it's not something deemed valuable enough considering the high maintenance cost).

For now, the recommended way is simply to copy/paste the _hsv_to_rgb and _rgb_to_hsv utils into your own code-base. You could also rely on them directly, but since they're private, there is no backward-compatibility guarantee.

@rehno-lindeque
Copy link
Author

rehno-lindeque commented Jan 14, 2024

Thanks Nicolas, and apologies for missing this discussion.

For now, the recommended way is simply to copy/paste the _hsv_to_rgb and _rgb_to_hsv utils into your own code-base.

I threw together a tiny gist package for my purposes shortly after I opened the issue and that solved my immediate problem.

Just to mention, I didn't copy-paste because I felt it could be a bit dubious wrt licensing. I suspect it might not be the best recommendation for commercial users with proprietary code since it would be easy for the code to end up somewhere without the license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants