You are on page 1of 104

Digital Image Processing

Lecture 3: Basic Image Processing


Sibt ul Hussain

Slides Credit: Andrew Zisserman

Slides Credit: Andrew Zisserman

Slides Credit: Andrew Zisserman

Slides Credit: Andrew Zisserman



Images and Digital Images

A digital image difers from a photo in that the values are all
discrete.

Usually they take on only integer values.

A digital image can be considered as a large array of discrete


dots, each of which has a brightness associated with it. These
dots are called picture elements, or more simply pixels.

The pixels surrounding a given pixel constitute its


neighborhood. A neighborhood can be characterized by its
shape in the same way as a matrix: we can speak of a 3x3
neighborhood, or of a 5x7 neighborhood.

An Image as 2D Function

An Image as 2D Function

An Image as 2D Function
Key Stages in Digital Image Processing: A
Traditional Linear View
Image
Acquisition
Image
Restoration
or!"ological
Processing
Segmentation
#$%ect
Recognition
Image
&n"ancement
Re!resentation
' Descri!tion
Pro$lem Domain
Colour Image
Processing
Image
Com!ression
Key Stages in Digital Image Processing: A
Traditional Linear View
Image
Acquisition
Image
Restoration
or!"ological
Processing
Segmentation
#$%ect
Recognition
Image
&n"ancement
Re!resentation
' Descri!tion
Pro$lem Domain
Colour Image
Processing
Image
Com!ression
Key Stages in Digital Image Processing:
Image &n"ancement
Image
Acquisition
Image
Restoration
or!"ological
Processing
Segmentation
#$%ect
Recognition
Image
&n"ancement
Re!resentation
' Descri!tion
Pro$lem Domain
Colour Image
Processing
Image
Com!ression
Processing an image so t"at t"e result is
more suita$le (or a !articular a!!lication) *s"ar!ening or de+
$lurring an out o( (ocus image, "ig"lig"ting edges, im!ro-ing
image contrast, or $rig"tening an image, remo-ing noise.
Key Stages in Digital Image Processing:
Image Resotration
Image
Acquisition
Image
Restoration
or!"ological
Processing
Segmentation
#$%ect
Recognition
Image
&n"ancement
Re!resentation
' Descri!tion
Pro$lem Domain
Colour Image
Processing
Image
Com!ression
T"is may $e considered as re-ersing t"e
damage done to an image $y a /nown cause) *remo-ing o( $lur
caused $y linear motion, remo-al o( o!tical distortions.
Key Stages in Digital Image Processing:
or!"ological Processing
Image
Acquisition
Image
Restoration
or!"ological
Processing
Segmentation
#$%ect
Recognition
Image
&n"ancement
Re!resentation
' Descri!tion
Pro$lem Domain
Colour Image
Processing
Image
Com!ression
Key Stages in Digital Image Processing:
Segmentation
Image
Acquisition
Image
Restoration
or!"ological
Processing
Segmentation
#$%ect
Recognition
Image
&n"ancement
Re!resentation
' Descri!tion
Pro$lem Domain
Colour Image
Processing
Image
Com!ression
Key Stages in Digital Image Processing:
Re!resentation ' Descri!tion
Image
Acquisition
Image
Restoration
or!"ological
Processing
Segmentation
#$%ect
Recognition
Image
&n"ancement
Re!resentation
' Descri!tion
Pro$lem Domain
Colour Image
Processing
Image
Com!ression
Key Stages in Digital Image Processing:
#$%ect Recognition
Image
Acquisition
Image
Restoration
or!"ological
Processing
Segmentation
#$%ect
Recognition
Image
&n"ancement
Re!resentation
' Descri!tion
Pro$lem Domain
Colour Image
Processing
Image
Com!ression
Key Stages in Digital Image Processing:
Image Com!ression
Image
Acquisition
Image
Restoration
or!"ological
Processing
Segmentation
Re!resentation
' Descri!tion
Image
&n"ancement
#$%ect
Recognition
Pro$lem Domain
Colour Image
Processing
Image
Com!ression
Key Stages in Digital Image Processing:
Color Image Processing
Image
Acquisition
Image
Restoration
or!"ological
Processing
Segmentation
Re!resentation
' Descri!tion
Image
&n"ancement
#$%ect
Recognition
Pro$lem Domain
Color Image
Processing
Image
Com!ression

An Image as 2D Function

Sampling

Digitization of Coordinate Values



Quantization


Image Formation

Sampling: Digitization of the coordinate values,

Depends on efective number of digital sensors.

Defnes the spatial resolution of image.

Quantization: Digitization of the amplitude values

Defned in number of bits, usually 8 bits are used


to record 256 diferent shades or light variations.

Types of image

Binary: Each pixel is black or white, so only one bit is needed


per pixel.

GrayScale: Each pixel is a shade of gray normally from black


(0) to white (255) so 8 bits per pixel.

Colour: Each pixel is a colour described by the mix of red,


green or blue (RGB). Each channel has a range of 0-255, so
24bits in total.

Indexed: Most colour images only use a subset of the possible


colours, for reduction of storage a colour map is used.

Binary Image

Gray Scale Image
White = 255 Black = 0
>> w=imread(tire.tif); figure ,imshow(w), pixval on

RGB Image
>> pep=imread('peppers.png'); fgure(1) ,imshow(pep); pixval on;
>> r=pep(:,:,1);g=pep(:,:,2); b=pep(:,:,3);fgure(2),imshow(r),pixval on

Indexed Image

Image Size

Image fles tend to be large

e.g. 512 x 512 gray scale image requires 256


Kbytes = 512 x 512 x 8bits.

For an RGB color image this will be 768


Kbytes= 256 x 3

General Commands

imread: Read an image

fgure: creates a fgure on the screen.

imshow(g): which displays the matrix g as an image.

pixval on: turns on the pixel values in our fgure.

impixel(i,j): the command returns the value of the pixel (i,j)

iminfo: Information about the image.




Image Enhancement
Image is composed of informative pattern modified by
non-informative variations.

Goal : Enhance informative pattern based on image data.

Examples: noise filtering,contrast adjustment, gamma


correction, etc.

Two types of image enhancement methods

Spatial domain (local) methods: operate directly on


image pixels.

Frequency domain (global) methods: operate in a


transformed domain.

We will mainly deal with spatial domain methods.


Spatial Domain Methods
f(x,y)
g(x,y)
g(x,y)
f(x,y)
Point
Processing
Area/Mask
Processing

Point Processing
Simplest yet contain powerful processing methods
for image enhancement.

Arithmetic operations

Histogram based methods

Histogram Stretching

Histogram Equalization

Point Processing Transformations

Convert a given pixel value to a new pixel value based on


some predefned function.

Identity Transformation

1. Arithmetic Operations
Apply simple function y= f(x) to each pixel gray value, those
include

Additions and subtractions:

Multiplication by a constant:
Where C is a constant
Note: Clipping will be required to keep the values in the range.

Addition and Subtraction

Addition and Subtraction

Adding a constant lighten the image.

Subtracting makes it darker.



Addition and Subtraction
>> im=imread('blocks.tif');
>> im = double(im) + 128;
>> im = min(im, 255); fgure, imshow(im,[])
>> im=imread('block.jpg');
>> im = double(im) - 128;
>> im = max(im, 0); fgure, imshow(im,[])
OR
>> im=imread('blocks.tif'); im=imadd(im,128),imshow(im);
>> im=imread('block.jpg'); im=imsubtract(im,128),

Multiplication and Division

Multiplication implies scaling.

Lightens if C > 1; Darkens if C < 1;



Multiplication and Division

Image Complements

Solarization

Solarization
Complementing dark Pixels. Complementing light Pixels.

Some Examples

Addition

Some Examples

Subtraction

Some Examples

Multiplication

Some Examples

Division
Credits:0aris Pa!asai/a+0anusc"
odesy

Slicing Transformations
Stretch grayle!el ranges "here "e desire more information (slope # $)%
&ompress grayle!el ranges that are of little interest (' ( slope ( $)%

Slicing Transformations
Image Addition

Useful for combining information between two


images
Image Averaging

Image quality can be improved by averaging a


number of images together (very useful in
astronomy applications).
1
23
43
13
233
images must $e
registered5
Image Subtraction

Useful for change detection.


Image Subtraction (contd)
)
edical a!!lication)
iodine medium in%ected
into t"e $loodstream
di((erence
en"anced
Image
Multiplication/Division

Suppose a sensor introduces some shading in the form:


g(x,y)=f(x,y) h(x,y)

We can estimate h(x,y) and remove shading by division.


original
s"ade !attern s"ade correction
Caution !!!
Arithmetic operation can produce pixel values outside of the
range [0 255].
You should convert values back to the range [0 255] to ensure
that the image is displayed properly.
How would you do the following mapping?
[f
min
f
max
] [ 0 255]

Power Law ( ) Transformations

Power Law ( ) Transformations

Image Histograms
An image histogram is a plot of the grayle!el fre*+encies (i%e%, the n+m,er of
pixels inthe image that ha!e that gray le!el)%

Image Histograms (Cont.)

Divide frequencies by total number of pixels to represent as


probabilities.
N n p
k k
/ =

Image Histograms

Records the distribution of diferent pixel values e.g.

Given a greyscale image, its histogram consists of a graph


indicating the number of times each grey level occurs in
the image.
>> pep=imread('pout.tif'); fgure(1) ,imhist(pep),axis tight;

Image Histograms

We can infer a lot about image appearance from its


histogram.

In a dark image, the gray levels (and hence the histogram)


would be clustered at the lower end.

In a uniformly bright image, the gray levels would be


clustered at the upper end.

In a well contrasted image, the gray levels would be well


spread out over much of the range:

Image Histograms

Image Histograms

Given a poorly contrasted or a dark image we would


like to improve its contrast or lighten it. We can do
this by
1. Histogram (Contrast) Stretching (Requires Manual
Input)
2. Histogram Equalization. (Automatic)

1. Histogram Stretching

1. Histogram Stretching

2. Histogram Equalization

We know that in a well contrasted image, the gray levels


would be well spread out over much of the range.

In other words each gray level value (shade) from [0,


255] will have equal occurrence probability in an
image.

Goal: The goal of histogram equalization is to apply a


transformation function T(r) on the input image such that
each gray level has equal occurrence probability.

2. Histogram Equalization

We know that in a well contrasted image, the gray levels


would be well spread out over much of the range.

In other words each gray level value (shade) from [0,


255] will have equal occurrence probability in an
image.

Goal: The goal of histogram equalization is to apply a


transformation function T(r) on the input image such that
each gray level has equal occurrence probability.

2. Histogram Equalization

2. Histogram Equalization
The transformation function needs to satisfy two conditions.
1.It must be a monotonic function.
2.It must be within the following range

within the limit
(Equation 1)
so
(Equation 2)
Lets use CDF as transormation unction!

e"aluatin# a $ierential o"er $einite inte#ral results in the inte#ral e"aluate$ at the u%%er limit
(Lei&ni' (ule)! so
(Equation ))
%uttin# the "alue o equation ()) to equation (2)
we #et
so

2. Histogram Equalization

2. Histogram Equalization

In discrete case it is very simply, we simply map each


gray level to its corresponding CDF value i.e.

A gray level k will be mapped to sum of


probabilities upto level k.
where (L-1) is the total number of gray levels
and is the scaling factor used to map pixels
back in the range [0, L-1].

2. Histogram Equalization
Example

2. Histogram Equalization
Example

2. Histogram Equalization
Example

2. Histogram Equalization

2. Histogram Equalization

2. Histogram Equalization

Histogram Matching

Goal: The goal is to apply a transformation function T(r)


on the input image such that its graylevels have
distribution similar to the pre-specifed one.
!*6.
6
L+2
3

Histogram Matching
!*6.
6
L+2
3
Step I Step II
Step III
*+
Algorithm: Histogram Matching
1.Equalize the input image to obtain equalized histogram
s=T(r).
2.Find the transformation G(z) for the pre-specifed histogram,
and built a lookup table for mapping z G(z).
3.For each value of s, fnd its closest G(z) value and respectively
its corresponding z value.
4.Finally map the s value to z.
**
Histogram Matching:Example
*,
Histogram Matching
,0
Histogram Matching
,1
Histogram Matching
,2
Histogram Matching
,)
Histogram Matching
,-
Histogram Matching
Note: Histogram matching is a trial and test method.
,5
Local Enhancement

Normally, transformation function based on the


content of an entire image.

Some cases it is necessary to enhance details


over small areas (local neighbourhoods) in an
image.

The histogram processing techniques are easily


adaptable to local enhancement.
,.
Local Enhancement
Pi7el+to+!i7el translation 8ono-erla!!ing region
,+
Local Equalization
,*
Local Equalization
,,
Bit-plane slicing

Instead of highlighting gray-level ranges,


highlighting the contribution made to total
image appearance by specifc bits might be
desired.

Suppose that each pixel in an image is


represented by 8 bits. Imagine that the image is
composed of eight 1-bit planes, ranging from
bit-plane 0, the least signifcant bit to bit-plane
7, the most signifcant bit.
100
23223322
2
2
3
3
2
2
3
2
9it+!lane 3
*least signi(icant.
9it+!lane :
*most signi(icant.
101
Bit-plane Slicing
9it+!lane :
9it+!lane ; 9it+!lane < 9it+!lane 2
#riginal Image
102
Bit-plane Slicing
10)
Bit-plane Slicing

Lookup Tables

Point operations can be done very efciently using


Lookup (LUT) tables.
1. We pre-calculate the transformation function T(r)
(mapping) value for each gray-scale value and
store that in a table.
2. We map each pixel value to its corresponding
mapped value via a single look-up.

Example: consider the division by 2 operations,


the lookup table will look like.


Spatial Domain Image Enhancement
These methods can be categorized into two classes:
1. Neighbourhood processing: To modify or change a pixel
value we only need to know its local neighbour gray values.
2. Point processing: works independently on each pixel i.e
changes its value without knowledge of its surroundings.

You might also like