Skip to content

torchvision.transforms.functional.adjust_hue does not respect alpha channel #3219

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
jamespltan opened this issue Jan 4, 2021 · 5 comments

Comments

@jamespltan
Copy link

jamespltan commented Jan 4, 2021

🐛 Bug

when working with RGBA images, the adjust_hue function does not seem to respect the alpha channel and imposes a max_value of 255 after the transform. Taking a quick look at the source code, it seems that the image is immediately converted to HSV without retaining the alpha channel. It should be a quick fix to retain the alpha channel and include it when merging back into RGBA.

To Reproduce

Steps to reproduce the behavior:

img = Image.open('xyz.png')
img_ = adjust_hue(img, 0.1)
print(np.array(img.split()[-1]).mean())
print(np.array(img_.split()[-1]).mean())

cc @vfdev-5

@datumbox
Copy link
Contributor

datumbox commented Jan 4, 2021

@jamespltan Thanks for reporting this.

You are right to say that the adjust_hue() method does not currently support transparency (neither on the PIL nor on the Tensor backend). The same applies for other transformations and unfortunately the documentation does not mention those limitations (cc @voldemortX).

Extending support and providing a proper and consistent solution across both backends is not trivial and will require storing additional meta-data about the images (for example their mode in case of tensors). This definitely requires additional discussion, so before tackling that "beast" I think it would be best to improve the current situation by:

  1. Aligning the behavior of the two backends. For instance currently PIL.adjust_hue() returns the image if monochrome while Tensor.adjust_hue() throws an exception.
  2. Update the documentation to clearly mention the limitations.
  3. Open an issue and list all current limitations so that we can discuss potential solutions.

Any contribution that addresses the above 3 points would be highly appreciated.

@voldemortX
Copy link
Contributor

voldemortX commented Jan 5, 2021

Yeah I forgot to mention that in the doc...

Maybe I can do the listed 3 points tomorrow to make up for it.

@datumbox
Copy link
Contributor

datumbox commented Jan 5, 2021

That would be awesome @voldemortX, thank you. There might be more limitations on the adjust_* methods that we don't clearly mention.

@jamespltan
Copy link
Author

Many thanks my dudes 🙏

@Iteravse
Copy link

Iteravse commented Apr 3, 2021

i want to fix this problem,any proposal?i just fix the same question in numpy,but,because it dosn't using gpu,seems like inefficient using for pyqt animation.so i need more efficiency solution,like use pytorch, think it is are not big issues,just copy alpha channel to result, @datumbox any good idea?, forget me dosn't really skilled the grammar with torchvision,and i ask a same questoin in here

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

No branches or pull requests

4 participants