0% found this document useful (0 votes)
2 views

5. Digital Image Processing - Intensity Transformation & Spatial Filtering

Uploaded by

22021200
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

5. Digital Image Processing - Intensity Transformation & Spatial Filtering

Uploaded by

22021200
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 64

IMAGE PROCESSING

Le Thanh Ha, Ph.D


Assoc. Prof. at University of Engineering and Technology,
Vietnam National University
[email protected]; [email protected]; 0983 692 592
Content
3. Intensity Transformation & Spatial Filtering
- Some basic transformations
- Spatial filtering (Smoothing, Sharpening, Edge detection)
- …

12/19/2024 Le Thanh Ha 2
Digital Image
• A continuous image a(x,y) is sampled and quantized to form a
digital image presented by a matrix with N rows and M column.
One element in the matrix is called “Pixel”.
• The value of a pixel , called gray level, is assigned with an
integer I[m,n] {m=0,1,2,...,M-1} and {n=0,1,2,...,N-1}

12/19/2024 Le Thanh Ha 3
12/19/2024 Le Thanh Ha 4
Values frequently used

Parameter Symbol Values frequently used

row N 256,512,525,625,1024,1035

Column M 256,512,768,1024,1320

Gray level L 2,64,256,1024,4096,16384

12/19/2024 5 Le Thanh Ha
Image operator types
• Image operator takes images as inputs and also output images.
• Operators for Images are classified based on the affecting
region of the operators. There are three types:
– Point
– Local
– Global

12/19/2024 Le Thanh Ha 6
Image operator types
Operator Describe Complexity

The value of output pixel at a specific location Constant


Point
depends only on that of pixel at that location.

The value of output pixel at a specific location


P2
Local depends on the values of the pixel’s
neighbors

The value of output every pixel depends on all N2


Global
pixels in the image.

12/19/2024 7 Le Thanh Ha
Các thao tác trên ảnh (…)

12/19/2024 Le Thanh Ha 8
-Image negatives
-Power-law (gamma) transformations
- Contrast stretching
- Intensity-level slicing
-Histogram processing

INTENSITY TRANSFORMATION
(POINT OPERATORS)

12/19/2024 Le Thanh Ha 9
Image negatives

• I(x,y) = 255-I(x,y)

12/19/2024 Le Thanh Ha 10
Power-law (gamma) transformations

• A CRT device has an


intensity-to-voltage
response that is a
power function.
– The displayed images
are darker than they
actually are.

12/19/2024 Le Thanh Ha 11
Power-law (gamma) transformations

• Need a gamma correction for these CRT


devices:
I(x,y)I(x,y)
Example with =2

12/19/2024 Le Thanh Ha 12
Contrast stretching
• Low-contrast
images can
result from:
– Poor
illumination
– Small sensitive
range in imaging
sensor
–…

12/19/2024 Le Thanh Ha 13
Intensity-level slicing

• Highligting a interest range of intensities for specific


applications:
– Enhancing features
– Two types of highligting transformation functions

12/19/2024 Le Thanh Ha 14
Histogram processing
• Simply, histogram shows the count number of each gray level.
• In maths, histogram is the probability mass function of
intensity random variable.
• Histogram applications:
– Easily to be implemented in hardware
– How contrast an image is.
– Useful for applications involved with image segmentation and
compression.
–…
12/19/2024 Le Thanh Ha 15
Histogram processing
• H(i) is the number of pixels
1 2 1 2 1 1 with gray level i.
1 3 3 2 3 1  – H(1) = 14
 – H(2) = 8
1 5 6 5 5 1
  – H(3) = 6
2 5 7 7 4 2
– H(4) = 1
1 3 3 2 3 1
  – H(5) = 4
1 2 1 1 1 2 – H(6) = 1
– H(7) = 2

12/19/2024 Le Thanh Ha 16
Histogram processing
• Dark image: large numbers at
low intensity range.
• Light image: large numbers at
high intensity range.
• Low-contrast image:
histogram is condensed.
• High-contrast image:
histogram is look like a
uniform distribution.
12/19/2024 Le Thanh Ha 17
Histogram Equalization
• Is used to increase the contrast of a given
image by linearizing its histogram.

