0

Perceived Contrast

Unsolved
Computer Vision

Difficulty: 2 | Problem written by mesakarghm
The perceived contrast of an image can be calculated using the formula: 

\(contrast = {(max - min) \over (max + min)}\)

The percieved contrast of good images fall in the region of 0.5 +- 0.1.

Write a function contrast(img), which takes in a 2D NumPy array as input (representing a grayscale image) and returns the percieved contrast of the image. The output value should be a floating point value representing the percieved contrast of the image. 

Sample Input:
<class 'numpy.ndarray'>
img: [[ 1 7 119 13 12] [ 11 21 61 81 91] [ 5 66 6 5 5] [ 5 66 166 145 155] [ 5 66 136 145 155]]

Expected Output:
<class 'float'>
0.9880239520958084

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Officiis est aperiam voluptatem, magnam quaerat aliquam dolore. Voluptatem earum iusto eos labore magnam fugiat nemo repellendus atque voluptatum qui, repudiandae eum aliquam doloribus, non fugiat laborum, quod culpa illo dolor possimus error dolore saepe sint repudiandae, exercitationem magni voluptatibus fugiat tempora necessitatibus praesentium nulla magnam autem? Aut rerum ea cumque similique voluptatum repellendus culpa, fuga velit cum, sunt aliquid accusantium pariatur ducimus temporibus.

Excepturi modi accusantium cum cumque?

Exercitationem ipsa reprehenderit placeat ipsam error magnam ducimus fugiat cupiditate, harum eveniet odit ducimus impedit omnis cupiditate error cum quaerat esse, accusamus repudiandae atque.

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)