Skip to content

Support grayscale image-like tensors for adjust_contrast and adjust_saturation functions #4466

@VinhLoiIT

Description

@VinhLoiIT

🚀 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions