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.

Inconsistent of adjust_contrast and adjust_brightness with PIL lib

See original GitHub issue

The 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))
Screenshot 2020-03-21 at 10 36 25 AM

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shijianjiancommented, Mar 27, 2020

Yes. I will finish the tests for spatial augmentation in this weekend and update the docs accordingly.

0reactions
shijianjiancommented, Apr 10, 2020

Closed since we are going to keep those functions in OpenCV math than PIL.

Read more comments on GitHub >

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

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