0% found this document useful (0 votes)
18 views42 pages

Lec 3

Chapter 3 discusses spatial domain image processing, focusing on techniques such as intensity transformation functions, spatial filtering, and histogram processing. It differentiates between spatial and transform domains, explaining various methods like contrast stretching, thresholding, and histogram equalization. The chapter also includes exercises for practical application of these concepts.

Uploaded by

Seladdin Yassin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views42 pages

Lec 3

Chapter 3 discusses spatial domain image processing, focusing on techniques such as intensity transformation functions, spatial filtering, and histogram processing. It differentiates between spatial and transform domains, explaining various methods like contrast stretching, thresholding, and histogram equalization. The chapter also includes exercises for practical application of these concepts.

Uploaded by

Seladdin Yassin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Chapter 3

Spatial Domain Image Processing

Wachemo University(Durame Campus)


School of Computing and Informatics
Department of Computer Science
Course :Computer Vision and Image Processing
Mr. Habtamu B.(2025)
OUTLINES
 Spatial Processing of Digital Images
 Basic Intensity Transformation Functions
 Spatial filtering
 Histogram processing
Spatial Processing of Digital Images
Spatial Domain vs Transform Domain

Spatial domain (p127)


 This method directly processes the intensity values or pixel values of the
image plane and its results can immediately be interpreted by humans.

Transform domain
 This method transforms the input images into a transform domain,
processes some operation in the domain, and applies the inverse transform to
return to the spatial domain as shown in below diagram:

Fourier Inverse Fourier


Transform Transform

3
Spatial Domain vs Transform Domain

g ( x, y ) T [ f ( x, y )])
f ( x, y ) : input image Spatial – Transform
g ( x, y ) : output image domain domain

T : an operator on f defined over


a neighborhood of point ( x, y)
- The operator T can be a Fourier
Transformation in this book. The
output of T is much different from
input image and the shape in the
input image completely changed.

4
Spatial Domain Process

5
Spatial Domain Process
- Contrast stretching, Thresholding

Intensity transformation function


s T ( r )

Contrast stretching Thresholding function


function

6
Basic Intensity Transformation Functions

Intensity transformation
function

7
Image Negatives (p130)
intensity level s ( 0 ~ 255)

Image negatives
s L  1  r
Output image –

r= input intensity level


s= output intensity level
L-1 = maximum intensity
level
= 256 -1 = 255

r=0  s= (256-1)-0
=255
r=128  s=(256-1)-128
=127
r=255  s=(256-1)-255 = 0
Input image –
intensity level r ( 0 ~
255) 8
Image Negatives

Image negatives
s L  1  r

9
Example: Image Negatives
Ex:
w w=686

h
Ex:
h=790

Small
lesion

10
Log Transformations (p131)
Log Transformations
s c log(1  r )

11
Example: Log Transformations

12
Power-Law (Gamma) Transformations


s cr

13
Power-Law (Gamma) Transformations
void DibGammaCorrection(CDib& dib, float gamma)
{ register int i, j;
float invgamma = 1.f / gamma;

int w = dib.GetWidth(); int h = dib.GetHeight();

BYTE** ptr = dib.GetPtr();


for( j = 0 ; j < h ; j++ )
for( i = 0 ; i < w ; i++ )
{ ptr[j][i] = (BYTE)limit(pow((ptr[j][i]/255.f), invgamma)*255 + 0.5f); }


}

s cr
14
Example: Gamma Corrections - p134

s=r2.5

s=r0.5

s=r2.5

15
Example: Gamma Transformations
Cathode ray tube
(CRT) devices have
s=r2.5 an intensity-to-
voltage response
that is a power
function, with
exponents varying
s r1/2.5 from approximately
1.8 to 2.5
s=r0.
4 s=r2.5

16
Example: Gamma Transformations
s=r0.6

(a) original

17
s=r0.4 s=r0.3
Example: Gamma Transformations

s=r3.0

s=r4.0

s=r5.0 18
 Exercise

Select a image and implement:

– Image negative

– Log and gamma transformation

19
Spatial Filtering (p 166)

• A spatial filter consists of


(a) a neighborhood, and
(b) a predefined operation

• “Filtering” refers to accepting (passing) or rejecting certain frequency


components.

• “Low pass filter” passes low frequencies and vise versa.

• The Main role is to enhance image quality such as reducing noises.

• Spatial filter: is called also mask, kernel, template, and window.

20
Spatial Filtering (p 166)
• Linear spatial filtering of an image of size MxN with a filter of size mxn is
given by the expression

a b
g ( x, y )    w(s, t ) f ( x  s, y  t )
s  a t  b

Here,
a=(m-1)/2, b=(n-1)/2

Example: In an image of size MxN with a filter of size mxn


where

m=3, n=3  a=(3-1)/2= 2/2=1, b=1


21
Spatial Filtering

Spatial
filter mask

Image section
under filter
22
Spatial Correlation

The correlation of a filter w( x, y) of size m n


with an image f ( x, y ), denoted as w( x, y) f ( x, y)
a b
w( x, y ) f ( x, y )    w(s, t ) f ( x  s, y  t )
s  a t  b

The convolution of a filter w( x, y) of size m n


