MIP Lecture 3
MIP Lecture 3
Intensity Transformations
and Spatial Filtering
1
Preview
• The principal objective of enhancement
– to process an image so that the result is more suitable than the
original image for a specific application.
ex) A method that is quite useful for enhancing X-ray images may
not necessarily be the best approach for enhancing pictures of Mars
transmitted by a space probe.
0
0 Input r L-1
2
Some Basic Intensity Transformation
Functions
- Image Negatives
• s=L-1-r
• (0,1,2,…254,255)à(255,254,…,1,0)
L-1
T
Output s
0
0 Input r L-1
Log Transformations
• s=c log(1+r)
• Compresses the dynamic range of the image
ex) to visualize Fourier spectra
• to expand the values of dark pixels in an image while
compressing the higher-level values. (and vice versa)
L-1
Output s
0
0 Input r L-1
3
Power-Law (Gamma) Transformation
• s=c rg
• Compresses the dynamic range of the
image
– the exponent is called gamma (g)
– gamma correction
– i.e. CRT monitors have an intensity to
voltage response which is a power-law
with gamma 1.8-2.5
• As in the case of the log transformation,
power-law curves with fractional values of y
map a narrow range of dark input values
into a wider range of output values, with
the opposite being true for higher values of
input levels
Gamma Correction
• Useful to compensate for the
non-linear response of monitors
4
ex) MRI image (surface coil)
and aerial image (washed-out)
g=0.6 g=3.0
Piecewise-Linear Transformations
- Contrast Stretching
• Adjust brightness and contrast
• Expand the range of intensity levels
5
Example : CT image
(Window/Level)
Intensity-Level Slicing
• Highlighting a specific range of intensities
6
Histogram Processing
• The number of pixels having dark image
• Useful for
– gathering image statistics
– spatial domain (real-time)
processing low-contrast
Example : CT image
The meaningless background should be excluded.
tissue
bone
7
Histogram Equalization
• s=T(r)
• PDF : pr(r), ps(s)
ds dT ( s ) d r
= = ( L - 1) [ ò pr ( w)dw] = ( L - 1) pr (r )
dr dr dr 0
dr 1 1
p s ( s ) = pr ( r ) = pr ( r ) =
ds ( L - 1) pr (r ) L - 1
Example
Intensity distribution and histogram for
a 3-bit 64x64 image
r n pr(r)=n/(64x64) s
0 790 0.19 1
1 1023 0.25 3
2 850 0.21 5
3 656 0.16 6
4 329 0.08 6
5 245 0.06 7
6 122 0.03 7
7 81 0.02 7
0
s0 = T (0) = 7å pr ( j ) = 7 pr (0) = 1.33 » 1
j =0
1
s1 = T (1) = 7å pr ( j ) = 7{ pr (0) + pr (1)} = 3.08 » 3
j =0
8
Examples
Example : CT image
9
Histogram Matching (Specification)
• Given histogram pz(z)
r
• s = T (r ) = ( L - 1) ò pr ( w)dw: histogram-equalized
0
z
s = G ( z ) = ( L - 1) ò p z ( w)dw
0
z = G -1[T (r )] = G -1 ( s )
M -1 N -1
1
m=
MN
åå f ( x, y)
x =0 y =0
• Nth moment of r
L -1
m n (r ) = å (ri - m) n p (ri )
i =0
MN x =0 y =0
• Local statistics
– Good measures for spatially-adaptive processing
10
Example of Local Processing
Homework #2
• Enhance the contrast of the CT image
1) Apply global histogram equalization.
2) Apply the same algorithm as the example.
- Choose appropriate E, k0, k1, k2
3) Compare both results.
11
Fundamentals of Spatial Filtering
• Spatial filtering ⇔ Frequency domain filtering
• filtering operations that are performed directly
on the pixels of an image
• Operation between a neighborhood
• Define a 2D filter with the following properties
– linear
– Space-invariant
– finite impulse response (FIR) ß Convolution
12
Linear Convolution
• Space-invariant linear system
Remarks
• Filtering is linear because each output pixel value is computed as a
linear combination of a set of input pixel values.
• Filtering is space invariant because filter coefficients are independent
on the point of application (x, y).
• The output has size (M+m-1)×(N+n-1) samples, but practically
(M×N)
• The sum of filter coefficients?
– Normalization
– Output : overflow, underflow
• Computational complexity ∝ M×N×m×n
– why 3×3 convolution is popular
• The borders of the image?
– exclude borders à effective output size (M-a)×(N-b)
– add padding to the input image with average gray level
– bypass (replace with input pixels)
– fill zeros
13
Smoothing Spatial Filters
• Blurring to remove small details and extract a large
object
• Noise reduction
• Low pass filter – remove high frequency components
• The most simple smoothing filter : Averaging filter
1 1 1 1 1
1 1 1 1 1 1 1 1
1/9 × 1 1 1 1/25 × 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1
• Weighted average
1 2 1
1/16 × 2 4 2
1 2 1
Weighted Average
K=4 K=1
14
Window Size Effect of Average Filter
3x3
5x5 9x9
15x15 35x35
15
Order-Statistic (Nonlinear) Filters
• Based on ordering the pixels
• ex) maximum, minimum, median filters
• Nonlinear filter
• Median filter
– Quite popular
– Excellent noise-reduction capabilities with less blurring (edge-
preserving filter)
– In particular, effective to remove impulse noise (salt-and-
pepper)
– Remove defective pixels
3
4
5, 4, 5.5, 100, 6, 7, 8, 7, 7.5
2
1
4, 5, 5.5, 6, 7, 7, 7.5, 8, 100 1 0.67
0.5
Median = 7
3x3 median 3x3 averaging
Average = 16.7
Examples
16
Blurring Filter and Median Filter
x1 x2 x3 x10 x∞
17
The 1st and 2nd Order Derivatives
18
Examples of the Laplacian Operator
clipping scaling
0 -1 0
-1 4 -1
0 -1 0
c=1 c=1
0 -1 0 -1 -1 -1
-1 5 -1 -1 9 -1
0 -1 0 -1 -1 -1
g(x,y)=f(x,y)+∇2f=(1+∇2)f(x,y)
k=1
Highboost
(k=4.5)
19
Gradient – The 1st Derivative
• Gradient é ¶f ù
é g x ù ê ¶x ú
Ñf º grad ( f ) º ê ú = ê ¶f ú
ëg y û ê ú
êë ¶y úû
• Gradient image
M ( x, y ) =| Ñf |= g x2 + g y2 » | g x | + | g y | z1 z2 z3
z4 z5 z6
• The simplest approximation
gx=z6-z5, gy=z8-z5 z7 z8 z9
Sobel Operators
-1 0 1 -1 -2 -1
• gx=f(x,y)* -2 0 2 gy=f(x,y)* 0 0 0
-1 0 1 1 2 1
-1 0 1
-1 0 1 -1 0 1
-1 0 1
• M(x,y)=|gx|+|gy|
20
Example
The edge defects are quite visible, but with the added advantage that
constant or slowly varying shades of gray have been eliminated thus
simplifying considerably the computational task required for
automated inspection. à preprocessing step
21
Fuzzy Set
• “Crisp” set : 1 or 0, true or false (bi-valued
Boolean logic)
• Membership functions
– Set of “young” people
Several Definitions
A∪B A∩B
22
Examples of Membership Functions
23
Example
24
Example
25
Homework #3
• Improve the SNR of the noisy MR image below by use of a 5x5
averaging filter
• Preserve edges as much as possible
– Design a simple adaptive filter (space-variant)
• Get an edge image of the 2nd noisy image using the Sobel mask
• Change the filter coefficient K according to the edge strength
– K=1 for a flat area (no edge)
– Larger K for a strong edge
• Compare the result with the original images with/without noise
1 1 1 1 1
1 1 1 1 1
1/(K+24) × 1 1 K 1 1
1 1 1 1 1
K=1 1 1 1 1 1
Image without noise Image with noise
(for comparison)
26