chương 1: xử lý ảnh
Trang 1DIGITAL IMAGE PROCESSING
CHAPTER 3
Image Enhancement
Trang 2
3.1 Introduction
Objective of Image Enhancement : to process an image so that the processed image is more suitable than the original image for a specific application
Relation of Enhancement and Restoration : in image restoration, an original image has been degraded and the objective is to make the processed image resemble the original image as much as possible
Classification of Enhancement Techniques
Point Operations : on each pixel, the input gray level is mapped into a new one
Sapatial Operations : spatial filtering
Transform Operations : manipulation in transform domain
Trang 3
Digital Image Processing Image Enhancement
3.2 Point Operations Contrast Stretching
« Key Idea : to increase the dynamic range of the gray levels in the image being
processed » A r Olu Osu<a Ỳ V; v={B(u-a)+v ,asu<b 8 y(u—b)+v_ ,bSu<L Vo —— etre a : °
| where wu : input gray level
0 a b L Pi
v: output gray level Fig 3.2.1 Contrast stretching transformation
¢ Clipping : a special case of contrast stretching where a =y =0 (Fig 3.2.1)
useful for noise reduction of the input signal known to lie in fa, 5] should be performed on images that will be represented with a finite number of bits, for example, with unsigned character
Trang 4« Thresholding : a special case of clipping where a=b=tf
(a) (b) (Cc) (d)
Fig 3.2.2 (a) Original Image, (b) Contrast Stretching a =80,b=175,v, =40,v, = 215), (c) Clipping, (d) Thresholding (tf = 128)
Other Simple Operations
« Image negative: v=L—u, u,ve [0,L]
(a) (b) (Cc)
Fig 3.2.3 (a)(c) Original images, (b)(d) negative images
Trang 5JL Peas! : CÔN Image Enhancement n= log (h) ; vxC ee Ã< a pha 2k2 ae 4 m © te us - 4 bare’, % is pr.) 1 e \ I> stl ue te “i42 eeu AD tes rẻ | - ‘ ea a, ` u | )
e (a) O-bit, , (h) 7-bit
Jif u 1 imag te ey oY Sa Wn ital igit (b) (ft) fs na eh bs =e eh, or ee * 6 ‘ RE NT tờ af Se SSS SOAR Die re etter ete Ae v22: ` xế ch .2.4 8-bit planes of a d ^ 2) a) ơ, dS Fi ( Apr or s -~ " er Ee aatey Pe iG x© et s2 ry a Lye a te ees S% (z2 CS án ớt ean 1 Bint ote
Bit Extraction (Bit-plane
Trang 6
« Range Compression: The dynamic range of a unitarily transformed image is so large that only a few pixels are visible The dynamic range can be compressed via the logarithmic transformation
v=clog,(I+|w|) where c isascaling constant
« Image Subtraction: In many imaging applications it is desired to compare two images A simple but powerful method is to align the two images and subtract them
ví j) = ax|u ( j)—u,(ỉ, j)|+Ð
where (i, 7) means each pixel position, and uw, and u, are two images being compared
Trang 7Digital Image Processing Image Enhancement
Histogram Processing
« Histogram of a Digital Image : represents the relative frequency of occurrence of the various gray levels in the image The histogram gives an estimate of the probability of occurrence of each gray level
« Histogram Equalization : The goal is to obtain a uniform histogram for the output image Consider an image pixel value u20 to be a random variable with a continuous pdf p(w) andcdf F (6)=P[u <6] Then the random variable
vA F(u)=[ p,(x)dx (3.2.1)
will be uniformly distributed over (0,1)
(Proof) From Eq (3.2.1), the derivative of v with respect to wu is
dv |
~= p (u) (3.2.2)
du
Substituting Eq (3.2.2) into the relation of p,(v) and p,(u):
du l |
P.(v)= p,(u)— = p,(u) =] (3.2.3)
dv p,(u)
Trang 8(Implementation of histogram equalization on digital image)
Suppose the input uw hasa histogram A(x,), 7=0,1, -,2—1 Then we obtain
p(x) = Le i=O,l, -,L—-1 (3.2.4)
>„h(x,) ja)
The output v ,also assumed to have L levels, is given as
v= Dp.)
(v-v_) (3.2.5)
v =/nt 1y t=+03 —V
where v 1s the smallest value of w obtained from Eq (3.2.5)
c Uniform * — ” Đb » P(X) |_——w L——y quantization Pu(x)
Fig 3.2.5 Histogram equalization transformation
Trang 9Image Enhancement
Digital Image Processing
(Example) Histogram equalization for the given histogram A(u) of a 3-bit image u 0 | 2 3 4 5 6 7 A(u) 790 1023 850 656 329 245 122 81 pu) 0.19 0.25 0.21 0.16 0.08 0.00 0.03 0.02 v 0.19 0.44 0.65 0.81 0.&9 (0.95 0.98 1.00 v 0 2 4 5 6 7 7 7 Đ« 0.19 0.25 0.21 0.16 0.08 0.21 v= Š p(X, ) v =Int oe —l)+ as| il ila (c) (đ) (a) (b)
Fig 3.2.6 Histogram equalization (a) original image, (b) original histogram (x-axis: [0,255], y-axis: [0, 255]), (c) equalized image, (d) equalized histogram
Trang 10
« Histogram Specification : Suppose the random variable ¿>0 with pdf p,(w) is to be transformed to v2=0 such that it has a specified pdf p,(v) For this to be true, we define a uniform random variable
w= [’ p,(x)dx = F (u) (3.2.6)
That also satisfies the relation
w= p(x)dx= F(v) (3.2.7)
Eliminating w, we obtain
v= F"(F(w)) (3.2.8)
(Implementation of histogram specification on digital image)
H w min —“p} ¥ p.(x,) of, 20} Fa Le P u(X/) x,=0
Fig 3.2.7 Histogram specification
Trang 11
Digital Image Processing Image Enhancement
(Example) Histogram specification for the given histograms (pdf) p,(w) and p.(v) of a 2-bit ima (a) x, =) (b) (Cc) u 0) l 2 3 p,(u) 0.25 0.25 0.25 0.25 p,(v) 0.00 0.50 0.50 0.00 vụ 0.25 0.50 0.75 1.00 W, 0.00 0.50 1.00 1.00 we 0.50 0.50 1.00 1.00 vy =n l I 2 2 w= Š p,(x,) and Ww, (ul Mt (d)
Fig 3.2.8 Histogram specification (a) Original image, (b) Original histogram (c) Specified image (triangular pdf), and (d) Histogram of the specified image Lư
Trang 12
3.3 Spatial Operations
Smoothing
Âô Smoothing filters are used for blurring and for noise reduction Blurring is used in preprocessing steps, such as removal of small details from an image prior to (large) object extraction, and bridging of small gaps in lines or curves
Spatial Averaging
¢ Each pixel is replaced by a weighted average of its neighborhood pixels, that 1s,
vữứn,n)= 3S a(k,l)y(m—k,n—]) (3.3.1)
(kJ)
where y(m,n) and v(m,n) are the input and output images, respectively, W is a suitably chosen window, and a(k,/) are the filter weights {a(k,/)} is an impulse response called spatial mask A common class of spatial averaging filters has all equal weights, giving
l
v(m, n) =—— YY v(m—k,n-1) (3.3.2)
we (LJ
where a(k,/)=1/N, and N,, is the number of pixels in the window W Fig 3.3.1 shows some spatial averaging masks
Trang 13Digital Image Processing Image Enhancement
ITTT] ITTITI IT2Tì
x[1|[I|l1l —>|I|2|1| —>x|2{1412
9 10 ~ 16 ~ ~
iti iti |i 121!
(a) (b) (c)
Fig 3.3.1 Spatial averaging masks
Spatial averaging is used for noise smoothing, low-pass filtering, and sub-sampling of images Suppose the observed image ts given as
y(m,n) = u(m,n) +N(m, n) (3.3.3)
where 1(m,n) is white noise with zero mean and variance O° Then the spatial average of Eq (3.3.3) yields
v(m) = — 33 (m— k,n—]) +TỊ(m.n) (3.3.4)
(tlie
4
where T[Ún,m) is the spatial average of †J(m.n) It can be shown that TJm,n) has
Zzcro mean and varlance ỞØ ` =Ø”/N,, that ¡s, the noise power is reduced by a
factor equal to the number of pixels in the window W
Trang 14(a) (b) (C) (d) Fig 3.3.2 Image averaging (a) noise (biasing & contrast stretching),
(b) noisy image, (c) 3x3 averaging, and(d) 5x5 averaging
(a) (b) (C) (d)
Fig 3.3.3 (a) Original image, (b) — (d) results of spatial filtering with a mask of Fig 3.3.1 (a) —(c)
Trang 15Digital Image Processing Image Enhancement
Median Filtering
The input pixel is replaced by the median of the pixels contained in a window W around the center pixel, that 1s,
v(m, n) = median { y(m—k,n—-1), (k, lye W} (3.3.5) If N, is even, then the median is taken as the average of the two values in the
middle
Example 3
Let { y(m)} ={2,3,8,4,2} and W =[-1,0,1] The median filter output is given by
v(0)=2 (boundary value), v(1) = median} 2,3,8} = 3 v(2) = median} 3,8,4} = 4, v(3) = median{S.4.2} = 4 v(4) =2 (boundary value)
Hence {v(m)}= {2,3,4,4,2} If W contains an even number of pixels — for
example, W =[-1,0,1,2] — then v(0)=2, v(1l)=3, v(2) =median{2,3.8,4} =3.5,
v(3) = median{3,8,4,2} = 3.5, and v(4)=2 gives {v(m)} = {2,3,3.5,3.5,2}
Trang 16Properties of median filter
1 Itis a nonlinear filter, that is,
median x(m) + y(m)} # median x(m)} + median y(m)} 2 It reduces impulsive noise well and also preserves edges well
19,0,0,1,0,0,0} ~ (0.0.0.0.0.0.0) ¡0,0,0,1,1,1,1) — (0,0,0,1,1,1,13
Fig 3.3.4 Examples of median filtering (ex W =[-—1,0,1])
(a) (b) (Cc) (d)
Fig 3.3.5 (a) Original image, (b) image with binary noise (-128 and 128 for 10 %),
(c) averaging with 3x3 mask, and (d) 3x3 median filtered image
Trang 17Digital Image Processing Image Enhancement
Sharpening (Crispening)
e« Psychophysical experiments indicate that a photograph or visual signal with accentuated or crispened edges is often more subjectively pleasing than exact photometric reproduction
«Ắ Unsharp Masking : The unsharp masking technique is used commonly in the printing industry for crispening the edges A signal proportional to the unsharp, or low-pass filtered, version of the image is subtracted from the image This is equivalent to adding the gradient, or a high-pass signal, to the image (See Fig 3.3.7) The unsharp masking operation can be represented by
v(m.n) =(A +1)ju(m,n)—Ah,,u(m.n)}, A>O
=u(m,n)+Alu(m,n)—h,,u(m,n)] (3.3.6) =u(m,n)+Ah,,u(m,n)
where h,, and h,, mean low-pass and high-pass filters, respectively The constant A is typically chosen as 0.25 ~ 0.33 Eq (3.3.6) also called high-boost or high-frequency-emphasis filtering
Trang 18
Signal Low-pass High-pass
mf a, 4 (3) Lf (4) : Am xá (a) (b) (c) (d)
Fig 3.3.7 (a) Original signal, (b) low-pass filtering, (c) (1) — (2), (d) (1) + A(3)
(a) (b) (C) (d)
Fig 3.3.8 (a) Original image, (b) low-pass filtered image, (c) absolute image of ((a) — (b)), (d) (a) — 0.33 x (c)
Trang 19Digital Image Processing Image Enhancement
« Statistical Differencing : The statistical differencing, suggested by Wallis, forces the enhanced image to a form with desired mean and standard deviation The
operation is defined by
oO
=———t—— _ —B)n 33:7
v(m,n) G.x) £ữÐ [w(m.m) — H(m.n)]+[ mu +(1— B)H(m.n)]} — ( )
where O(m,n) and H(m,m) represent local mean and standard deviation, oO, and m, denote desired mean and standard deviation, @ is a gain factor that prevents overly large output values when O(m,n) is small, and B is a factor controlling the ratio of the edge to background intensities The constant O,, m d # 3 œ,and are typically chosen as 8.5, 128, 1/6, and 0,1
(a) (b) (c) (d)
Fig 3.3.11 (a)(c) Original image, (b)(d) images after statistical differencing operation
Trang 20Homomorphic Filtering
Homomorphic filtering is a useful technique for image enhancement when an image is subject to multiplicative noise or interference
One can reduce the dynamic range and increase the local contrast of an image to be enhanced by applying a homomorphic filtering to an illumination-reflectance image model Based on the image model, an input image u(m,n) can be expressed as
u(im,n) = i(m,n)r(m, n) (3.3.8)
where i(m,n) represents the illumination and r(m,n) represents the reflectance Assumption : i(m,n) 1s primary contributor to the dynamic range, varying slowly
r(m,n) is primary contributor to local contrast, varying rapidly To separate i(m,n) from r(m,n), a logarithmic operation is applied to Eq (3.3.8)
logu(m,n) = logi(m,n) + logr(m,n) (3.3.9)
Low-pass filtering logu(m,n) — logi(m,n) High-pass filtering logu(m,n) — logr(m,n)
Trang 21Digital Image Processing Image Enhancement
logi(m,n) is attenuated to reduce the dynamic range while logr(m,n) is emphasized to increase the local contrast The processed logi(m,n) and
logr(m,n) are then combined and the result is exponentiated to get back to the
image intensity domain œ<1
LPF LH yếo
u(m,n) yb exp -—Pv(,n)
HPE |—**r y,
BI
Fig 3.3.12 Homomorphic system for image enhancement
(a) (b) [0,285]
Fig 3.3.13 Results of homomorphic filtering (a) original image, (b) homomorphic result
Trang 22
Zooming (Interpolation)
« Various interpolation techniques can be used in changing the size of a digital image to improve its appearance when viewed on a display device
« Digital zooming can be performed by using a continuous interpolator which reconstructs a continuous signal from samples This operation is described in Fig
3.3.14 u( n) Continuous v( x) v( m) Interpolator | -— _}_ Re-sampling | _» - Zoomed Se h (0m) Continuous
sequence ¢ Signal sequence
Fig 3.3.14 Description of digital zooming by continuous interpolator The continuous signal interpolated 1s given as
v(x)= 3 ,(n)h (x — n) (3.3.10)
where A (x) denotes a continuous interpolation function
Trang 23Digital Image Processing Image Enhancement
1 Sync-Function Interpolator (not spatially limited):
sin 70x 7x h (x)= (3.3.11) {a| Son 2 N th-order Interpolator: Zero-order Interpolator | XS (b) Square (¢) Triangle h.,(x) =1 on (-1/2,1/2] dit
First-order Interpolator LS N ST ÔN
| oh ¬ t = i r : a
h(x) =h,,(x)* h,, (x) mm oie " spting
Second-order Interpolator Fig.3.3.15 Continuous interpolation functions
h.,(x) =h,(x)*h,,(x)
Cubic B-spline (Third-order) Interpolator
xf/2-x +2/3, x{<1
h (x)=h (x)*h (x)= : | | (3.3.12)
—|x|} /6+x -2|x|+4/3, 1s) x\<2
The above interpolation functions are shown in Fig 3.3.15
Trang 24
¢ Two-dimensional Continuous Interpolation
1 Separable Interpolator
h.(x,y)=h.(x)-h,(y)
2 Bilinear Interpolator
v(x, vy) =(1— Ax)(1 — Ay )u(m,n) +(1— Av) Ayu(m,n +1)
+ Ax (1 —Ay)u(m +1,n) + Ax Avu(m +1,n +1) where Av=x— and Ay = y—n
e L:1 Interpolator
Based on the theory of digital signal processing, the L:1 interpolator which
increases sampling rate by L consists of upsampler, low-pass filter, and amplifier with gain of L It is shown in Fig 3.3.16
y(m) | LPF : u(n) —* 1| ——* h(m) —x >— v(n) €quence Zoomed amplifier sequence
Fig 3.3.16 Block diagram of L:1 interpolator
Trang 25Digital Image Processing Image Enhancement
The upsampler produces a sequence
(m) u(m/L), if m is integer multiple of LZ
m)=
Ỷ 0 , otherwise (zero appending)
=u([m/ L])
Then the output sequence v(m) can be written as
v(m) = L¥ h(k) y(m—k) = LY h(k)u({(m— k)/ L)) (3.3.13)
Where the interpolation filter A(k) in general is a symmetric LPF and }{A(k)=1 For example, any QMF filter can be selected as a good interpolation filter
Relation between continuous interpolator and L:1 interpolator
Setting x =m/ L, the Eq (3.3.10) becomes
vựn(L)= 3,u(n)h, (m/L—n) (3.3.14)
Let k/L=m/L—n Then
v(m/ L)= Lh(k /L)w([(m— k)( L]) = L 2„h,(k/L)w([Um~ k)/L]) (3.3.15)
Comparing Eq (3.3.15) with Eq (3.3.13), we can see that
h(n) =—h (n/L) (3.3.16)
Trang 26
e L:! Decimator
The block diagram of L:1 decimator which reduces sampling rate by L is shown in
Fig 3.3.17 LPF ‘ un) —* h(n) _"Đ „it —> v(m) Sequence Decimated downsampler sequence Fig 3.3.17 Block diagram of L:1 decimator The decimator sequence v(m) can be written as
v(m) = 3 h(k)u(Lm— k) (3.3.17)
(a) (b) (Cc) (d)
Fig 3.3.18 Results by 2:1 Interpolators (a) square, (b) triangular, (c) bell, and (d) cubic B-spline
Trang 27Digital Image Processing Image Enhancement
3.4 Transform Operations
« Linear filtering in frequency domain is straightforward We simply compute the Fourier transform U(k,/) of the image to be enhanced, and multiply the result by a filter transfer function H(k,/)
V/(k,l)= H(&k.lU(&.l)
Then we obtained the enhanced image by taking the inverse Fourier transform of
V (k,l)
« Image enhancement by transform filtering
u(m,n) Unitary v(k,D Point v*(k,D) Inverse u*(m,n)
——+» transformation }+——% operations +=} _ transformation }———_»
AUA' #C) AV(A)
Fig 3.4.1 Image enhancement by transform filtering