Background❖The Basics of Intensity Transformations and Spatial Filtering ➢ intensity also called a gray-level, or mapping transformation function Intensity transformation functions... ➢
Trang 1XỬ LÝ ẢNH TRONG CƠ ĐIỆN TỬ
Machine Vision
TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI
Giảng viên: TS Nguyễn Thành Hùng Đơn vị: Bộ môn Cơ điện tử, Viện Cơ khí
Trang 2Chapter 3 Intensity Transformations and Spatial Filtering
❖Two principal categories of spatial processing are intensity transformations and
spatial filtering.
➢ Intensity transformations operate on single pixels of an image for tasks such
as contrast manipulation and image thresholding.
➢ Spatial filtering performs operations on the neighborhood of every pixel in an
image.
➢ Examples of spatial filtering include image smoothing and sharpening.
Trang 3Chapter 3 Intensity Transformations and Spatial Filtering
1 Background
2 Some Basic Intensity Transformation Functions
3 Histogram Processing
4 Fundamentals of Spatial Filtering
5 Smoothing (Lowpass) Spatial Filters
6 Sharpening (Highpass) Spatial Filters
7 Highpass, Bandreject, and Bandpass Filters from Lowpass Filters
8 Combining Spatial Enhancement Methods
Trang 41 Background
❖The Basics of Intensity Transformations and Spatial Filtering
➢ The spatial domain processes are based on the expression
where f(x, y) is an input image, g(x, y) is the
output image, and T is an operator on f defined
over a neighborhood of point (x, y).
A 3x3 neighborhood about a point (x0, y0) in an image The neighborhood
is moved from pixel to pixel in the image to generate an output image.
Trang 51 Background
❖The Basics of Intensity Transformations and Spatial Filtering
➢ intensity (also called a gray-level, or mapping) transformation function
Intensity transformation functions (a) Contrast stretching function
(b) Thresholding function.
Trang 6Chapter 3 Intensity Transformations and Spatial Filtering
1 Background
2 Some Basic Intensity Transformation Functions
3 Histogram Processing
4 Fundamentals of Spatial Filtering
5 Smoothing (Lowpass) Spatial Filters
6 Sharpening (Highpass) Spatial Filters
7 Highpass, Bandreject, and Bandpass Filters from Lowpass Filters
8 Combining Spatial Enhancement Methods
Trang 7❖Three basic types of functions
➢ linear (negative and identity transformations)
➢ logarithmic (log and inverse-log transformations)
➢ power-law (nth power and nth root
transformations)
Some basic intensity transformation functions.
2 Some Basic Intensity Transformation Functions
Trang 82 Some Basic Intensity Transformation Functions
❖Image Negatives
(a) A digital mammogram (b) Negative image obtained using Eq (3-3) (Image (a) Courtesy of General Electric Medical Systems.)
Trang 92 Some Basic Intensity Transformation Functions
❖Log Transformations
where c is a constant and it is assumed that r 0
(a) Fourier spectrum displayed as a grayscale image (b) Result of applying the log
Trang 102 Some Basic Intensity Transformation Functions
❖Power-Law (Gamma) Transformations
where c and are positive constants
Plots of the gamma equation s = cr for various values
of (c = 1 in all cases).
Trang 112 Some Basic Intensity Transformation Functions
❖Power-Law (Gamma) Transformations
(a) Image of a human retina (b) Image as
as it appears on a monitor with a gamma setting of 2.5 (note the darkness) (c) Gammacorrected image (d) Corrected image, as it appears on the same monitor (compare with the original image) (Image (a) courtesy of the National Eye Institute, NIH)
Trang 122 Some Basic Intensity Transformation Functions
❖Power-Law (Gamma) Transformations
➢ Contrast enhancement using power-law intensity transformations.
a) Magnetic resonance image (MRI) of a fractured human spine (the region of the fracture is enclosed by the circle) (b)–(d)
Results of applying the transformation in Eq (3-5) with and and 0.3, respectively (Original image courtesy of Dr David R Pickens, Department of Radiology and Radiological Sciences, Vanderbilt University Medical Center.)
Trang 132 Some Basic Intensity Transformation Functions
❖Power-Law (Gamma) Transformations
➢ Another illustration of power-law transformations.
(a) Aerial image (b)–(d) Results of applying the transformation in Eq (3-5) with = 3.0, 4.0 and 5.0, respectively
Trang 142 Some Basic Intensity Transformation Functions
❖Piecewise Linear Transformation Functions
➢ Contrast Stretching
where rmin and rmax denote
the minimum and maximum
intensity levels in the input
image, respectively
where m is the mean intensity
level in the image
Trang 152 Some Basic Intensity Transformation Functions
❖Piecewise Linear Transformation Functions
➢ Intensity-Level Slicing
Figure 1: (a) This transformation function highlights range [A, B] and
reduces all other intensities to a lower level (b) This function highlights
range [A, B] and leaves other intensities unchanged.
Figure 2: (a) Aortic angiogram (b) Result of using a slicing transformation
of the type illustrated in Fig 1(a) , with the range of intensities of interest selected in the upper end of the gray scale (c) Result of using the
transformation in Fig 1(b) , with the selected range set near black, so that the grays in the area of the blood vessels and kidneys were preserved
Trang 162 Some Basic Intensity Transformation Functions
❖Piecewise Linear Transformation Functions
➢ Bit-Plane Slicing
Bit-planes of an 8-bit image.
Trang 172 Some Basic Intensity Transformation Functions
❖Piecewise Linear Transformation Functions
image of size pixels (b) through (i) Bit planes 8 through 1, respectively, where plane 1 contains the least significant bit
Each bit plane is a binary image Figure (a) is an SEM image of a
trophozoite that causes a
disease called giardiasis
(Courtesy of Dr Stan Erlandsen, U.S Center for Disease Control and Prevention.)
Trang 182 Some Basic Intensity Transformation Functions
❖Piecewise Linear Transformation Functions
➢ Bit-Plane Slicing
Image reconstructed from bit planes: (a) 8 and 7; (b) 8, 7, and 6; (c) 8, 7, 6, and 5.
Trang 19Chapter 3 Intensity Transformations and Spatial Filtering
1 Background
2 Some Basic Intensity Transformation Functions
3 Histogram Processing
4 Fundamentals of Spatial Filtering
5 Smoothing (Lowpass) Spatial Filters
6 Sharpening (Highpass) Spatial Filters
7 Highpass, Bandreject, and Bandpass Filters from Lowpass Filters
8 Combining Spatial Enhancement Methods
Trang 203 Histogram Processing
❖Histogram
➢ The unnormalized histogram:
where rk is the k-th intensity level of an L-level
digital image f(x, y); nk is the number of pixels
in f with intensity rk and the subdivisions of the
intensity scale are called histogram bins.
Trang 213 Histogram Processing
❖Histogram
➢ The normalized histogram:
where M and N are the number of image rows and columns, respectively.
𝑘=1 𝐿−1
𝑝 𝑟 𝑘 = 1
Trang 223 Histogram Processing
❖Histogram
Four image types and their corresponding histograms (a) dark; (b) light; (c) low contrast; (d) high contrast
The horizontal axis of the histograms are values of rk and the vertical axis are values of p ( rk)
Trang 243 Histogram Processing
❖Histogram Equalization
➢ Example: Illustration of the mechanics of histogram equalization.
• Suppose that a 3-bit image (L = 3) of size 64x64 pixels (MN = 4096) has the intensity distribution
in Table
Trang 253 Histogram Processing
❖Histogram Equalization
➢ Example: Illustration of the mechanics of histogram equalization.
We round them to their nearest integer values in the range [0, 7]:
Trang 263 Histogram Processing
❖Histogram Equalization
➢ Example: Illustration of the mechanics of histogram equalization.
Histogram equalization (a) Original histogram (b) Transformation function (c) Equalized histogram.
Trang 273 Histogram Processing
❖Histogram Equalization
➢ Algorithm for Histogram Equalization
Trang 283 Histogram Processing
❖Histogram Equalization
equalized images
Histogram-equalized images Source images Histogram
Trang 293 Histogram Processing
❖Histogram Equalization
(a) Image from Phoenix Lander (b) Result of histogram equalization (c) Histogram of image (a) (d) Histogram of image (b) (Original image courtesy of NASA.)
Trang 30Chapter 3 Intensity Transformations and Spatial Filtering
1 Background
2 Some Basic Intensity Transformation Functions
3 Histogram Processing
4 Fundamentals of Spatial Filtering
5 Smoothing (Lowpass) Spatial Filters
6 Sharpening (Highpass) Spatial Filters
7 Highpass, Bandreject, and Bandpass Filters from Lowpass Filters
8 Combining Spatial Enhancement Methods
Trang 314 Fundamentals of Spatial Filtering
❖The Mechanics of Linear Spatial Filtering
➢ Spatial filter kernel: filter kernel, kernel, mask,
template, and window
➢ Linear spatial filtering
Trang 334 Fundamentals of Spatial Filtering
❖Spatial Correlation and Convolution
➢ 2-D illustration
➢ Correlation
➢ Convolution
Trang 344 Fundamentals of Spatial Filtering
❖Spatial Correlation and Convolution
Trang 35Chapter 3 Intensity Transformations and Spatial Filtering
1 Background
2 Some Basic Intensity Transformation Functions
3 Histogram Processing
4 Fundamentals of Spatial Filtering
5 Smoothing (Lowpass) Spatial Filters
6 Sharpening (Highpass) Spatial Filters
7 Highpass, Bandreject, and Bandpass Filters from Lowpass Filters
8 Combining Spatial Enhancement Methods
Trang 365 Smoothing (Lowpass) Spatial Filters
➢ Smoothing (also called averaging) spatial filters are used to reduce sharp
transitions in intensity.
➢ Application: noise reduction, reduce aliasing, reduce irrelevant detail in an image, smoothing the false contours, …
➢ Linear spatial filtering
➢ Nonlinear smoothing filters
Trang 375 Smoothing (Lowpass) Spatial Filters
❖Box Filter Kernels
Trang 385 Smoothing (Lowpass) Spatial Filters
❖Box Filter Kernels
➢ Example: Lowpass filtering with a box
kernel
(a) Test pattern of size 1024x1024 pixels (b)-(d)
Results of lowpass filtering with box kernels of
sizes 3x3, 11x11, and 21x21 respectively.
Trang 395 Smoothing (Lowpass) Spatial Filters
❖Lowpass Gaussian Filter Kernels
➢ Gaussian kernels of the form
Trang 405 Smoothing (Lowpass) Spatial Filters
❖Lowpass Gaussian Filter Kernels
(a) Sampling a Gaussian function to obtain a discrete Gaussian kernel
The values shown are for K = 1 and = 1 (b) Resulting kernel.
Trang 415 Smoothing (Lowpass) Spatial Filters
❖Lowpass Gaussian Filter Kernels
➢ Example: Lowpass filtering with a Gaussian kernel
(a)A test pattern of size 1024x1024 (b) Result of lowpass filtering the pattern with a Gaussian kernel of
size 21x21, with standard deviations = 3.5 (c) Result of using a kernel of size 43x43, with = 7 We
Trang 425 Smoothing (Lowpass) Spatial Filters
❖Lowpass Gaussian Filter Kernels
➢ Example: Lowpass filtering with a Gaussian kernel
(a) Result of filtering using a Gaussian kernels of size43x43, with = 7 (b) Result of using
a kernel of 85x85, with the same value of (c) Difference image.
Trang 435 Smoothing (Lowpass) Spatial Filters
➢ Example: Comparison of Gaussian and box filter smoothing characteristics.
Trang 445 Smoothing (Lowpass) Spatial Filters
➢ Example: Using lowpass filtering and thresholding for region extraction.
Trang 455 Smoothing (Lowpass) Spatial Filters
❖Order-Statistic (Nonlinear) Filters
values in the neighborhood of that pixel
→ Effective in the presence of impulse noise (salt-and-pepper noise)
→ The 50th percentile of a ranked set of numbers
Trang 465 Smoothing (Lowpass) Spatial Filters
❖Order-Statistic (Nonlinear) Filters
➢ Min filter:
→ used for the opposite purpose
→ The 0th percentile filter
Trang 475 Smoothing (Lowpass) Spatial Filters
❖Order-Statistic (Nonlinear) Filters
➢ Example: Median filtering
Trang 48Chapter 3 Intensity Transformations and Spatial Filtering
1 Background
2 Some Basic Intensity Transformation Functions
3 Histogram Processing
4 Fundamentals of Spatial Filtering
5 Smoothing (Lowpass) Spatial Filters
6 Sharpening (Highpass) Spatial Filters
7 Highpass, Bandreject, and Bandpass Filters from Lowpass Filters
8 Combining Spatial Enhancement Methods
Trang 496 Sharpening (Highpass) Spatial Filters
❖Foundation
➢ First-order derivative
➢ Second-order derivative
Trang 506 Sharpening (Highpass) Spatial Filters
❖Image Sharpening —the Laplacian
➢ Laplacian
Trang 516 Sharpening (Highpass) Spatial Filters
❖Image Sharpening —the Laplacian
➢ Laplacian kernel
Trang 526 Sharpening (Highpass) Spatial Filters
❖Image Sharpening —the Laplacian
➢ The basic way in which the Laplacian is used for image sharpening:
▪ c = 1 if the center element of the Laplacian kernel is positive
▪ c = -1 if the center element of the Laplacian kernel is negative
Trang 536 Sharpening (Highpass) Spatial Filters
❖Image Sharpening —the Laplacian
➢ Example: Image sharpening using the Laplacian
a) Blurred image of the North Pole of the moon (b) Laplacian image obtained using the kernel in Fig
3.51(a) (c) Image sharpened using Eq (3-63) with c = -1 (d) Image sharpened using the same procedure,
Trang 546 Sharpening (Highpass) Spatial Filters
❖Unsharp Masking and Highboost Filtering
➢ Unsharp masking
▪ Blur the original image
▪ Subtract the blurred image from the original (the resulting difference is called the mask)
▪ When k = 1 → unsharp masking
▪ When 0 k < 1 → reduces the contribution of the unsharp mask
Trang 556 Sharpening (Highpass) Spatial Filters
❖Unsharp Masking and Highboost Filtering
1-D illustration of the mechanics of unsharp masking (a) Original signal (b) Blurred signal with original
shown dashed for reference (c) Unsharp mask (d) Sharpened signal, obtained by adding (c) to (a).
Trang 566 Sharpening (Highpass) Spatial Filters
❖Unsharp Masking and Highboost Filtering
(a) Unretouched “soft-tone” digital image of size 469x600 pixels (b) Image blurred using a 31x31 Gaussian lowpass
filter with = 5 (c) Mask (d) Result of unsharp masking using Eq (3-65) with k = 1 (e) and (f) Results of highboost
filtering with k = 2 and k = 3 respectively.
Trang 576 Sharpening (Highpass) Spatial Filters
❖Image Sharpening —the Gradient
➢ The gradient of an image f at coordinates (x, y)
➢ The magnitude (length) of vector f
Trang 586 Sharpening (Highpass) Spatial Filters
❖Image Sharpening —the Gradient
➢ Roberts cross-gradient operators
Trang 596 Sharpening (Highpass) Spatial Filters
❖Image Sharpening —the Gradient
➢ Sobel operators
Trang 606 Sharpening (Highpass) Spatial Filters
❖Image Sharpening —the Gradient
➢ Filter masks
(a) A 3x3 region of an image, where the zs are intensity values (b)–(c) Roberts cross-gradient operators
(d)–(e) Sobel operators All the kernel coefficients sum to zero, as expected of a derivative operator.
Trang 616 Sharpening (Highpass) Spatial Filters
❖Image Sharpening —the Gradient
➢ Example: Using the gradient for edge enhancement.
(a) Image of a contact lens (note defects on the boundary at 4 and 5 o’clock)
Trang 62Chapter 3 Intensity Transformations and Spatial Filtering
1 Background
2 Some Basic Intensity Transformation Functions
3 Histogram Processing
4 Fundamentals of Spatial Filtering
5 Smoothing (Lowpass) Spatial Filters
6 Sharpening (Highpass) Spatial Filters
7 Highpass, Bandreject, and Bandpass Filters from Lowpass Filters
8 Combining Spatial Enhancement Methods
Trang 637 Highpass, Bandreject, and Bandpass Filters from Lowpass Filters
❖Transfer functions of ideal 1-D filters
Transfer functions of ideal 1-D filters in the frequency domain (u denotes frequency) (a) Lowpass filter (b) Highpass filter (c) Bandreject filter (d) Bandpass filter (As before, we show only positive frequencies for simplicity.)
Trang 647 Highpass, Bandreject, and Bandpass Filters from Lowpass Filters
❖Transfer functions of ideal 1-D filters