jbohnslav / opencv_transforms

OpenCV implementation of Torchvision's image augmentations
MIT License
375 stars 46 forks source link

How to determine the 74 in adjust_contrast function? #23

Closed AndyChang666 closed 3 years ago

AndyChang666 commented 3 years ago

Hi, I am curious that how you determine the number 74 in the line table = np.array([(i - 74) * contrast_factor + 74 in functional.py? Thank you.

jbohnslav commented 3 years ago

Thank you @AndyChang666 for this question. I chose this because it matched the performance of Pillow's ImageEnhance contrast. However, this magic number only worked for the image I was testing it on--the correct answer is the mean grayscaled value of the input image.

It is verified fixed with 7f633b691c8579d3e185bdc65ca185d8c3e32379. I added some unit tests to verify in c52c0ac370ac217bbb479f2ffaa32f3c2b81f1dc.