Repository navigation
Conversation
## Changes - In `torchvision/transforms/functional_pil.py::adjust_hue`, extract the alpha channel (if present) before converting to `HSV`, perform the hue shift on the RGB data only, then reapply the original alpha channel via `putalpha` before converting back to the input mode. - Updated the `adjust_hue` docstring to note that the alpha channel is preserved if present. - No behavior change for images without an alpha channel (L, RGB, etc.). - Added a test asserting alpha values are unchanged after `adjust_hue` for an RGBA input across several hue factors. ## Testing - Ran `pytest test/test_transforms.py -vvv -k test_adjust_hue_rgba_preserves_alpha` locally — all passing. - Verified manually with a sample RGBA PNG that alpha values are identical before and after `adjust_hue` for factors in [-0.5, 0.5].
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9691
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @Aks27-hub! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
transforms.functional.adjust_hue(via_functional_pil.adjust_hue) convertsthe input image to PIL's
HSVmode before shifting the hue channel. SinceHSVmode has no alpha band, any alpha channel present on the input is lostand silently reset to fully opaque (255) once the result is converted back
to the original mode.
Fixes #3219
Changes
torchvision/transforms/_functional_pil.py::adjust_hue, extract the alpha channel (if present) before converting toHSV, perform the hue shift on the RGB data only, then reapply the original alpha channel viaputalphabefore converting back to the input mode.adjust_huedocstring to note that the alpha channel is preserved if present.adjust_huefor an RGBA input across several hue factors.Testing
pytest test/test_transforms.py -vvv -k test_adjust_hue_rgba_preserves_alphalocally - all passing.adjust_huefor factors in [-0.5, 0.5].