1

Global Contrast Normalization

Unsolved
Computer Vision

Difficulty: 3 | Problem written by mesakarghm
Global Contrast Normalization aims to prevent images from having different levels of contrast in different parts of images. 
To perform global contrast normalization, you will have to subtract the mean from each image, then rescale it so that the standard 
deviation across pixels equals constant x. 

\(X' = s {X - \bar {X} \over max (\epsilon , contrastValue) }\)

Here, the contrast value is defined as: 

\(contrast = \sqrt {\lambda +{1 \over mn} \sum_{i=1}^{m} \sum_{j=1}^{n} (X - \bar{X}) ^ 2} \)

Lambda is a positive regularization term to bias the standard deviation, and the denominator is supposed to be at least equal to epsilon.

Write a function global_contrast_normalization(image, s, lmda, epsilon) which takes in a 2D input image and the values of s, lambda, and epsilon, respectively. The output of the function should be a global contrast normalized image. The dimension of output image should be exactly the same as the dimension of input image. 

Sample Input:
<class 'numpy.ndarray'>
image: [[ 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]]
<class 'int'>
s: 1
<class 'int'>
lmda: 10
<class 'float'>
epsilon: 0.001

Expected Output:
<class 'numpy.ndarray'>
[[-1.0301608 -0.92870045 0.96522623 -0.82724005 -0.8441501 ] [-0.8610602 -0.6919596 -0.01555722 0.32264397 0.49174455] [-0.96252054 0.06899307 -0.94561046 -0.96252054 -0.96252054] [-0.96252054 0.06899307 1.759999 1.4048878 1.5739883 ] [-0.96252054 0.06899307 1.2526972 1.4048878 1.5739883 ]]

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.

Libero ullam ea aut quasi, ratione corporis quae, aut vero quidem eius soluta? Quas voluptatum sit fuga consequuntur sequi quos numquam minima, magni unde necessitatibus autem modi accusamus vitae est aspernatur incidunt fuga numquam, nihil illum asperiores suscipit dolore alias minima repellat laborum atque, recusandae non voluptates modi atque?

Minus eaque quam laudantium libero recusandae enim assumenda dolor, quasi optio deleniti magni maiores, laborum explicabo quos quaerat nihil quidem iste, commodi debitis pariatur similique rerum nesciunt asperiores corporis. Suscipit incidunt dolorem ex sit quia nulla perferendis numquam vel vitae nesciunt, minima beatae natus ex adipisci rem sunt laboriosam deserunt nihil fugit omnis? Consectetur cum earum ipsa alias natus corrupti minus neque excepturi, maiores sint sit totam iure quidem, tenetur adipisci doloribus culpa iure asperiores veniam quisquam veritatis perferendis voluptate cum, veritatis vero nemo, incidunt qui iusto eos autem a cum sunt molestias nulla. Possimus provident consequatur expedita libero saepe praesentium sint obcaecati deleniti qui.

Nihil omnis excepturi necessitatibus nostrum dolores labore itaque magni, illum incidunt saepe ratione, minus repellat sunt perferendis, laudantium fugiat cumque quam ipsa iusto, atque fugit vero nobis non. Voluptas deserunt ipsam voluptatibus. Nam dolorum harum itaque eveniet, repellat eveniet quis sint ad quidem quaerat et animi atque laudantium, commodi fuga consequatur minima omnis expedita consequuntur unde ea.

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)