Lecture 2
Lecture 2
Spring 2020
Readings: Chapter 2 (sections 2.5 and 2.6), Chapter 3 (sections 3.1 and 3.2)
1 / 49
How to read: Minimum distraction! More Notes!
Table of Content
●
Relationships Between Pixels
●
Mathematical Tools for DIP
●
Basics of Intensity Transformations and Spatial Filtering
●
Basic Intensity Transformation Functions
2 / 49
Neighbors of a Pixel
●
The 4-neighborhood of pixel p(x,y) is the set:
{(x-1, y), (x+1, y), (x, y-1), (x, y+1)}
or {(i, j): |x-i| + |y-j| = 1}
● The two pixels p and q are 4-adjancent (or connected) if q is in N4(p) or p
is in N4(q).
●
The 8-neighborhood of pixel p(x,y) is the set:
{(x-1, y), (x+1, y), (x, y-1), (x, y+1),
(x-1, y-1), (x+1, y-1), (x-1, y+1), (x+1, y+1)}
or {(i, j): max(|x-i|, |y-j|) = 1}
● The two pixels p and q are 8-adjancent (or connected) if q is in N8(p) or p
is in N8(q).
3 / 49
Paths Between Pixels
●
A digital path from the pixel p(x,y) to the pixel q(s,t) is a sequence of pixels
with coordinates:
●
The adjacency can be defined using 4- or 8-neighborhood
●
Length of a path: number of edges on the path
● Closed paths: (x0, y0) = (xn, yn).
●
Ambiguity of a path:
8-neighborhood 4-neighborhood
4 / 49
Paths Between Pixels
●
Assuming S a subset of pixels in an image, pixels p and q
are connected in S if there exists a path between them
consisting entirely of pixels in S. p
●
For any pixel p in S, the set of pixels that are connected to S
it in S is called a connected component of S. q
●
If it only has one component, and that component is
connected, the S is called a connected set.
●
Assuming R a subset of pixels in an image, R is called a
region of the image if R is a connected set. Two regions Ri
and Rj are adjacent if their union forms a connected set.
Otherwise they are disjoint.
●
The definitions are dependent on the how the
neighborhood is defined.
5 / 49
Paths Between Pixels
Background
R1 R2
R3
6 / 49
Distance Measures
●
For pixels p(x,y), q(u,v) and s(w,z), D is a distance function or metric if:
●
The Euclidean distance between p and q is defined as:
7 / 49
Element-wise vs. Matrix Operations
●
An element-wise operation involving one or more images is carried out on
a pixel-by-pixel basis.
●
The element-wise product of two 2-by-2 images is:
●
The matrix product of the same images is:
8 / 49
Linear vs. Non-Linear Operations
●
Assume a general operator that produces an output image, g(x,y), from a
given input image f(x,y):
●
The operator is said to be linear, if it satisfies two properties:
– Homogeneity
– Additivity
●
For example mean operator is a linear operator, while max operator is not.
9 / 49
Arithmetic Operations
●
Arithmetic operations between two images are defined as:
●
All are element-wise operations, performed between corresponding pixel
pairs in f and g for x=0,1,2,…,M-1 and y=0,1,2,…, N-1, resulting in images
of the same size as inputs.
●
They are defined for input images of the same size.
10 / 49
Arithmetic Operations: Examples
●
Assume that in image acquisition, zero-mean uncorrelated noise is added
to the noiseless image:
g (x , y)=f ( x , y)+η ( x , y)
●
If noise is zero-mean and uncorrelated with the noise-less image,
averaging K different noisy images can help is reducing the noise:
11 / 49
Arithmetic Operations: Examples
●
Another example of arithmetic operations is by using subtraction to
compare images.
12 / 49
Arithmetic Operations: Examples
●
Digital Subtraction Angiography (DSA)
13 / 49
Arithmetic Operations: Examples
●
Image multiplication and division can be used for shading correction.
●
Assume an imaging sensor produces images that are modeled as the
product of a perfect image f(x,y), times a shading function h(x,y):
g (x , y)=f ( x , y)h(x , y)
●
If h(x,y) is known, or could be estimated, then:
f ( x , y)=g( x , y )/ h(x , y)
14 / 49
Technical Note
●
Since there is a range of values that can be shown using any specific
number of bits, it is likely that image processing procedures result in values
that are out of this range.
●
For example, subtraction of two 8-bit images can range from -255 to +255,
which is out of bound for an 8-bit image.
●
Clipping or scaling is necessary, especially when saving the images.
●
To map the processed image to the desired range:
g( x , y)−g min
g s ( x , y)=K
g max−g min
●
For an 8-bit image, K=255.
● gmin and gmax are the smallest and largest intensity values of the image
g(x,y) respectively.
15 / 49
Set Operations
●
Set: a collection of distinct objects.
16 / 49
Set Operations
●
How set operations can be applied to images? Let’s see an example.
●
Complement of an image can be defined using set operations as:
●
K is equal to the maximum intensity values in the image. In an 8-bit image,
K=255.
●
The union of two grayscale sets A and B with the same number of
elements is defined as:
17 / 49
Set Operations
18 / 49
Logical Operations
●
Logical operations deal with TRUE (1) and
FALSE (0) variables and expressions, which
means that we can apply them to binary
images with foreground (1-valued) pixels and
background (0-valued) pixels.
●
A binary image can be considered as a Venn
diagram with regions of 1-valued pixels
considered as sets.
19 / 49
Spatial Operations
●
Spatial operations work directly on the pixels of an image.
●
Three types of spatial operations:
– Single-pixel operations
– Neighborhood operations
– Geometric spatial transformations
20 / 49
SOs: Single-Pixel Operations
●
To alter the intensity of pixels individually using a transformation function T,
where z is the intensity of a pixel in the original image and s is the mapped
(transformed) intensity of the corresponding pixel in the processed image.
s=T (z)
●
Examples for negative (complement), contrast stretching and thresholding
of images, respectively.
21 / 49
SOs: Neighborhood Operations
1
g (x , y)= ∑
mn (r ,c)∈S
f (r , c)
xy
22 / 49
SOs: Geometric Spatial Transformations
●
Geometric operations of digital images consists of two basic operations:
– Spatial transformation of coordinates;
– Intensity interpolation for assigning intensity values to spatially
transformed pixels.
●
Affine Transformation provides scaling, translation, rotation and
shearing.
●
Affine transformations preserve points, straight lines, and planes.
[ ] [][ ][ ]
x' x a11 a12 a13 x
y ' = A y = a21 a22 a 23 y
1 1 0 0 1 1
23 / 49
SOs: Geometric Spatial Transformations
●
Different transformations can be concatenated by calculating the product
of their transformation matrices.
24 / 49
SOs: Geometric Spatial Transformations
●
To complete the process, we assign intensity values to the spatially
transformed locations by means of intensity interpolation.
●
Basic interpolation methods are:
– Nearest neighbor
– Bilinear interpolation (4 nearest neighbor pixels are needed)
i=0 j=0
25 / 49
Image Transforms
●
Some image processing tasks are best formulated in a transform domain,
for example Fourier domain. A general 2D linear transform, T(u,v) is
formed as: M −1 N −1
T (u , v)= ∑ ∑ f (x , y)r (x , y , u , v)
x=0 y=0
where f(x,y) is the input image, r(x,y,u,v) is forward transformation kernel,
and the equation is evaluated for u=0,1,2,…,M-1 and v=0,1,2,…,N-1.
●
We can recover f(x,y) using the inverse transform of T(u,v) as:
M −1 N −1
f ( x , y)= ∑ ∑ T (u , v) s( x , y , u , v)
u=0 v =0
26 / 49
Image Transforms
●
The forward transformation kernel is separable if:
r ( x , y ,u , v)=r 1 ( x ,u)r 2 ( y , v)
●
The kernel is symmetric if:
r ( x , y ,u , v)=r 1 ( x , y)r 1 ( y , v)
●
The general approach for working in the linear transform domain can be
summarized as:
27 / 49
Image Transforms
●
The forward and inverse kernels of
the Fourier transform are:
− j 2 π (ux / M + vy / N )
r ( x , y ,u , v)=e
1 j 2 π (ux / M + vy / N )
s(x , y ,u , v)= e
MN
●
The image is corrupted by a
sinusoidal interference, which can
be seen in the Fourier domain as
two bright dots. By applying a
mask to the Fourier transform, the
interference can be removed.
28 / 49
Image Intensities as Random Variables
●
What is the probability of an intensity level in an image?
● Let’s have zi, for i=0,1,2,…,L-1 as the values of all possible intensity levels
in an image.
29 / 49
Image Intensities as Random Variables
●
Like any other random variable, we can determine important
characteristics by using the probabilities.
●
The mean (average) intensity is:
L−1
m= ∑ z k p( z k )
k=0
●
The variance of the intensities is:
L−1
σ =∑ ( z k −m) p ( z k )
2 2
k =0
●
Generally, the n’th central moment of random variable z about the mean is:
L−1
μn ( z)= ∑ ( z k −m) p( z k )
n
k =0
2
where μ0 ( z )=1, μ1 ( z)=0, μ 2 (z )= σ .
30 / 49
Intensity Transformations and Spatial Filtering
Spatial Frequency
Domain Domain
31 / 49
Type I: Intensity Transformations
●
Intensity transformation: s=T (r)
– Operating on single pixels
●
Example: thresholding & contrast
stretching
– The transformation is independent of
locations, determined only by the
intensity values.
●
Procedure
– Check the pixels in a raster scanning
method
– Calculate the new value for each
pixel
– Update the intensity
– Repeat for every pixel
32 / 49
Type II: Intensity Transformations
●
Spatial filtering: g ( x , y)=T [ f ( x , y)]
– In a neighborhood
●
Typically a square shape
●
Example: intensity averaging
●
Procedure
– Check the pixels in a raster scanning
method
– Calculate the new value for each pixel
– Update the intensity
– Repeat for every pixel
33 / 49
Basic Intensity Transformation Functions
●
Two types of low-quality images we
deal with here
– Too dark
– Too bright
●
Transformation function
s=T (r)
●
In digital images, r and s are discrete
values. We should have a look-up table
to define the function T(*).
34 / 49
Image Inversion
●
Compute the negative of an image:
s=(L−1)−r
●
Good to visualize the features when black areas are dominant in size.
Mammography images
35 / 49
Log Transformation
s log r
●
Transformation function
s=c log (1+r )
– Enhancing (stretching) dark areas (1,0)
– Compressing bright areas
Range: Range:
0 – 1.5X106 0 – 6.2
γ γ
●
The mathematical form: s=cr or s=c (r +ϵ )
for c >0 and γ >0
●
If γ <1 and s and r scaled to [0,1]
– Enhancing dark areas
●
If γ >1
– Enhancing bright areas
●
If γ =c=1
– Identity transformation
37 / 49
Application I: Gamma Correction
●
Many image devices (capturing, printing, and displaying) internally
undergo a “gamma” intensity conversion process:
γ
s^ =r
●
For instance, CRT devices 2.5
have a gamma value of
1.8 – 2.5, which tend to
darken the output images
0.4
●
Correction:
– Estimate gamma
38 / 49
Application II: Contrast Enhancement
●
Can be used to enhance dark or bright regions
– Dark regions 1
– Bright regions 1
●
Example on the right
– Original image (upper-left) is too dark
– Use 1
γ =0.6 , 0.4 , 0.3 , with c=1
39 / 49
Application II: Contrast Enhancement
●
When the input image is too bright,
it appears washed-out and detail
in the bright regions is unclear.
●
Example on the right
– Original image (upper-left) is
too bright
– Use 1
3.0, 4.0, 5.0
c 1
40 / 49
Summary
●
Identity (not useful)
●
Negative
●
Log and root functions
– For dark images (convex curves)
●
Inverse log and power functions
– For bright images (concave curves)
41 / 49
Contrast Stretching
Raw image
●
A process to expand the range of
intensity levels so that the contrast
between different intensity regions
are enhanced
●
The function must be increasing to
prevent intensity artifacts:
r1 r2 s1 s2
●
But may not be strictly increasing:
r1 r2 s1 s2
●
Features of interest are in a certain intensity range
●
We want to highlight the features while keeping the rest of the image dark
(left) or unchanged (right)
●
What if you want to keep the feature’s intensities while darkening the non-
features?
43 / 49
Intensity-Level Slicing: Example
●
Left: aortic image near the kidney area
●
Middle: the result of highlighting the blood vessels while making the other
regions dark.
●
Right: the result of keeping dark regions and blood vessels unchanged
while darkening the other regions
44 / 49
Bit-Plane Slicing
●
Consider 8-bit for each pixel
– The first (rightmost) bit of the intensity value at each pixel is the least
significant
– The last (leftmost) bit of the intensity value at each pixel is the most
significant
●
What we can do is to decompose each image into eight binary images
(only one bit for each pixel)
45 / 49
Bit-Plane Slicing
●
Example: the eight (binary) images from the least significant to the most
significant
●
Can be used for image compression
●
Idea: use only the most significant bits to “recover” the original image
●
Example:
47 / 49
What is Next: Histogram Processing and Spatial
Filtering
●
Image histogram
– Intensity distribution probability
nk
p( zk )
MN
●
Histogram processing, very useful in contrast enhancement and other
applications.
49 / 49