Image Enhancement
Techniques
Objective – process an image so that the result is
more suitable than the original image for a
specific application.
Methods
1. Spatial Domain
direct manipulation of pixels of the image
2. Frequency Domain
modifying the Fourier Transform of an image
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Image Enhancement in Spatial
Domain
These techniques operate directly on the pixels.
More efficient computation and requires less processing
resources to implement
Spatial Domain Process is defined by g(x,y)=T[f(x,y)]
T is an operator on f defined over a
neighborhood of point (x,y)
OUTPUT INPUT
IMAGE IMAGE
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Image Enhancement in Spatial
Domain
y
(x,y)
3x3 neighborhood of (x,y)
Image f
Smallest possible neighborhood size is 1x1,
x it can be 5x5, 7x7 or 9x9 etc.
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Image Enhancement in Spatial
Domain
1x1 neighborhood operation is called as point processing and is
represented by the transformation function s= T(r). Where s and r
represents the intensity of g and f respectively
Contrast stretching Thresholding Function
function
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Intensity Transformation
Function
Image Negative
Let the image has an intensity level in the range [0 L-1], then the intensity
transformation is given by s=L-1-r
s=T(r)
Output intensity
L-1
0 L-1 r
Input intensity
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Intensity Transformation
Function
Log Transformations
For an image having intensity ranging from [0 L-1], log transformation is given
by s=c log(1+r) , where c is a constant
Maps the narrow range of low
s=T(r) intensity values of input levels to
wider range of output levels.
Output intensity
L-1
Higher range of high intensity input
levels is mapped to narrow range of
out put levels.
0 L-1 r
Input intensity
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Intensity Transformation
Function
Log Transformations
The Log function has the important characteristic that it compresses the
dynamic range of images with large variation in the pixel value.
Classical example is displaying Fourier spectrum.
Fourier spectrum has the values in the range 0 to 1.5x106. These values are
scaled linearly for the display in 8 bit system.
Fourier spectrum Log transformation with c=1
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Intensity Transformation
Function
Power-law (Gamma ) Transformations
This has the basic form s=c rγ ,where c and γ are positive constants
Fractional values of γ maps a narrow
range of dark input values into a wider
range of output values. Opposite of this
also true for higher values of input
levels.
These are also called as gamma
correction due to the exponent in the
power law equation.
Plot for c=1
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Intensity Transformation
Function
Power-law (Gamma ) Transformations
CRT device have an intensity to
voltage response that is a power
function with exponent varying from
approximately 1.8 to 2.5. Such
display system would produce
images that are darker than intended.
Pre-processed image with
gamma correction
s=r1/2.5=r0.4. before input to
the display device
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Intensity Transformation
Function
Gamma correction is very important
when to reproduce an image exactly
on a display system.
Power-law transformations are also
used in general purpose contrast
manipulation.
close all
clear all;
clc;
[filename, pathname] = uigetfile('*.tif');
im = imread([pathname filename]);
imshow(im);
im1=double(im).^0.3;
im1=mat2gray(im1);
figure,imshow(im1);
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Intensity Transformation
Function
MRI of fractured Result of a Result of a Result of a
human spine transformation transformation transformation
for γ=0.6 for γ=0.4 for γ=0.3
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Intensity Transformation
Function
Arial image
Result of a transformation
for c=1 and γ=3
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Intensity Transformation
Function
Result of a transformation Result of a transformation
for c=1 and γ=4 for c=1 and γ=5
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Piecewise Linear
transformation functions
Contrast stretching
Low contrast images result from the following
Poor illumination
lack of dynamic range in the imaging sensor
Wrong settings of the lens aperture during acquisition
It is a process that expands the range of intensity levels in an image so
that it spans full intensity range of the recording medium or display
device
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Piecewise Linear
transformation functions
Contrast stretching
L-1
Controls the shape of the
transformation function
output intensity level, s
(r2,s2)
3L/4
L/2 T(r)
L/4
(r1,s1)
0
0 L/4 L/2 3L/4 L-1
Input intensity level, r
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Piecewise Linear
transformation functions
Contrast stretching
Suppose r1=s1 and r2=s2
L-1 L-1
output intensity level, s
output intensity level, s
(r2,s2) (r2,= s2)
3L/4 3L/4
L/2 T(r) L/2 T(r)
L/4 L/4
(r1,s1) (r1,=s1)
0 0
0 L/4 L/2 3L/4 L-1 0 L/4 L/2 3L/4 L-1
Input intensity level, r Input intensity level, r
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Piecewise Linear
transformation functions
Contrast stretching
Suppose r1=r2 and s1=0 and s2=L-1
L-1 (r2)
L-1
output intensity level, s
output intensity level, s
(r2,s2)
3L/4 3L/4
L/2 T(r) L/2 T(r)
L/4 L/4
(r1,s1)
0 0 (r1)
0 L/4 L/2 3L/4 L-1 0 L/4 L/2 3L/4 L-1
Input intensity level, r Input intensity level, r
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Piecewise Linear
transformation functions
Contrast stretching
Intermediate values of (r1,s1) and (r2,s2) produces various degree of spread in
the intensity
L-1
output intensity level, s
(r2,s2)
3L/4
T(r)
L/2
L/4
(r1,s1)
0
0 L/4 L/2 3L/4 L-1
Input intensity level, r
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Piecewise Linear
transformation functions
Contrast stretching (Example)
(r1,s1)=(rmin, 0) and (r2,s2)=(rmax,L-1)
L-1
output intensity level, s
3L/4 rmax,L-1
L/2 T(r)
L/4 rmin, 0
0
0 L/4 L/2 3L/4 L-1
Input intensity level, r
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Piecewise Linear
transformation functions
Contrast stretching (Example)
POOR CONTRAST IMAGE CONTRAST STRETCHED IMAGE
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Piecewise Linear
transformation functions
Contrast stretching (Example)
CONTRAST STRETCHED IMAGE
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Piecewise Linear
transformation functions
Contrast stretching (Example MATLAB PROGRAM)
close all
clear all;
clc;
[filename, pathname] = uigetfile('*.tif');
im = imread([pathname filename]);
imshow(im);
title('POOR CONTRAST IMAGE');
J = imadjust(im,[0.2 0.5],[0 1]);
figure,imshow(J);
title('CONTRAST STRETCHED IMAGE');
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Piecewise Linear
transformation functions
Contrast stretching (Example)
close all
clear all;
clc;
[filename, pathname] = uigetfile('*.tif');
im = imread([pathname filename]);
imshow(im);
title('POOR CONTRAST IMAGE');
K=im2bw(im,0.42);
figure,imshow(K)
Image Processing By Dr. Jagadish Nayak ,BITS Pilani, Dubai Campus
Piecewise Linear
transformation functions
Contrast stretching (Example)
POOR CONTRAST IMAGE
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Piecewise Linear
transformation functions
Intensity Level slicing
Highlighting specific range of intensities
Example :
Enhancing features such as masses of water in the satellite
imagery
Enhancing flaws in X-ray images.
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Piecewise Linear
transformation functions
Intensity Level slicing
L-1
s T(r)
0 r
L-1
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Piecewise Linear
transformation functions
Intensity Level slicing
L-1
s T(r)
0 r
L-1
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Piecewise Linear
transformation functions
Intensity Level slicing (Example)
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Piecewise Linear
transformation functions
Intensity Level slicing (Example)
clear all ;
clc;
[filename, pathname] = uigetfile('*.tif');
im = imread([pathname filename]);
z=double(im);
[row,col]=size(z);
for i=1:1:row
for j=1:1:col
if((z(i,j)>142)) && (z(i,j)<250)
z(i,j)=255;
else
z(i,j)=im(i,j);
end
end
end
figure(1); %-----------Original Image-------------%
imshow(im);
figure(2); %-----------Gray Level Slicing With Background-------------%
imshow(uint8(z));
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Piecewise Linear
transformation functions
Intensity Level slicing (Example)
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Piecewise Linear
transformation functions
Intensity Level slicing (Example)
clear all ;
clc;
[filename, pathname] = uigetfile('*.tif');
im = imread([pathname filename]);
z=double(im);
[row,col]=size(z);
for i=1:1:row
for j=1:1:col
if((z(i,j)>142)) && (z(i,j)<250)
z(i,j)=255;
else
z(i,j)=0;
end
end
end
figure(1); %-----------Original Image-------------%
imshow(im);
figure(2); %-----------Gray Level Slicing With Background-------------%
imshow(uint8(z));
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Piecewise Linear
transformation functions
Bit Plane slicing (Example)
Each pixels are digital number comprising of bits
For a 256 level gray-scale image there are 8 bits for each pixel
We can highlight the contribution of these bits to total image appearance
Example pixel value =135
1
0
10000111 0
0
0
1
1
1
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Piecewise Linear
transformation functions
Bit Plane slicing (Example)
An 8 bit gray scale
image
Contribution of bit
plane 8
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Processing
Let the intensity level in the image be in the range from [0 L-1]
Histogram is a discrete function h(rk)=nk, where rk is the kth intensity value
and nk is the number of pixels in the image with pixel level rk.
This histogram is normalized by dividing each component by total number of
pixels in the image. Thus normalized histogram is given by,
nk
p(rk ) for k 0,1,2,3......L 1
MN
p(rk) is an estimate of the probability of occurrence of intensity level rk in an
image. (Sum all the components=1)
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Processing
clear all ;
clc;
[filename, pathname] = uigetfile('*.tif');
im = imread([pathname filename]);
imshow(im);
figure, imhist(im);
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Processing
6000
5000
4000
3000
2000
1000
0 50 100 150 200 250
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Processing
7000
6000
5000
4000
3000
2000
1000
0 50 100 150 200 250
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Processing
7000
6000
5000
4000
3000
2000
1000
0 50 100 150 200 250
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Processing
4000
3500
3000
2500
2000
1500
1000
500
0 50 100 150 200 250
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
Let us denote r [0 L-1] as intensities of the image to be processed
r=0 corresponding to black and r=L-1 representing white.
Let the intensity transformation is defined by s=T(r) , where 0 ≤ r ≤ L-1
T(r) is monotonically increasing function in the interval 0 ≤ r ≤ L-1
0 ≤ T(r) ≤ L-1 and 0 ≤ r ≤ L-1
Suppose we use the inverse operation as r=T-1(s) , then the condition should
be strictly monotonically increasing.
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
Satisfies the condition T(r) is Strictly monotonically
monotonically increasing increasing
function in the interval 0 ≤ r ≤ L- Mapping is one to one in
1 and 0 ≤ T(r) ≤ L-1 and 0 ≤ r both the directions.
≤ L-1
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
Let us consider intensity levels in the image as random variables in the
interval 0 to L-1.
Let us defined the Probability Density Function (PDF) as pr(r) and ps(s) for
r and s respectively.
If pr(r) and T(r) is known, where T(r) is continuous and differentiable
over the PDF range , then
dr
ps ( s ) pr ( r )
ds Cumulative
The transformation function is of the form Distribution
r
Function (CDF) of
s T (r ) ( L 1) pr ( w)dw random variable r
0
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
The transformation function of this form satisfies both the conditions we
have seen.
Now let us compute ps(s), we know s=T(r)
Substituting this for ps(s), we get
ds dT (r ) dr
dr dr ps ( s ) pr ( r )
ds
r
d 1
( L 1) pr ( w)dw pr ( r )
dr 0 ( L 1) pr (r )
( L 1) pr (r ) 1
0 s L 1
L 1
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
Which is a uniform probability density function, this means , performing
intensity transformation yields a random variable s characterized by
uniform PDF.
It can be noted that T(r) depends on pr(r) but ps(s) is always uniform and
independently of the form of pr(r).
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
(Example)
Suppose intensity values in an image have the PDF
2r
for 0 r ( L 1)
pr ( r ) ( L 1) 2
0 otherwise
r r
2 r2
s T (r ) ( L 1) pr ( w)dw wdw
0
( L 1) 0 ( L 1)
Suppose L=9 and pixel at location say (x,y) has the value r=3, then
s=T(r)= r2/9=1
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
(Example)
The PDF of the intensities in the new image is
1
dr 2r ds
ps ( s ) pr ( r )
ds ( L 1) 2 dr
2 1
2r d r
( L 1) 2 dr L 1
Assume r is positive and
L>1
2r ( L 1) 1
Result is uniform PDF
( L 1) 2 2r L 1
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
For the discrete values of the histogram , we deal with summation instead of
integration
nk
p(rk ) k 0,1,2,.......L 1
MN
The discrete form of transformation is given by
k
sk T (rk ) ( L 1) pr ( r j )
j 0
k
( L 1)
nj k 0,1,2,........L 1
MN j 0
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
The input pixel rk is mapped to output pixel sk
The transformation (mapping) T(rk) is called as histogram
equalization or histogram linearization.
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
(Example)
Let us consider a 3 bit image (L=8) of 64 x 64 (MN=4096), has the intensity
distribution shown below.
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
(Example)
From the equation of histogram equalization , we have
0
s0 T (r0 ) 7 pr (rj ) 7 pr (r0 ) 1.33
j 0
1
s1 T (r1 ) 7 pr (rj ) 7 pr (r0 ) 7 pr (r1 ) 3.08
j 0
Similarly compute s2, s3, s4, s5, s6, s7
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram Equalization
(Example)
s0 1.33 1
s1 3.08 3
s2 4.55 5
s3 5.67 6
s4 6.23 6
s5 6.65 7
s6 6.86 7
s7 7.00 7
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram matching
(Specification)
Histogram equalization is an automatic enhancement.
Some times shape of the histogram can be specified based on the
requirement.
The method used to generate a processed image that has a specified
histogram is called histogram matching or histogram specification
nk
p(rk ) k 0,1,2,.......L 1
MN
The discrete form of transformation is given by
k
sk T (rk ) ( L 1) pr ( r j )
j 0
k
( L 1)
nj k 0,1,2,........L 1
MN j 0
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram matching
(Specification)
Let pz(z) is the specified PDF, which is going to be the PDF of the output
image. So we have
q
G ( z q ) ( L 1) p z ( zi ) sk
j 0
Desired value zq=G-1(sk)
This will give value of z for each value of s, by performing mapping of s to z
Let us understand it by an example
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram matching
(Specification)
Let us consider a 3 bit image (L=8) of 64 x 64 (MN=4096), has the intensity
distribution shown below.
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram matching
(Specification)
Specified histogram is given as follows
zq Pz(zq) STEP 1 : Scaled histogram-equalized values
Z0=0 0.00 s0 1.33 1
Z1=1 0.00 s1 3.08 3
Z2=2 0.00 s2 4.55 5
Z3=3 0.15 s3 5.67 6
Z4=4 0.20 s4 6.23 6
Z5=5 0.30 s5 6.65 7
Z6=6 0.20 s6 6.86 7
Z7=7 0.15 s7 7.00 7
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram matching
(Specification)
STEP 2 : Compute all the values of transformation function G,
0
G ( z0 ) 7 pz ( z j )
j 0
0
G ( z1 ) 7 p z ( z j ) 7[ p( z0 ) p( z1 )]
j 0
G ( z2 ) 0.00 G ( z3 ) 1.05 G ( z 4 ) 2.45 G ( z5 ) 4.55
G ( z6 ) 5.95 G ( z7 ) 7.00
These fractional values are converted to integer values as shown
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram matching
(Specification)
G(z0) 0.00 0
G(z1) 0.00 0
G(z2) 0.00 0
G(z3) 1.05 1
G(z4) 2.45 2
G(z5) 4.55 5
G(z6) 5.95 6
G(z7) 7.00 7
The condition of strictly monotonic is violated
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Histogram matching
(Specification)
To handle this situation following procedure is used
Find the smallest value of zq so that the value G(zq) is closest to sk.
For example s0=1, and G(z3)=1, which is a perfect match for this case,
here s0 -> z3 ,i. e every pixel whose value is 1 in the histogram
equalized image is mapped to pixel valued 3 in the histogram
specified image. Continuing this we get,
sk zq
1 3
3 4
5 5
6 6
7 7
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956