with an image f ( x, y ), denoted as w( x, y) f ( x, y)
a b
w( x, y ) f ( x, y )    w( s, t ) f ( x  s, y  t )
s  a t  b 23
Spatial Convolution: Example
a b
w( x, y ) f ( x, y )    w( s, t ) f ( x  s, y  t )
s  a t  b

s= -1, t= -1,  w(-1,-1) f(x+1, y+1)


-1, 0,  w(-1, 0) f(x+1, y)
-1, 1,  w(-1, 1) f(x+1, y-1)
0, -1,  w( 0,-1) f(x, y+1)
0, 0,  w( 0, 0) f(x, y)
0, 1,  w( 0, 1) f(x, y-1)
1, -1,  w( 1,-1) f(x-1, y+1)
1, 0,  w( 1, 0) f(x-1, y)
1, 1,  w( 1, 1) f(x-1, y-1)

24
Histogram Processing (p142)

• Histogram Equalization

• Histogram Matching

• Local Histogram Processing

• Using Histogram Statistics for Image Enhancement

25
Histogram Processing

n0 n1 n2
Histogram h( rk ) nk
0 1 2 3 ..... 254 255

rk is the k th intensity value


nk is the number of pixels in the image with intensity rk

nk
Normalized histogram p( rk ) 
MN
nk : the number of pixels in the image of
size M N with intensity rk

26
Histogram Processing

• Exercise:

• Use mat lab to compute a histogram of an


image. (Choose any image)?

• Normalize the obtained Histogram?

27
Histogram Processing

0 1 2 3 ..... 254 255

28
29
Histogram Equalization
histogram equalization
• Probability theory: (page 145)
If pr(r) and T(r) are known, and T(r) is continuous and differentiable
over the range of values of interest,
then the PDF of the transformed (mapped) variable s can be obtained
using: dr
p s ( s )  pr ( r ) (3.3  3)
ds
• The PDF of the output intensity variable s is determined by the PDF of input r and
the transformation function [ recall that r and s are related by T( r)].
r
s T (r ) ( L  1)  pr ( w)dw (3.3  4)
0
The right side of this equation is CDF (Cumulative distribution function)
of random variable r.
1) Transformation function of e.q. 3.3-4 satisfies condtion (a)
because the area under the function cannot decrease as r increases
2) When the upper limit of this eq. is r=(L-1), the integral evaluates to 1,
this satisfies condition (b)

30
Histogram Equalization (page 148)

nk
Normalized histogram p( rk ) 
MN
nk : the number of pixels in the image of
size M N with intensity rk
Continuous case:
r
s T ( r ) ( L  1)  pr ( w) dw Eq. (3.3-4)
0
The right side of the eq. is recognized as the cumulative distribution
function (CDF) of random variable r.

Discrete values:
k
sk T ( rk ) ( L  1) pr ( rj ) Eq. (3.3-8)
j 0
k nj L 1 k
( L  1)   nj k=0,1,..., L-1
j 0 MN MN j 0
31
Example 3.5 : Histogram Equalization ★★★
(page 148)

Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN =


4096) has the intensity distribution shown in following table.
Get the histogram equalization transformation function and give
the ps(sk) for each sk.

32
Example: Histogram Equalization
• Use eq. 3.3-8 for sk :
Discrete values:
k
sk T ( rk ) ( L  1)  pr ( rj ) Eq. (3.3-8)
j 0

Solution:
0
s0 T (r0 ) 7 pr (rj ) 7 0.19 1.33  1
j 0
1
s1 T ( r1 ) 7  pr ( rj ) 7 (0.19  0.25) 3.08
j 0
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
33
Example: Histogram Equalization

34
Histogram Equalization Ex3.5

rk nk pr(rk) sk=T(rk) sk rk ps(sk) rk

r0=0 790 0.19 s0=1.33 → 1 ← 0 ← 0


r1=1 1023 0.25 s1=3.08 → 3 ← 1 ← 0.19 0
r2=2 850 0.21 s2=4.55 → 5 . 2 ← 0
r3=3 650 0.16 s3=5.67 → 6 . 3 ← 0.25 1
r4=4 329 0.08 s4=6.23 → 6 . 4 ← 0
r5=5 245 0.06 s5=6.55 → 7 . 5 ← 0.21 2
r6=6 122 0.03 s6=6.86 → 7 . 6 ← 0.24 3,4
r7=7 81 0.02 s7=7 → 7 . 7 ← 0.11 5,6,7
35
36
Histogram Equalization

Exercise:

Use mat lab, and Implement histogram equalization?

Compare the original image and the reconstructed image


with histogram equalization?

37
Histogram Equalization
 Input image vs Histogram equalized image

“lenna.bmp”
image and
histogram

“lenna.bmp”
image after
histogram
equalization

and its histogram

38
Histogram Equalization
 Input image vs Histogram equalized image

11.08
“camera man”
image and
histogram

“camera man” image


after histogram
equalization

and its histogram

39
Histogram Equalization
 Histogram equalization does not give us always better images.

“child” image and


histogram

“child” image
after histogram
equalization

and its histogram

40
Question
Is histogram equalization always good?

No

41
Thank You !!!

42

You might also like