Image Filtering 1
Image Filtering 1
Digital Image
An image may be defined as a two-dimensional function, f ( x, y), where x and y are spatial (plane)
coordinates, and the amplitude of f at any pair of coordinates (x, y) is called the intensity or gray level of the
image at that point.
When x, y, and the intensity values of f are all finite, discrete quantities, we call the image a digital image.
Image filtering
• Producing a new image where the value at a pixel in the output image is a
function of a neighborhood of the pixel location in the input image.
Image Filtering Vs. Warping
• Image filtering changes the range (i.e. the pixel values) of an image, so
the colors of the image are altered without changing the pixel
positions.
• image warping changes the domain (i.e. the pixel positions) of an
image, where points are mapped to other points without changing
the colors.
• The goal of using filters is to modify or enhance image properties and/or
to extract valuable information from the pictures such as edges, corners,
and blobs.
Linear Filters
• Form new image whose pixels are a weighted sum of original pixel values, using
the same set of weights at each point.
• Example: smoothing by averaging :form the average of pixels in a neighborhood.
• Smoothing with a Gaussian– form a weighted average of pixels in a neighborhood.
• Finding a derivative– form a difference of pixels in a neighborhood
Gaussian Kernel
Linear Filter Properties
Output is a linear function of the input.
• Additivity:The sum of the filtered versions of two images is equal to the filtered
version of the sum of the two images.
• Homogeneity:The filtered version of a constant multiplied by an image is equal
to the constant multiplied by the filtered version of the image.
• Shift invariance:Output is a shift-invariant function of the input (i.e. shift the
input image two pixels to the left, the output is shifted two pixels to the left)
• Linearity: The filtered version of a constant multiplied by an image is equal to
the constant multiplied by the filtered image
Use Of Linear Filters:
• Linear filters are used to improve images by: Sharpening edges, Reducing noise,
Correcting for uneven illumination, and Deconvoluting blur and motion.
Filtering Application Noise Filtering
• Image processing is useful for noise reduction.
Common types of noise:
• Salt and pepper noise: contains random occurrences of black and white pixels.
• Impulse noise: contains random occurrences of white pixels .
• Gaussian noise: variations in intensity drawn from a Gaussian normal distribution
Mean filtering(Low Pass)
Mean filtering
• Mean filtering is a widely employed technique within the realm of image processing,
serving as a crucial tool for noise reduction and smoothing. By adopting spatial filtering
principles, mean filtering aids in eliminating random variations or noise present in an
image, all while retaining its essential features. In this context, we will explore the
mechanics, advantages, and limitations of mean filtering
• The fundamental concept behind mean filtering is elegantly simple: each pixel in an
image is substituted with the average value derived from neighboring pixels confined
within a specified window or kernel. The size of this kernel determines the degree of
smoothing, with larger kernels inducing more potent smoothing effects at the potential
cost of finer detail loss.
• In essence, mean filtering involves the replacement of each pixel’s value with the
average value of its neighboring pixels, including the pixel itself. This process proves
effective in removing pixel values that diverge significantly from their surroundings.
Conceptually aligned with a convolution filter, mean filtering revolves around a kernel
that defines the shape and size of the neighborhood encompassed for mean calculation.
While a standard 3×3 square kernel is frequently employed, the utilization of larger
kernels like 5×5 squares can intensify the smoothing for more substantial noise
reduction
Mean filtering
• Several iterations of mean smoothing exist, among which is Threshold Averaging. Here, smoothing is
contingent upon a condition: the central pixel value undergoes alteration only if the difference between its
initial value and the computed average surpasses a preset threshold. This approach efficiently reduces noise
while preserving more image detail than traditional mean filtering.
• In the realm of computational simplicity, mean filtering stands as an exemplar. Its straightforward
implementation and efficiency render it an easily accessible tool. However, mean filtering’s suitability is not
universal; images containing sharp edges or intricate details may experience edge blurring due to the
averaging procedure. Notably effective against Gaussian or salt-and-pepper noise, mean filtering harnesses
the context of surrounding pixels to mitigate random noise values.
• While mean filtering holds its place in preprocessing images for subsequent intricate tasks like edge
detection or object recognition, its significance is underscored in image restoration and enhancement
processes. Notably, in domains like medical imaging, mean filtering’s application contributes to enhanced
diagnostic precision and improved visual quality.
• In summary, mean filtering emerges as an uncomplicated yet potent technique in image processing. Its
prowess in noise reduction and texture smoothing bestows it with versatility across diverse applications.
Nevertheless, judicious selection of kernel size remains pivotal to striking a balance between noise
reduction and vital image feature preservation. When judiciously employed, mean filtering profoundly
elevates image quality and facilitates comprehensive image analysis. Despite its computational efficiency, it
is imperative to acknowledge its limitations; alternative convolution filters, such as the Gaussian smoothing
filter, present distinct trade-offs between noise reduction and detail preservation
Effect of mean filters
Mean Filters Kernels
Generalization: Cross-Correlation
•Filtering
Let’s write this down as an equation. Assume the averaging window is
(2k+1)x(2k+1):
• As edges can be seen as boundaries between objects within image, there is often a
sharp transition in pixel intensities neighboring an edge, and therefore such pixels
have high magnitude value. Similarly, we can interpret this observation as a pixel
with high magnitude is likely to be an edge that we want to detect.
• Therefore, many detectors are built with thresholding in order to remove non-
probable pixels. It applies to Canny edge detector as well. One difference is that while
others use a single threshold, Canny edge detector use two thresholds: high and low,
and this is called Hysteresis thresholding.
• Before getting into Hysteresis thresholding, Let’s take a look what could happen when
single-value thresholding. Think of a case when a certain threshold theta is given. Any
edge whose magnitude (|grad|) is lower than theta will be discarded, and this
indicates the lost of edge in image.
• Here is an example. If the chosen theta is higher
than the lowest magnitude of true edges, we
loose them. In the following image, we lost
some edges in woman’s chin due to the
thresholding.
• In order to reduce such lost, Hysteresis
thresholding uses a high and low thresholds.
• The main idea of Hysteresis thresholding is
• Use the high threshold to find “strong edges”, which
is sure to be considered as an edge, to start edge
chain.
• Use the low threshold to find “weak edges”, which
connect empty segment between “strong edges”.
Gradient-Based Methods of Edge detection
• Prewitt Operator:
• Wherever there is a sudden change in pixel intensities, an edge is detected by the
mask. Since the edge is defined as the change in pixel intensities, it can be calculated
by using differentiation. Prewitt mask is a first-order derivative mask. In the graph
representation of Prewitt-mask’s result, the edge is represented by the local maxima or
local minima.
• Prewitt operator detects both types of edges, these are:
Horizontal edges or along the x-axis
Vertical Edges or along the y-axis.
Wherever there is a sudden change in pixel intensities, an edge is detected by
the mask. Since the edge is defined as the change in pixel intensities, it can be
calculated by using differentiation. Prewitt mask is a first-order derivative mask.
In the graph representation of Prewitt-mask’s result, the edge is represented by
the local maxima or local minim.
• More weight means more edge detection.
• The opposite sign should be present in the mask. (+ and -)
• The Sum of the mask values must be equal to zero.
Gradient-Based Methods of Edge detection
• Sobel Operator:
• The Sobel operator is a discrete differentiation operator that computes an approximation of the
gradient of the image intensity function. It uses convolutional masks to highlight regions with high
spatial frequency, which correspond to edges.
As the center column is of zero so it does not Above mask will find edges in
include the original values of an image but horizontal direction and it is
rather it calculates the difference of right because that zeros column is in
and left pixel values around that edge. Also horizontal direction. When you will
the center values of both the first and third convolve this mask onto an image
column is 2 and -2 respectively. it would prominent horizontal Vertical Mask of
This give more weight age to the pixel values edges in the image. The only Sobel Operator
around the edge region. This increase the difference between it is that it
edge intensity and it become enhanced have 2 and -2 as a center element Horizontal Mask
comparatively to the original image. of first and third row of Sobel Operator
Sample Image After Applying Vertical Mask After Applying Horizontal Mask
As you can see that in the first picture on which we apply vertical mask, all the vertical edges are
more visible than the original image. Similarly in the second picture we have applied the horizontal
mask and in result all the horizontal edges are visible.
Roberts Cross Edge Detector
The Roberts Cross operator performs a simple, quick to compute, 2-D spatial gradient measurement on an image
It thus highlights regions of high spatial frequency which often correspond to edges
The input to the operator is a grayscale image, as is the output. Pixel values at each point in the output represent the
estimated absolute magnitude of the spatial gradient of the input image at that point
How It Works
The operator consists of a pair of 2×2 convolution kernels as shown in Figure 1. One kernel is simply the other rotated
by 90°
Since the input image is represented as a set of discrete pixels, we have to find a discrete convolution
kernel that can approximate the second derivatives in the definition of the Laplacian.
Using one of these kernels, the Laplacian can be calculated using standard convolution methods.
Laplacian Operator
Laplacian kernel used to implement in equation. (b) Kernel used to implement an extension of this equation that includes the
diagonal terms. (c) and (d) Two other Laplacian kernels
Laplacian of Gaussian (LOG)
• Because Laplacian kernels are approximating a second derivative measurement
on the image, they are very sensitive to noise.
• To overcome this image is often applied Gaussian smoothing before applying
Laplacian filter.
• This pre-processing step reduces the high frequency noise components prior to
the differentiation step.
• Since the convolution operation is associative, we can convolve the Gaussian
smoothing filter with the Laplacian filter first of all.
• Since both the Gaussian and the Laplacian kernels are usually much smaller than
the image, this method usually requires far fewer arithmetic operations.
• The LoG (`Laplacian of Gaussian') kernel can be precalculated in advance so only
one convolution needs to be performed at run-time on the image.
Laplacian of Gaussian (LOG)
The 2-D LoG function centered on zero and with Gaussian standard deviation has the form
The 2-D Laplacian of Gaussian (LoG) function. The x and y axes are marked in standard deviations ( σ).
Laplacian of Gaussian (LOG)
• The LoG operator calculates the second spatial derivative of an image. This
means that in areas where the image has a constant intensity (i.e. where
the intensity gradient is zero), the LoG response will be zero. In the vicinity
of a change in intensity, however, the LoG response will be positive on the
darker side, and negative on the lighter side. This means that at a
reasonably sharp edge between two regions of uniform but different
intensities, the LoG response will be:
• zero at a long distance from the edge,
• positive just to one side of the edge,
• negative just to the other side of the edge,
• zero at some point in between, on the edge itself.
Laplacian of Gaussian (LOG)
Response of 1-D LoG filter to a step edge. The left hand graph shows a 1-D image, 200 pixels long, containing a
step edge. The right hand graph shows the response of a 1-D LoG filter with Gaussian σ= 3 pixels.
Laplacian of Gaussian (LOG)
Laplacian of Gaussian (LOG)
Canny Edge Detector
• Cranny’s approach is based on three basic objectives:
• 1. Low error rate. All edges should be found, and there should be
no spurious responses.
• 2. Edge points should be well localized. The edges located must be
as close as possible to the true edges. That is, the distance between
a point marked as an edge by the detector and the center of the
true edge should be minimum.
• 3. Single edge point response. The detector should return only one
point for each true edge point. That is, the number of local maxima
around the true edge should be minimum. This means that the
detector should not identify multiple edge pixels where only a
single edge point exists.
Canny Edge Detector
• Let f (x,y) denote the input image and G (x, y) denote the Gaussian
function
This operation is followed by computing the gradient magnitude and direction (angle),
Canny Edge Detector
Canny Edge Detector
When repeated for all values of x and y, this procedure yields a nonmaxima suppressed image g N (x,y) that is of the same
size as fs(x, y)
The final operation is to threshold g N (x,y) to reduce false edge points, in which all values below the threshold were set to 0
If we set the threshold too low, there will still be some false edges (called false positives). If the threshold is set too high,
then valid edge points will be eliminated (false negatives).
Canny’s algorithm attempts to improve on this situation by using hysteresis thresholding which a low threshold,
TL and a high threshold, TH . Experimental evidence (Canny [1986]) suggests that the ratio of the high to low
threshold should be in the range of 2:1 to 3:1.
Canny Edge Detector
• We can visualize the thresholding operation as creating two additional
images:
Canny Edge Detector
Harris Corner Detector
• The Harris corner detector is a fundamental algorithm in computer vision
used to extract corners from images.
• It identifies "corners" in an image, which are points where the image
intensity changes significantly in two or more directions which are valuable
features for various computer vision task.
• The Harris corner detector essentially analyzes how the image intensity
changes when a small window is shifted in different directions.
• It was first introduced by Chris Harris and Mike Stephens in 1988 upon the
improvement of Moravec’s corner detector. Compared to the previous one,
Harris’ corner detector takes the differential of the corner score into account
with reference to direction directly, instead of using shifting patches for
every 45-degree angles, and has been proved to be more accurate in
distinguishing between edges and corners
Corner
In the above figure, if we take the flat region then no gradient change is observed in any
direction. Similarly, in the edge region, no gradient change is observed along the edge direction.
So both flat region and edge region are bad for patch matching since they not very distinctive
(there are many similar patches in along edge in edge region). While in corner region we observe
a significant gradient change in all direction. Due this corners are considered good for patch
matching(shifting the window in any direction yield a large change in appearance) and generally
more stable over the change of viewpoint
visualization of gradients
Compute image gradients over a small region
Distribution reveals edge orientation and
magnitude
How do you quantify orientation and
magnitude?
Subtract the mean from each image gradient
Finding corners
λ1 and λ2 are the eigenvalues of M. So the values of these eigenvalues decide whether a region is a
corner, edge or flat.
Error surface indicates a good image feature
• When |R| is small, which happens when λ1 and λ2 are small, the
region is flat.
• When R<0, which happens when λ1>>λ2 or vice versa, the region is an
edge.
• When R is large, which happens when λ1 and λ2 are large and λ1∼λ2,
the region is a corner.
Eigen Value
• Compute eigenvalues and eigenvectors
We can visualize M as an ellipse with axis lengths determined by the eigenvalues and orientation determined by R
Interpreting eigenvalues
Use threshold on eigenvalues to detect corners
Ellipse rotates but its shape (eigenvalues) remains the same Corner response R is invariant to image rotation