SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Mathematical Techniques
of Image Processing
Master of Applied Mathematics
Department of Mathematics
College of Science - University of Baghdad
Saad Al-Momen
2
Underexposed photo
Overexposed photo
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
Power Functions and
Gamma-Correction
01
𝒇 𝒙 = 𝒙𝟐
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
𝒇 𝒙 = 𝒙𝜸
y= 𝒙𝟐
y= 𝒙𝟑
y= 𝒙𝟏𝟎
y= 𝒙
𝟏
𝟐
y= 𝒙
𝟏
𝟑
y= 𝒙
𝟏
𝟏𝟎
Basic Power Functions 𝜸 >
𝟏
Basic Power Functions 𝟎 < 𝜸 <
𝟏
MATLAB
Implementation
A=imread('underexposed.jpg');
A=rgb2gray(A);
subplot(3,2,1);imshow(A);
subplot(3,2,2);imhist(A);
A=double(A);
gamma=0.7;
B=((A/255).^ gamma)*255;
B=uint8(B);
subplot(3,2,3);imshow(B);
subplot(3,2,4);imhist(B);
gamma=0.4;
B=((A/255).^ gamma)*255;
B=uint8(B);
subplot(3,2,5);imshow(B);
subplot(3,2,6);imhist(B);
Example
MATLAB
Implementation
A=imread(‘overexposed.jpg');
A=rgb2gray(A);
subplot(3,2,1);imshow(A);
subplot(3,2,2);imhist(A);
A=double(A);
gamma=4;
B=((A/255).^ gamma)*255;
B=uint8(B);
subplot(3,2,3);imshow(B);
subplot(3,2,4);imhist(B);
gamma=7;
B=((A/255).^ gamma)*255;
B=uint8(B);
subplot(3,2,5);imshow(B);
subplot(3,2,6);imhist(B);
Example
Any value 𝛾> 1 can
be used to darken the
image, and any value
0 < 𝛾 < 1 can be
used to lighten it.
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
Exponential Functions and
Image Transformations
02
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
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
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
MATLAB
Implementation
A=imread('overexposed.jpg');
A=rgb2gray(A);
subplot(2,2,1);imshow(A);
subplot(2,2,2);imhist(A);
A=double(A);
b=1000;
c=1/(b-1);
B=c*(b.^(A/255))*255;
B=uint8(B);
subplot(2,2,3);imshow(B);
subplot(2,2,4);imhist(B);
Example
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.
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
Logarithmic Functions and
Image Transformations
03
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
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)
𝐥𝐨𝐠𝒂𝒙 =
𝐥𝐨𝐠𝒃 𝒙
𝐥𝐨𝐠𝒃 𝒂
𝑔 𝑥 = 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
𝒚 = 𝒍𝒐𝒈𝒃𝒙 ⇔ 𝒃𝒚 = 𝒙
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
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
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
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
Linear Functions and
Contrast Stretching
04
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]
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
Consider the linear function 𝑔 𝑥 = 𝑚𝑥 + 𝑏, where 𝑚 is the slope
and 𝑏 is the 𝑦-intercept.
𝑚 =
∆𝑦
∆𝑥
=
𝑦2−𝑦1
𝑥2−𝑥1
,where 𝑥1 ≠ 𝑥2
𝑦 − 𝑦1 = 𝑚 𝑥 − 𝑥1
𝑦 =
𝑦2 − 𝑦1
𝑥2 − 𝑥1
𝑥 − 𝑥1 + 𝑦1
0 63 191 255
𝒂 𝑸𝟏 𝑸𝟑 𝒃
𝑔 𝑥 =
63
𝑄1 − 𝑎
𝑥 − 𝑎 , 𝑎 ≤ 𝑥 ≤ 𝑄1
128
𝑄3 − 𝑄1
𝑥 − 𝑄1 + 63, 𝑄1 < 𝑥 < 𝑄3
64
𝑏 − 𝑄3
𝑥 − 𝑄3 + 191 𝑄3 ≤ 𝑥 ≤ 𝑏
MATLAB
Implementation
A=imread('lowcontrast.jpg');
A=rgb2gray(A);
[M,N]=size(A);
V=reshape(A,[1,M*N]);
a=min(V); b=max(V);
Q1=prctile(V,25);
Q3=prctile(V,75);
L=length(V);
for i=1:L
if V(i)<=Q1
W(i)=(63/(Q1-a))*(V(i)-a);
elseif V(i)>=Q3
W(i)=(64/(b-Q3))*(V(i)-Q3)+191;
else
W(i)=(128/(Q3-Q1))*(V(i)-Q1)+63;
end
end
B=reshape(W,[M,N]);
subplot(2,2,1); imshow(A,[0,255]);
subplot(2,2,2); imhist(A);
subplot(2,2,3); imshow(B,[0,255]);
subplot(2,2,4); imhist(B);
Example
MATLAB
Implementation
Example
Automation of Image
Enhancement
05
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
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
THANK YOU
Any questions?
You can find me at:
saad.m@sc.uobaghdad.edu.iq

Weitere ähnliche Inhalte

Ähnlich wie Lightening & Darkening of Grayscale Image

01 Functions and their Graphs.pptx
01 Functions and their Graphs.pptx01 Functions and their Graphs.pptx
01 Functions and their Graphs.pptx
Eljon02
 
Arjrandomjjejejj3ejjeejjdjddjjdjdjdjdjdjdjdjdjd
Arjrandomjjejejj3ejjeejjdjddjjdjdjdjdjdjdjdjdjdArjrandomjjejejj3ejjeejjdjddjjdjdjdjdjdjdjdjdjd
Arjrandomjjejejj3ejjeejjdjddjjdjdjdjdjdjdjdjdjd
12345arjitcs
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
aa11bb11
 