12/19/2024 Le Thanh Ha 18
Histogram Equalization
• Pseudocode
– Input I[M,N]:image, L:maximum gray level.
– Output Ihe[M,N]: histogram equalized image.
– Procedure:
1.
2.
Calculate histogram pI for image I.
T[0] = pI[0]
0 0 0 0
3. For k=1 to L
T[k] = T[k-1] + pI[k]
1 
1 2 2
I 
End for

4. For r=0 to L
S[r] = round(T[r]*L) 0 0 0 2
 
End for

2 2 3 3
5. For y=0 to M-1
For x=0 to N-1
r = I[y,x]
Ihe[y,x] = S[r]
End for
End for
12/19/2024 Le Thanh Ha 19
Histogram Equalization
• Equalize histogram of following image, (L=7):

0 0 0 0
1 
1 2 2
I 
0 0 0 2
 
2 2 3 3

12/19/2024 Le Thanh Ha 20
Histogram Equalization

12/19/2024 Le Thanh Ha 21
-Convolution
-Convolution for Image Processing
-Average filtering
-Median filtering

SPATIAL FILTERING

12/19/2024 Le Thanh Ha 22
Convolution

• Convolution of two continous signals:


 f  g (t )   f ( ) g (t   )d


• Convolution of two discrete signals:



 f  g [n]   f [i ]g[n  i ]
• Example: i  

12/19/2024 Le Thanh Ha 23
Convolution
• Convolution of 2D continuous signals:
 

 f  g ( x, y )   f ( x , y ) g ( x   x , y   y )d x d y


• Convolution of 2D discrete signals:


 
 f  g [m, n]    f [m, n]g[m  i, n  j ]
j   i  

12/19/2024 Le Thanh Ha 24
Properties of convolution
• Commulative:
c = a*b = b*a
• Associativity:
d = a*(b*c) = (a*b)*c
• Distributivity
d = a*(b+c) = a*b + a*c

12/19/2024 Le Thanh Ha 25
Convolution for Image Processing

• Discrete convolution for Image Processing:


f [ x, y ] I [ x, y ]  h[ x, y ]
 
  I [ x, y]h[ x  i, y  j]
j   i  
M N
  I [ x, y ]h[ x  i, y  j ]
j 1 i 1

• Image border problem


12/19/2024 Le Thanh Ha 26
Convolution for Image Processing
• Matrix manipulation:
h

I f

12/19/2024 Le Thanh Ha 27
Convolution for Image Processing
• Filtering

f [ x, y ] I [ x, y ]  h[ x, y ]

– I is an Image, h is a mask
– A pixel called anchor for the mask (topleft, or center)

12/19/2024 Le Thanh Ha 28
Convolution for Image Processing

• Mask h: 3x3 – An average filter used to smoothen image


• Anchor point is (1,1) in the mask.

1/8 1/8 1/8

1/8 0 1/8

1/8 1/8 1/8

12/19/2024 Le Thanh Ha 29
Convolution for Image Processing

12/19/2024 Le Thanh Ha 30
Border problem
• It happens when calculating convolution at border points
where some points of mask is placed outside of the image.
• It can be solved by padding the missing pixel by zero value
or copy vale from the nearest available pixels.

12/19/2024 Le Thanh Ha 31
Mask shape
• The value of output pixel at a specific location depends on the
values of the pixel’s neighbors

4-neighbor 8-neighbor
Mask size 3x3 Mask size 5x5

12/19/2024 Le Thanh Ha 32
Mask shape

Round with radius of 3 Lozenge shape

12/19/2024 Le Thanh Ha 33
Local Image Processing methods
• Smoothing and noise removal • Edge detection and highboost filtering
– Average filtering – Gradient methods
– Median filtering – Laplace method
– Probability filtering – Highboost filtering

