question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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).

  1. adjust_contrast. Similar implementation in Pillow is:
    enhancer = ImageEnhance.Contrast(img)
    img = enhancer.enhance(contrast_factor)
  1. 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

cc @vfdev-5 @datumbox

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
VinhLoiITcommented, Sep 24, 2021

Sure I’ll do. I’ll create a PR soon.

1reaction
vfdev-5commented, Sep 24, 2021

@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 to main and I think we will be good.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found