Ähnlich wie Lightening & Darkening of Grayscale Image (20)

DIP_Lecture-35_36_RKJ_Interpolation_Resampling_Unitary_Transformations1.pptx
DIP_Lecture-35_36_RKJ_Interpolation_Resampling_Unitary_Transformations1.pptxDIP_Lecture-35_36_RKJ_Interpolation_Resampling_Unitary_Transformations1.pptx
DIP_Lecture-35_36_RKJ_Interpolation_Resampling_Unitary_Transformations1.pptx
 
Chapter 2 - Types of a Function.pdf
Chapter 2 - Types of a Function.pdfChapter 2 - Types of a Function.pdf
Chapter 2 - Types of a Function.pdf
 
Image Enhancement in the Spatial Domain.pdf
Image Enhancement in the Spatial Domain.pdfImage Enhancement in the Spatial Domain.pdf
Image Enhancement in the Spatial Domain.pdf
 
Choice of weighting function and expansion function in cem
Choice of weighting function and expansion function in cemChoice of weighting function and expansion function in cem
Choice of weighting function and expansion function in cem
 
PRML Chapter 4
PRML Chapter 4PRML Chapter 4
PRML Chapter 4
 
Session 4 .pdf
Session 4 .pdfSession 4 .pdf
Session 4 .pdf
 
Module 2
Module 2Module 2
Module 2
 
01 Functions and their Graphs.pptx
01 Functions and their Graphs.pptx01 Functions and their Graphs.pptx
01 Functions and their Graphs.pptx
 
image processing intensity transformation
image processing intensity transformationimage processing intensity transformation
image processing intensity transformation
 
Arjrandomjjejejj3ejjeejjdjddjjdjdjdjdjdjdjdjdjd
Arjrandomjjejejj3ejjeejjdjddjjdjdjdjdjdjdjdjdjdArjrandomjjejejj3ejjeejjdjddjjdjdjdjdjdjdjdjdjd
Arjrandomjjejejj3ejjeejjdjddjjdjdjdjdjdjdjdjdjd
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)
 
AMS_502_13, 14,15,16 (1).pptx
AMS_502_13, 14,15,16 (1).pptxAMS_502_13, 14,15,16 (1).pptx
AMS_502_13, 14,15,16 (1).pptx
 
Image Enhancement in the Spatial Domain U2.ppt
Image Enhancement in the Spatial Domain U2.pptImage Enhancement in the Spatial Domain U2.ppt
Image Enhancement in the Spatial Domain U2.ppt
 
Image enhancement
Image enhancementImage enhancement
Image enhancement
 
EPE821_Lecture3.pptx
EPE821_Lecture3.pptxEPE821_Lecture3.pptx
EPE821_Lecture3.pptx
 
Act_Fin_IAMT
Act_Fin_IAMTAct_Fin_IAMT
Act_Fin_IAMT
 
Digtial Image Processing Q@A
Digtial Image Processing Q@ADigtial Image Processing Q@A
Digtial Image Processing Q@A
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
 

Kürzlich hochgeladen

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
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
  • 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
  • 7. 𝒇 𝒙 = 𝒙𝜸 y= 𝒙𝟐 y= 𝒙𝟑 y= 𝒙𝟏𝟎 y= 𝒙 𝟏 𝟐 y= 𝒙 𝟏 𝟑 y= 𝒙 𝟏 𝟏𝟎 Basic Power Functions 𝜸 > 𝟏 Basic Power Functions 𝟎 < 𝜸 < 𝟏
  • 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
  • 12. Exponential Functions and Image Transformations 02
  • 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
  • 19. Logarithmic Functions and Image Transformations 03
  • 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
  • 30. Consider the linear function 𝑔 𝑥 = 𝑚𝑥 + 𝑏, where 𝑚 is the slope and 𝑏 is the 𝑦-intercept. 𝑚 = ∆𝑦 ∆𝑥 = 𝑦2−𝑦1 𝑥2−𝑥1 ,where 𝑥1 ≠ 𝑥2 𝑦 − 𝑦1 = 𝑚 𝑥 − 𝑥1 𝑦 = 𝑦2 − 𝑦1 𝑥2 − 𝑥1 𝑥 − 𝑥1 + 𝑦1 0 63 191 255 𝒂 𝑸𝟏 𝑸𝟑 𝒃 𝑔 𝑥 = 63 𝑄1 − 𝑎 𝑥 − 𝑎 , 𝑎 ≤ 𝑥 ≤ 𝑄1 128 𝑄3 − 𝑄1 𝑥 − 𝑄1 + 63, 𝑄1 < 𝑥 < 𝑄3 64 𝑏 − 𝑄3 𝑥 − 𝑄3 + 191 𝑄3 ≤ 𝑥 ≤ 𝑏
  • 31. MATLAB Implementation A=imread('lowcontrast.jpg'); A=rgb2gray(A); [M,N]=size(A); V=reshape(A,[1,M*N]); a=min(V); b=max(V); Q1=prctile(V,25); Q3=prctile(V,75); L=length(V); for i=1:L if V(i)<=Q1 W(i)=(63/(Q1-a))*(V(i)-a); elseif V(i)>=Q3 W(i)=(64/(b-Q3))*(V(i)-Q3)+191; else W(i)=(128/(Q3-Q1))*(V(i)-Q1)+63; end end B=reshape(W,[M,N]); subplot(2,2,1); imshow(A,[0,255]); subplot(2,2,2); imhist(A); subplot(2,2,3); imshow(B,[0,255]); subplot(2,2,4); imhist(B); Example
  • 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
  • 36. THANK YOU Any questions? You can find me at: saad.m@sc.uobaghdad.edu.iq