UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
Lightening & Darkening of Grayscale Image
1. Mathematical Techniques
of Image Processing
Master of Applied Mathematics
Department of Mathematics
College of Science - University of Baghdad
Saad Al-Momen
2
4. Power Functions and Gamma-
Correction
01
Exponential Functions and Image Transformations
02
Logarithmic Functions and Image
Transformations
03
Linear Functions and Contrast Stretching
04
Automation of Image Enhancement
05
6. 𝒇 𝒙 = 𝒙𝟐
0,
1
2
0,
1
4
Shrinks
1
2
, 1
1
4
, 1
Stretches
𝒇 𝒙 = 𝒙
0,
1
4
0,
1
2
Stretches
1
4
, 1
1
2
, 1
Shrinks
• First we divide the pixel values by 255 in order to normalize
them by putting them in to the range of 0 to 1.
• Next, we raise the (normalized) pixel values to a positive power
0 < 𝛾 < 1 (for example, 𝛾 =
1
2
).
• Finally, we multiply the transformed pixel values by 255 and plot
the resulting image.
Practicall
y
10. Any value 𝛾> 1 can
be used to darken the
image, and any value
0 < 𝛾 < 1 can be
used to lighten it.
11. Write a MATLAB function that would lighten (or darken)
the specified image using the specified value of 𝛾. The
function should accept both the matrix of the image and
the value of 𝛾 as inputs. Ideally, it should work with any
gray scale image and with any color image. In the latter
case, the image should be converted into the YCbCr
color space, and the transformation should be applied to
the Y channel.
E x e r c i s e s
13. As we saw in the previous section, darkening could be
accomplished by raising the (normalized) pixel values to a positive
power 𝛾 > 1, that is, by applying a function that has the property
of being concave up.
Another well-known class of
functions that are concave up is the
class of exponential functions 𝑏𝑥
Unlike the graphs of the power
functions, the graphs of exponential
functions do not pass through the
origin, which is going to be a
problem if we apply an exponential
function to the pixel values.
Fortunately, this deficiency can be
easily remedied by shifting the
graph one unit down.
𝒚 = 𝟐𝒙
𝒚 = 𝟓𝒙
𝒚 = 𝟐𝟎𝒙
Basic Exponential
Functions
14. We would also like our function to map the interval [0, 1] into the
interval [0,1].
We are looking for a function:
𝑓 𝑥 = 𝑐(𝑏𝑥 − 1)
that satisfies the conditions
𝑓 0 = 0 and 𝑓 1 = 1
The second conditions above
implies that the constant 𝑐 has to
equal
𝑐 =
1
𝑏 − 1
i.e.
𝑓 𝑥 =
(𝑏𝑥
− 1)
𝑏 − 1
𝒚 = 𝒄(𝟐𝒙
− 𝟏)
𝒚 = 𝒄(𝟓𝒙
− 𝟏)
𝒚 = 𝒄(𝟐𝟎𝒙
− 𝟏)
Exponential Transforms
15. MATLAB
Implementation
• First we divide the pixel values by 255 in
order to normalize them by putting them in
to the range of 0 to 1.
• Next, we calculate every pixel value 𝐵(𝑚, 𝑛)
in the modified image 𝐵 from the
corresponding pixel 𝐴(𝑚, 𝑛) by means of the
formal
𝐵 𝑚, 𝑛 = c(𝑏𝐴 𝑚,𝑛 − 1)
• Finally, we multiply the transformed pixel
values by 255 and plot the resulting image.
Practicall
y
17. The exponential transform
tends to be more
effective in correcting
overexposed images that
have most of the pixel
values crowded in a
small interval near the
maximal intensity.
18. Write a MATLAB function that would darken the specified
image using the exponential transform with a specified
value of the base b. Your function should accept the
image and the base b as inputs. Ideally, your function
should work with any gray scale image and with any
color image. In the latter case, the image must be
converted into the YCbCr color space, and the
transformation must be applied to the Y channel.
E x e r c i s e s
20. In the previous section, we saw that in order to darken an overexposed
image, we had a choice of mathematical instruments and were not limited
to just the power-function transforms with the parameter 𝛾 > 1.
The exponential-function transform is
used for images where most of the
pixel values concentrated in a
narrow interval of near-maximal
intensity.
Similarly, when it comes to lightening
an image, there is no reason to feel
limited to just the power function
transform with the parameter 0 < 𝛾 <
1.
𝒚 = 𝒍𝒐𝒈𝟐𝒙
𝒚 = 𝒍𝒐𝒈𝟓𝒙
𝒚 = 𝒍𝒐𝒈𝟐𝟎𝒙
What made such power functions
suitable for the purpose of lightening
an image is that their graphs are
concave down.
Basic Logarithmic Functions
21. Unlike the graphs of the power functions, the graphs of the logarithmic
functions do not pass through the origin. Nor do they pass through the point
(1,1)
The former deficiency can be easily
remedied by shifting the graph one unit to
the left by adding 1 to the expression of the
logarithm is applied to.
In order to ensure that our function maps
the interval [0,1] onto the interval [0,1], we
need to impose further conditions.
We are looking for a function:
𝑓 𝑥 = 𝑐log𝑏(𝑥 + 1)
that satisfies the conditions
𝑓 0 = 0 and 𝑓 1 = 1
The second conditions
above implies that the
constant 𝑐 has to equal
1 = 𝑐 log𝑏 2
𝑐 =
1
log𝑏 2
𝑓 𝑥 =
log𝑏(𝑥 + 1)
log𝑏 2
⇒ 𝑓 𝑥 = log2(𝑥 + 1)
𝐥𝐨𝐠𝒂𝒙 =
𝐥𝐨𝐠𝒃 𝒙
𝐥𝐨𝐠𝒃 𝒂
22. 𝑔 𝑥 = log𝑏(𝜎𝑥 + 1)
that satisfies the conditions
𝑔 0 = 0 and 𝑔 1 = 1
From the second condition we have
1 = log𝑏(𝜎 + 1)
𝑏1
= 𝜎 + 1
So the parameter 𝜎 satisfys the condition
𝜎 = 𝑏 − 1
One possible idea would be to recall that logarithmic and exponential functions
are inverses of each other.
The inverse of 𝑓 𝑥 = 𝑐 𝑏𝑥 − 1 is 𝑓−1 𝑥 = log𝑏(
𝑥
𝑐
+ 1)
Therefore, it would seem reasonable to construct a suitable function for our
logarithmic transform in the form.
𝒚 = 𝒍𝒐𝒈𝟐(𝝈𝒙 + 𝟏)
𝒚 = 𝒍𝒐𝒈𝟓(𝝈𝒙 + 𝟏)
𝒚 = 𝒍𝒐𝒈𝟐𝟎(𝝈𝒙 + 𝟏)
Logarithmic Transforms
𝒚 = 𝒍𝒐𝒈𝒃𝒙 ⇔ 𝒃𝒚 = 𝒙
23. MATLAB
Implementation
• First we divide the pixel values by 255 in
order to normalize them by putting them in to
the range of 0 to 1.
• Next, we calculate every pixel value 𝐵(𝑚, 𝑛) in
the modified image 𝐵 from the corresponding
pixel 𝐴(𝑚, 𝑛) by means of the formal
𝐵 𝑚, 𝑛 = log𝑏 𝜎𝐴 𝑚, 𝑛 + 1 =
loga(𝜎𝐴 𝑚, 𝑛 + 1)
log𝑎 𝑏
• Finally, we multiply the transformed pixel
values by 255 and plot the resulting image.
Practicall
y
24. E x a m p l e
Logarithmic transform
𝑏 = 1000
We can get similar results by using a power-function transform with the parameter
0 < 𝛾 < 1.
However, the logarithmic transform tends to be more effective in bringing to light the
otherwise hidden features in an image where intensity levels differ vastly, but most
of the pixel values are very small
25. Write a MATLAB function that would bring out the hidden
features of the specified image using the logarithmic transform
with the specified value of the base 𝑏.Your function should
accept the image and the base as inputs. Ideally, your function
should work with any gray scale image and with any color
image. In the latter case, the image must be converted into the
YCbCr color space, and the transformation must be applied to
the Y channel
E x e r c i s e s
26. Suppose that a function is described by the formula
𝑦 = log𝑏(𝑐𝑥 + 1).
Determine the values of the parameters 𝑏 and 𝑐 if the graph of
the functions passes through the points
(a) (1,3) and (2,12),
(b) (1,5) and (4,10).
E x e r c i s e s
28. Low Contrast images
• It is not too light or to dark.
• The image only takes advantage of a small part of the available
range of pixel values.
Instead of being spread between 0 and 255, most
of the pixel values appear to fall into the fairly
narrow interval between, roughly, 75 and 160
Find the smallest value
74 the darkest pixel
Find the quartiles
𝑄1 = 89, 𝑄3 = 131
Find the largest value
224 the lightest pixel
The Action
Stretch the current interval
[74,224] to [0,255]
Stretch the narrow range [𝑄1, 𝑄3] to
the middle half [63,191]
29. 0 63 19
1
25
5
mi
n
𝑸𝟏 𝑸𝟑 max
We are looking for a monotone function 𝑔(𝑥) such that
𝑔 74 = 0, 𝑔 89 = 63, 𝑔 131 = 191, and 𝑔 224 = 255
34. Previously, we used trial and error to select the value of parameters
in power, exponential and logarithmic functions to enhance an image.
The contrast-stretching effect of the power-function transformation 𝑓 𝑥 = 𝑥𝛾
at a point
𝑥 = 𝑥0is related the derivative
𝑓′
𝑥0 = 𝛾𝑥0
𝛾−1
Now, let 𝑚 𝛾 = 𝑓′
𝑥0 = 𝛾𝑥0
𝛾−1
and we have to find the absolute maximum of the
function 𝑚 𝛾 on the interval 0 < 𝛾 < ∞.
To that we have to find the derivative
𝑚′ 𝛾 = 𝑥0
𝛾−1
+ 𝛾 ln 𝑥0 𝑥0
𝛾−1
and set 𝑚′
𝛾 equal to zero.
𝑥0
𝛾−1
+ 𝛾 ln 𝑥0 𝑥0
𝛾−1
= 0
⟹ 𝛾 = −
1
𝑙𝑛(𝑥0)
The candidate for the
Optimal value of the power
35. 1- Try to imitate the approach of this section to automate the
choice of the optimal base for the exponential transform.
2- Try to imitate the approach of this section to automate the
choice of the optimal base for the logarithmic transform.
E x e r c i s e s