Support grayscale image-like tensors for adjust_contrast and adjust_saturation functions
See original GitHub issue🚀 The feature
The following functions in functional_tensor.py
should be updated to work with single-channel image-like tensor, i.e. (1, H, W)
.
adjust_contrast
. Similar implementation in Pillow is:
enhancer = ImageEnhance.Contrast(img)
img = enhancer.enhance(contrast_factor)
adjust_saturation
. Similar implementation in Pillow is:
enhancer = ImageEnhance.Color(img)
img = enhancer.enhance(saturation_factor)
Motivation, pitch
When updating the documentation, I discovered some transform functions that work well on one channel PIL image (image with mode='L'
), yet they only support 3-channel tensors as in #4457.
Therefore, I think it is necessary to re-check and implement those functions to provide a similar result as in transforming PIL images.
Also, after solving this issue, we can further enable users to use AutoAugment
and similar classes to work with grayscale image tensors. Currently, grayscale pillow images can use these augmentations without errors, but not with single-channel image tensors, i.e. (1,H,W)
Alternatives
No response
Additional context
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:9 (5 by maintainers)
Top Results From Across the Web
tf.image.adjust_contrast | TensorFlow v2.11.0
Adjust contrast of RGB or grayscale images. ... images is a tensor of at least 3 dimensions. The last 3 dimensions are interpreted...
Read more >Adjust image intensity values or colormap - MATLAB imadjust
This MATLAB function maps the intensity values in grayscale image I to new values in J. ... Adjust Contrast of Grayscale Image Specifying...
Read more >kornia.enhance - Read the Docs
Adjust the contrast of an image tensor by subtracting the mean over channels. Note. this is just a convenience function to have compatibility...
Read more >adjust_contrast — Torchvision main documentation - PyTorch
Adjust contrast of an image. Parameters: img (PIL Image or Tensor) – Image to be adjusted. If img is torch Tensor, it is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure I’ll do. I’ll create a PR soon.
@VinhLoiIT yes, I agree with you about
rgb_to_grayscale
and that we can bypass it if input image is gray. I think you can checkout this branch: https://github.com/vfdev-5/vision/tree/add-gray-support-adjust_contrast and submit a PR to this repo: pytorch/vision. After the first PR has been merged you can update your branch tomain
and I think we will be good.