You are on page 1of 21

Advanced Digital Image Processing EE5623

Lecture 2:

Basic relationships between pixels


and pixel operations

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 1

Basic relationships between pixels


Arrangement of pixels: 0 1 1
0 1 0
0 0 1
4 neighbours N4(p): 1
0 1 0
0

Diagonal neighbours ND(p): 0 1


1
0 1

8 neighbours N8 (p) = ND(p) U N4(p) : 0 1 1


0 1 0

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 2

1
Basic relationships between Pixels
 Connectivity between pixels:
An important concept used in establishing boundaries of objects
and components of regions
Two pixels p and q are connected if
– They are adjacent in some sense
– If their gray levels satisfy a specified criterion of similarity

V: Set of gray level values used to define the criterion of


similarity

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 3

Basic relationships between pixels


Path
Let coordinates of pixel p: (x, y), and of pixel q: (s, t)
A path from p to q is a sequence of distinct pixels with
coordinates: (x0, y0), (x1, y1), ......, (xn, yn) where
(x0, y0) = (x, y) & (xn, yn) = (s, t),
and (xi, yi) is adjacent to (xi-1, yi-1) 1 i  n
Regions
A set of pixels in an image where all component pixels are
connected
Boundary of a region
A set of pixels of a region R that have one of more neighbors
that are not in R
2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 4

2
Distance Measures
Given coordinates of pixels p, q, and z: (x,y), (s,t), and (u,v)
Euclidean distance between p and q:
De ( p, q)  ( x  s) 2  ( y  t ) 2
– De distance  r from (x,y) define a disk of radius r centered at (x,y)
City-block distance between p and q:
D4 ( p, q)  x  s  y  t

– The pixels with D4 distance  r from (x,y) form a diamond centered at (x,y)
– the pixels with D4=1 are the 4-neighbors of (x,y)
Chessboard distance between p and q:
D8 ( p, q)  max(| x  s |, | y  t |)
– The pixels with D8 distance  r from (x,y) form a square centered at (x,y)
– The pixels with D8=1 are the 8-neighbors of (x,y)
2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 5

Image Enhancement
Process an image to make the result more suitable than the original
image for a specific application
– Image enhancement is subjective (problem/application
oriented)
Image enhancement methods
Spatial domain: Direct manipulation of pixel in an image(on the
image plane)
Frequency domain: Processing the image based on modifying the
Fourier transform of an image

Many techniques are based on various combinations of methods from


these two categories

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 6

3
Image Enhancement
Types of image enhancement operations
Point/pixel operations Output value at specific coordinates (x,y) is
dependent only on the input value at (x,y)
Local operations The output value at (x,y) is dependent on the
input values in the neighborhood of (x,y)
Global operations The output value at (x,y) is dependent on all
the values in the input image

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 7

Basic concepts
Spatial domain enhancement methods can be generalized as
g(x,y)=T[f(x,y)]
f(x,y) : input image
g(x,y): processed (output) image
T[*] : an operator on f (or a set of input images),
defined over neighborhood of (x,y)

Neighborhood about (x,y): a square or rectangular sub-


image area centered at (x,y)

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 8

4
Basic Concepts

3x3 neighborhood about (x,y)

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 9

Basic concepts
Pixel/point operation:
Neighborhood of size 1x1: g depends only on f at (x,y)
T: a gray-level/intensity transformation/mapping function
Let r = f(x,y) s = g(x,y)
r and s represent gray levels of f and g at (x,y)
Then s = T(r)
Local operations:
g depends on the predefined number of neighbors of f at (x,y)
Implemented by using mask processing or filtering
Masks (filters, windows, kernels, templates) :
a small (e.g. 3×3) 2-D array, in which the values of the
coefficients determine the nature of the process
2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 10

5
Common pixel operations
 Image negatives

 Log transformations

 Power-law
transformations

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 11

Image negatives
 Reverses the gray level order
 For L gray levels the transformation function is
s =T(r) = (L-1)-r

Input image (X-ray image) Output image (negative)


2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 12

6
Image negatives
Application: To enhance the visibility for images with more
dark portion

Original digital mammogram Output image


2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 13

Image scaling
s =T(r) = a.r (a is a constant)

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 14

7
Log transformations
Function of s = c Log(1+r)

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 15

Log transformations
Properties of log transformations
– For lower amplitudes of input image the range of gray levels is
expanded
– For higher amplitudes of input image the range of gray levels is
compressed
Application:
– Dynamic range of a processed image far exceeds the capability
of the display device
• (e.g. display of the Fourier spectrum of an image)
– Also called “dynamic-range compression / expansion”

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 16

8
Log transformations

Fourier spectrum with values of The result applying log transformation,


range 0 to 1.5 x 106 scaled linearly c=1

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 17

Power-law Transformation
Basic form:

s = crg ,
where c & g
are positive

Plots of equation
s = crg,
For various values of g
(c  1)

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 18

9
Power-law Transformation
For γ < 1: Expands values of dark pixels, compress values of
brighter pixels
For γ > 1: Compresses values of dark pixels, expand values of
brighter pixels
If γ=1 & c=1: Identity transformation (s = r)