12/19/2024 Le Thanh Ha 34
Average Filter
• Random noise typically consists of sharp transitions in gray
levels

• The most obvious application of smoothing is noise reduction

12/19/2024 Le Thanh Ha 35
Average Filter
• Average filter is to replace the value of every pixel by the
average of the gray levels in the neighborhood defined by the
filter mask.

• Beside noise, edges are charaterized by sharp transitions 


average filter also blurs edges.

12/19/2024 Le Thanh Ha 36
Average Filter

• Frequently used masks:


 0 1/ 6 0 
 1/ 4 1/ 4 
h1   h2  1/ 6 1/ 3 1/ 6 
 1/ 4 1/ 4   0 1/ 6 0 

 1/ 9 1/ 9 1/ 9   1 1 1
h3  1/ 9 1/ 9 1/ 9  1 
h4   1 2 1
 1/ 9 1/ 9 1/ 9  10
 1 1 1

12/19/2024 Le Thanh Ha 37
Average Filter
Mask: h1 Mask: h2

Original Image

Mask: h3 Mask: h4

12/19/2024 Le Thanh Ha 38
Average Filter
• The effects of smoothing
as a function of filter size
– The larger is the size, the
more significant blurring
observed.

12/19/2024 Le Thanh Ha 39
Median Filter
• For each p pixel in the image:
– Collect all neighbor pixels which are in the mask.
– Sort these pixel in the order of pixel’s value.
– Chose the pixel at the center of the sorted pixel array.
– Assign the value of chosen pixel to p.

• Median Filter are often used for noise removal.

12/19/2024 Le Thanh Ha 40
Median Filter
• Median Filter is different from Average Filter.
• A = {5 4 1 6 2 7 2 6 2 10 2 3}
• The average value is 4.667
• The median value:
– Sort array A = [1 2 2 2 2 3 4 5 6 6 7 10]
– Choose the the center value A = [1 2 2 2 2 3 4 5 6 6 7 10]
– The median value is 3

12/19/2024 Le Thanh Ha 41
Median Filter
Noised images Noise removed

Orignal Image

12/19/2024 Le Thanh Ha 42
Edge detection - Gradient
• Edges in 1 dimesion:

Ramp edge

Step edge

Line

Roof edge

12/19/2024 Le Thanh Ha 43
Gradient

• Gradient of a function indicates how the


function strongest increases.
2
– For 1-dimension function: f ( x)  x
f ( x)
Grad ( x)  2 x
( x)
– Grad(2)=4 indicates the the increasing direction
of the function is to the right.
– Grad(-1)=-2 indicates the increasing direction
of the function is to the left.
12/19/2024 Le Thanh Ha 44
Edge detection - Gradient

• Gradient of a 2-dimension function is calculated as


follows:  f ( x, y )
 f ( x, y )
Grad ( x, y )  i j
x y

• The gradient is approximated as follows (first-order


derivative) :
f ( x, y ) f ( x, y )
 f ( x  1, y )  f ( x, y ),  f ( x, y  1)  f ( x, y )
x y

12/19/2024 Le Thanh Ha 45
Edge detection - Gradient

• The magnitude of gradient indicates the strong of


edges:
2 2
 f ( x, y )   f ( x, y ) 
Grad ( x, y )     
  y    x 

• Edge dection procedure:


– Calculate column gradient
– Calculate row gradient
– Calculate final gradient by the above function

12/19/2024 Le Thanh Ha 46
Edge detection - Gradient
• Pixel Difference masks

Column mask Row mask

0 0 0   0  1 0
 0 1  1  0 1 0
   
 0 0 0   0 0 0 

12/19/2024 Le Thanh Ha 47
Edge Detection – Gradient

Column
edges
Original Image Final edges

Row
edges
12/19/2024 Le Thanh Ha 48
Edge detection - Gradient

• Roberts masks calculate gradient from two diagonals

Column Row

 0 0  1  1 0
0 1 0   0 1 0
   
 0 0 0   0 0 0 

