Inconsistent of adjust_contrast and adjust_brightness with PIL lib
See original GitHub issueThe adjust_contrst
implementation in Kornia is essentially the adjust_brightness
in Torchvision.
In order to reproduce the results from Torchvision, I think we might need to rename the adjust_contrast
to adjust_brightness
, and rewrite the adjust_contrast
. Our current implementation of adjust_contrast
is not adjusting contrast at all.
To reproduce:
from PIL import Image
import requests
from io import BytesIO
from torch import allclose
from kornia.color.adjust import (
adjust_brightness, adjust_contrast, adjust_saturation, adjust_hue)
response = requests.get("https://tinypng.com/images/social/website.jpg")
img = Image.open(BytesIO(response.content))
import torch
import kornia.augmentation.functional as F
from torchvision.transforms import functional as tvF
from torchvision.transforms import transforms
import matplotlib.pyplot as plt
import numpy as np
to_tensor = transforms.ToTensor()
to_pil = transforms.ToPILImage()
def tensor_pre_transform_wrapper(input: torch.Tensor):
""" A wrapper that tried to reproduce the actual output from:
- transforms.ToPILImage()
- transforms.ToTensor()
For each image, simply (img * 255).int() // 255
"""
return (input * 255).int().float() / 255
in_tensor = to_tensor(img)
in_pil = img
# factor = 0.5
out_tensor = adjust_contrast(tensor_pre_transform_wrapper(in_tensor), torch.tensor(2))
out_pil = tvF.adjust_brightness(in_pil, 2)
allclose(out_tensor, to_tensor(out_pil))
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to adjust Brightness, Contrast, Sharpness and Saturation ...
In this Python tutorial, we're going to show you how to adjust brightness, contrast, sharpness and saturation of an image using PIL (pillow)...
Read more >How to process images with Python PIL library - LinuxConfig.net
PIL Tutorial; How to convert a color image to B&W (Black & White); How to adjust contrast; How to adjust brightness; How to...
Read more >Cognitive Surveillance Architecture for Scenario Understanding
Among them we can find the PIL-EYE [Chang11] which was presented as a new platform for the integrated development of visual surveillance algorithms....
Read more >AWIPS CAVE-D2D User' | Manualzz
To adjust brightness to a specific level on the slider bar, place the pointer at the desired location along the slider bar and...
Read more >ECP 41OO SERIES PROJECTION SYSTEM SERVICE MANUAL
c) Turn room lights off. Project an image on the screen. d) Adjust BRIGHTNESS to 5 on the function bar graph. Adjust CONTRAST...
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
Yes. I will finish the tests for spatial augmentation in this weekend and update the docs accordingly.
Closed since we are going to keep those functions in OpenCV math than PIL.