A variety of devices (image capture, printing, display) respond


according to a power law and need to be corrected;

Gamma (γ) correction


The process used to correct the power-law response phenomena

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 19

Power-law Transformation
 Example of gamma correction

 To linearize the CRT response a pre-distortion circuit is


needed s = cr1/g

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 20

10
Gamma correction

Linear Response of
wedge gray CRT to Linear
scale image wedge

Gamma Output of
corrected monitor
wedge

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 21

Power-law Transformation: Example

MRI image of Result of applying Result of applying Result of applying


fractured human power-law power-law power-law
spine transformation transformation transformation
c = 1, g  0.6 c = 1, g  0.4 c = 1, g  0.3

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 22

11
Power-law Transformation: Example

Original Result of applying


satellite power-law
image transformation
c = 1, g  3.0

Result of Result of applying


applying power-law
power-law transformation
transformation
c = 1, g  5.0
c = 1, g  4.0

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 23

Piecewise-linear transformation

Contrast stretching
Goal:
Increase the dynamic range of the gray levels for low contrast
images

Low-contrast images can result from


– poor illumination
– lack of dynamic range in the imaging sensor
– wrong setting of a lens aperture during image acquisition

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 24

12
Piecewise-linear transformation: contrast stretching
Method

where a1, a2, and a3 control the result of contrast stretching


if a1 = a2 = a3 = 1 no change in gray levels
if a1 = a3 = 0 and r1 = r2, T(*) is a thresholding function,
the result is a binary image
2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 25

Contrast Stretching Example

Form of
Transformation Original low-
function contrast image

Result of Result of
contrast thresholding
stretching

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 26

13
Contrast stretching through histogram
If rmax and rmin are the maximum and minimum gray level of the input
image and L is the total gray levels of output image
The transformation function for contrast stretching will be
 
s  T (r )  (r  rmin )
L

 rmax  rmin 

rmin rmax

0 L-1
2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 27

Histogram equalization: continuous case


 Idea: To find a non-linear transformation
s = T (r)
to be applied to each pixel of the input image f(x,y), such that a
uniform distribution of gray levels in the entire range results for
the output image g(x,y).

 Assuming ideal, continuous case, with normalized histograms


– that 0  r  1 and 0  s 1
– T(r) is single valued i.e., there exists r= T-1(r)
– T(r) is monotonically increasing

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 28

14
Single valued monotonically increasing function
A function T(r) is monotonically increasing
if T(r1) < T(r2) for r1 < r2,
and monotonically decreasing
if T(r1) > T(r2) for r1 < r2.

Example of a transformation function


which is both single valued and
monotonically increasing
2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 29

Background (probability distribution)


Assume continuous random variables
The cumulative probability distribution function or cumulative
distribution function (cdf)
The probability that the random variable is less than or equal to a
specified constant a. We write this as

for all values of a (i.e.,   < a < ),

The probability density function (pdf) or density function of random


variable x is defined as the derivative of the cdf:

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 30

15
Histogram equalization: continuous case
 Fr(r) and Fs(s) : cdfs of original and transformed gray levels r and s.
 pr(r) and ps(s) : pdfs of original and transformed gray levels r and s.
For strictly monotonically increasing transformation function
Fs(s) = Fr(r) or ps(s) ds = pr(r) dr
Goal of histogram equalization:
Gray levels are uniformly distributed
i.e. pdf ps(s) = 1 over the range 0  s  1
 dr  ds dT (r )
ps ( s)  pr (r )   1 or pr (r )  
 ds  dr dr
r
 s  T (r )   pr ( )d
0

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 31

Histogram equalization
If the following transformation function is used
r
s  T (r )   pr ( )d for 0  r 1
0
Then the pdf ps(s) = 1 over the range 0  s  1

In words
If we select T(r) as the cumulative distribution of r
Then the output image will have a uniform pdf of gray levels

Now Consider
1. a digital (gray level) case
2. the gray levels 0  r  L  1
2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 32

16
Histogram equalization: Discrete case
The discrete approximation of the transformation
function for histogram equalization is:
k
sk  T (rk )   pr (rj ) for 0  k  L  1
j 0

nj L 1
pr ( r j )  , j  0,........, L  1 and n  nj
where n j 0

nj : number of pixels with gray level rj


n : total number of pixels
Note: For digital images, gray-level pdf cannot be
exactly uniform after histogram equalization
2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 33

Histogram equalization examples


Input image Output image

Input histogram and cdf Output histogram and cdf


2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 34

17
Histogram equalization examples
Low contrast image Output image

Equalized histogram

Equalized histogram
high contrast image Output image

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 35

Histogram equalization examples


Dark input image Output image

Equalized histogram

Equalized histogram
Bright input image Output image

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 36

18
Histogram equalization examples

Transformation functions for


histogram equalization
2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 37

Histogram equalization examples

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 38

19
Histogram equalization examples

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 39

Histogram equalization examples

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 40

20
Histogram equalization examples

2/16/2016 Capital University of Science and Technology Advanced Digital Image Processing EE5623 41

21

You might also like