12/19/2024 Le Thanh Ha 49
Edge detection - Gradient

Column
edges
Original Image Final edges

Row
edges
12/19/2024 Le Thanh Ha 50
12/19/2024 50
Edge detection - Gradient

• Prewitt masks

Column Row

 1 0  1   1  1  1
1  1 
1 0  1 0 0 0
3  3 
 1 0  1  1 1 1 

12/19/2024 Le Thanh Ha 51
Edge detection - Gradient

Row
edges
Original Image Final edges

Column
edges
12/19/2024 Le Thanh Ha 52
Edge detection - Gradient

• Sobel masks

Column Row

 1 0  1   1  2  1
1  1 
2 0  2 0 0 0
4  4 
 1 0  1  1 2 1 

12/19/2024 Le Thanh Ha 53
Edge detection - Gradient

Column
Original Image Final edges

Row

12/19/2024 Le Thanh Ha 54
12/19/2024 54
Edge detection - compass
• Image is convoluted with 8 masks

• Each mask is sensitive to a geometric direction of edge.

• The mask with highest value is chosen.

12/19/2024 Le Thanh Ha 55
Edge detection - compass

• T is a template mask
• Let T0=T; Ti is obtained by rotating T with an
angle of i*/4.
• A(x,y)=max{|Ti*I(x,y)|: i=0,1,2,...,7}
1 1  1 5  3  3
Pr ewitt  1  2  1 ; Kirsh  5 0  3 ;
 1 1  1  5  3  3
1 0  1 1 0  1
Robinson  Robinson 
 1 0  1 ;  2 0  2 
bac3 bac5
 1 0  1  1 0  1

12/19/2024 Le Thanh Ha 56
Edge detection - compass
Example: Kirsh mask

 5  3  3  5 5  3  5 5 5   3 5 5 
       
H 0  5 0  3 ; H1  5 0  3 ; H 2   3 0  3 ; H 3   3 0 5 ;
 5  3  3   3  3  3   3  3  3   3  3  3
       

  3  3 5   3  3  3   3  3  3   3  3  3
       
H 4   3 0 5 ; H 5   3 0 5 ; H 6   3 0  3 ; H 7  5 0  3 ;
  3  3 5  3 5 5   5 5 5   5 5  3 
    

12/19/2024 Le Thanh Ha 57
Edge detection – Laplace

• Laplace edge in the continuous domain is


defined as follows:

  2 f ( x, y )  2 f ( x, y ) 
G ( x, y )   2
 2 
  x  y 

12/19/2024 Le Thanh Ha 58
Edge detection - Laplace
• In discrete domain, Laplace edge is approximated by the
second order of dirivative:

G ( x, y ) [ f ( x, y )  f ( x, y  1]  [ f ( x, y  1)  f ( x, y )]
[ f ( x, y )  f ( x  1, y ]  [ f ( x  1, y )  f ( x, y )]

 f ( x, y )  H ( x, y )

12/19/2024 Le Thanh Ha 59
Edge detection - Laplace
• Mask H

0 0 0   0  1 0
H   1 2  1   0 2 0 
 0 0 0   0  1 0 
0 1 0
  1 4  1
 0 1 0 

12/19/2024 Le Thanh Ha 60
Edge detection - Laplace
Original image I |I*H|

12/19/2024 Le Thanh Ha 61
Highboost filtering

• Highboost the details (high frequencies) of an


image without defect the image form (low
frequencies)

12/19/2024 Le Thanh Ha 62
Highboost filtering
• Overall method:
I highboost c I orginal  I highpass
  0 0 0 
 
 c  0 1 0   H   I original
  0 0 0 
   
• Using Laplace mask

  0 0 0  0  1 0   0 1 0
 
I highboost  c  0 1 0     1 4  1   I original   1 c  4  1  Ioriginal
  0 0 0  0  1 0    0 1 0 
    
12/19/2024 Le Thanh Ha 63
Highboost filtering

Original Image c=0.5 c=1

12/19/2024 Le Thanh Ha 64

You might also like