0% found this document useful (0 votes)
0 views22 pages

Module2 Notes

Module 2 of Digital Image Processing focuses on image transforms, particularly in the spatial domain. It covers techniques such as intensity transformations, histogram processing, and spatial filtering, emphasizing the subjective nature of image enhancement based on specific applications. Key methods discussed include image negatives, logarithmic transformations, and histogram equalization, which aim to improve image quality by manipulating pixel values directly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views22 pages

Module2 Notes

Module 2 of Digital Image Processing focuses on image transforms, particularly in the spatial domain. It covers techniques such as intensity transformations, histogram processing, and spatial filtering, emphasizing the subjective nature of image enhancement based on specific applications. Key methods discussed include image negatives, logarithmic transformations, and histogram equalization, which aim to improve image quality by manipulating pixel values directly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module 2 — Image Transforms

DIGITAL IMAGE PROCESSING

MODULE II
Image Transforms

Syllabus covered in this module


Spatial Domain transforms: Basic intensity transformation functions - image negatives and log
transformation; Histogram processing - histogram equalisation; Fundamentals of Spatial Filtering - spatial
correlation and convolution; Smoothing filters and Sharpening filters - Average and Laplacian filters.

Page 1
Module 2 — Image Transforms

1. Introduction to Image Enhancement


Image enhancement is the process that improves the quality of an image for a specific application. It is
important to understand that enhancement is a subjective, task-driven idea rather than an absolute one —
there is no mathematical measure of "image quality" that works for every situation. Different applications may
need very different kinds of enhancement: a chest X-ray needs contrast enhancement to reveal faint tissue
boundaries that a radiologist must inspect; a satellite photo may instead need noise removal so that terrain
features are not obscured by sensor noise; a faded photograph may simply need its dynamic range stretched
back out. There is no single "best" enhancement method — the right technique always depends on the task at
hand, the type of degradation present in the image, and what a human viewer or a downstream algorithm (such
as an edge detector) needs to see clearly.

Broadly, enhancement techniques trade off two competing goals: suppressing unwanted variations (noise, low
contrast, uneven illumination) while preserving or even amplifying the wanted variations (edges, boundaries,
fine texture) that carry the actual information in the image. Every technique studied in this module — from a
simple negative transform to the Laplacian sharpening filter — can be understood as pursuing one or the other
of these two goals.

1.1 Approaches to Image Enhancement


Image enhancement techniques are broadly divided into two domains, based on where the mathematical
manipulation actually takes place:

● Spatial Domain Methods (Image Plane) — techniques based on direct manipulation of pixels in an
image. The image itself, as an array of pixel intensity values, is operated on directly. These methods are
usually simple, intuitive, and computationally cheap, which is why they are the natural starting point for
studying image processing.
● Frequency Domain Methods — techniques based on modifying the Fourier transform of an image, and
then transforming the result back into the spatial domain. These methods make it easy to isolate and
manipulate specific spatial frequencies (e.g. removing periodic noise), but they require an additional
forward and inverse transform step and are conceptually more involved.
This module focuses entirely on spatial domain methods — that is, every technique described from this point
onward (intensity transformations, histogram equalisation, correlation, convolution, smoothing, and
sharpening) works by directly recomputing pixel values from the original image, without ever leaving the spatial
domain.

1.2 The Spatial Domain Process


The term spatial domain refers to the aggregate of pixels composing an image — in other words, the image
exactly as it is stored and displayed, a 2-D grid of intensity values indexed by row and column position. Spatial
domain methods are procedures that operate directly on these pixels, as opposed to operating on some
transformed representation of the image. A spatial domain process is denoted, in general form, by the
expression:

Page 2
Module 2 — Image Transforms

g(x, y) = T [ f(x, y) ]
where f(x, y) is the input image, g(x, y) is the processed (output) image, and T is an operator on f, defined over
some neighbourhood of (x, y). In general, T can operate on a set of input images rather than just one — for
example, adding K noisy images of the same scene together and averaging them is a classic noise-reduction
technique that fits this same general framework. The "neighbourhood" mentioned here is simply the small
region of pixels around (x, y) that T is allowed to look at when computing the output value — and, as the next
section shows, the size of that neighbourhood is what separates the very simplest enhancement techniques
from more elaborate spatial filters.

1.3 The Simplest Case: Point Processing


The simplest form of T occurs when the neighbourhood used is of size 1 × 1 (a single pixel). In this case, g
depends only on the value of f at (x, y), and T becomes a gray-level (also called an intensity, or mapping)
transformation function of the form:

s = T(r)
where, for simplicity of notation, r and s denote respectively the gray level of f(x, y) and g(x, y) at any point (x, y).
Because the output value at every point depends only on the intensity at that same point (not on its
neighbours), these are also called point processing techniques — the same rule s = T(r) is applied independently
and identically to every pixel in the image, regardless of where that pixel sits or what is around it. This makes
point processing extremely fast and simple to implement (often as a single lookup table with one entry per
possible gray level), but it also means point processing can never use spatial context — it cannot, for instance,
tell the difference between an isolated noisy pixel and a genuine edge, because it never looks at neighbouring
pixels at all. Section 2 of this module explores several standard point-processing functions T(r); Sections 4
onward move beyond the 1×1 neighbourhood into true spatial filtering, where the output at (x, y) depends on a
whole block of surrounding pixels.

2. Basic Intensity (Gray-Level) Transformation Functions


Gray-level transformation functions are the simplest of all image enhancement techniques, and, as Section 1.3
explained, they are a special case of point processing: every pixel is remapped independently, using exactly the
same rule, with no reference to its neighbours. As before, the value of a pixel before and after processing is
denoted r and s respectively, and the two are related by:

s = T(r)
where T is a transformation that maps an input pixel value r into an output pixel value s. Because T is applied
identically to every pixel, it is often visualised (and even implemented) as a single graph or lookup table: plot r
along the horizontal axis and the resulting s along the vertical axis, and the shape of that curve completely
describes the enhancement being performed. A curve that lies above the diagonal line brightens the
corresponding gray levels; a curve that lies below the diagonal darkens them; and the diagonal itself (s = r) is the

Page 3
Module 2 — Image Transforms

identity transformation, which leaves the image unchanged. Three basic families of such functions are used
frequently for image enhancement:

Fig. 2.1 — Some basic gray-level transformation functions used for image enhancement (Gonzalez & Woods).

Family Transformation Nature

Linear Negative transformation s=L−1−r

Linear Identity transformation s = r (no change)

Logarithmic Log transformation s = c·log(1 + r)

Expands high values, compresses low


Logarithmic Inverse-log transformation
values

Power-law nth power transformation s = c·r^n , n > 1

Power-law nth root transformation s = c·r^n , n < 1 (gamma correction)

The syllabus for this module focuses on the two simplest and most illustrative of these: the image negative and
the log transformation.

2.1 Image Negatives (Negative Transformation)

Definition
The negative of an image with gray levels in the range [0, L − 1], where L is the largest gray-level value
present, is obtained using the negative transformation:

s=L−1−r

Page 4
Module 2 — Image Transforms

This expression reverses the intensity levels of the input image, producing the equivalent of a photographic
negative. Every dark region becomes light and every light region becomes dark, while mid-gray areas remain
roughly unaffected (a pixel exactly at the midpoint of the range maps very close to itself). Geometrically, the
negative transformation is simply a straight line of slope −1 running from (0, L−1) down to (L−1, 0) — it is the
mirror image of the identity line s = r, reflected about the horizontal mid-gray level. This is why it is classified as
a linear transformation: equal steps in r always produce equal (but oppositely directed) steps in s, everywhere
across the gray-level range.

Why use it?


● Suitable for enhancing white or gray detail embedded in dark regions of an image, especially when the
black areas dominate in size — the human visual system is often better at distinguishing subtle
variations among light tones than among very dark ones, so inverting a mostly-dark image can make
faint structures much easier to see.
● Common in medical image analysis, e.g. inspecting detail in dark regions of mammograms, where
important diagnostic structures may sit against a very dark background and are easier for a radiologist to
study once the intensities are inverted.
● Because the transformation is its own inverse (applying s = L−1−r twice returns the original image), it is
trivial to undo — useful when the negative is used only as a temporary viewing aid.

Fig. 2.2 — An image (left) and its negative (right), obtained using s = L − 1 − r.

Worked Example
For an 8-bit image, L = 256, so L − 1 = 255. A pixel with intensity r = 60 maps to:

s = 255 − 60 = 195
A dark pixel (r = 60, close to black) is transformed into a bright pixel (s = 195, close to white) — exactly the
behaviour of a photographic negative.

Page 5
Module 2 — Image Transforms

2.2 Logarithmic Transformations

Definition
The general form of the log transformation is:

s = c · log(1 + r), where r ≥ 0


Here, c is a constant (often chosen so that the maximum output value is L − 1), and the "+1" avoids taking the log
of zero, since log(0) is undefined. Unlike the negative transformation, the log function is not a straight line — it
rises steeply for small r and then flattens out as r grows, which is precisely the shape needed to handle images
whose pixel values are extremely unevenly distributed.

Key Characteristics
● The log curve maps a narrow range of low gray-level values in the input image into a wider range of
output levels, and a wide range of high input values into a narrower range of output values — visually,
this is exactly what Fig. 2.1 shows: the "Log" curve rises very steeply near r = 0 and then bends over and
grows only slowly for larger r.
● Used to expand the values of dark pixels in an image while compressing the higher-level (bright) values,
so that detail hidden in the shadows becomes visible without completely blowing out the bright regions.
● Compresses the dynamic range of images that have very large variations in pixel values — for example,
Fourier spectra, where values can range from 0 to 10^6 or more, so that only a handful of the very
brightest pixels would be visible on a normal 0–255 display; the log transform brings the entire range
into a form the eye can actually perceive.
● The inverse log transformation performs the opposite: it expands high intensity values and compresses
low ones, which is useful when detail is hidden in the bright regions of an image rather than the dark
ones.
● Because it is a non-linear, monotonically increasing function, the log transform always preserves the
relative ordering of intensities (a brighter input pixel never becomes darker than a dimmer one after the
transform) — it only changes how much of the output range is devoted to each part of the input range.

Fig. 2.3 — (a) A Fourier spectrum. (b) Result of applying the log transformation with c = 1. Fine detail that was invisible in (a) becomes
visible in (b).

Worked Example

Page 6
Module 2 — Image Transforms

Suppose an 8-bit Fourier spectrum has pixel values ranging up to r = 100000, so directly displaying it would clip
almost all detail into a few visible gray levels. Choosing c so that s = 255 when r = 100000:

c = 255 / log(1 + 100000) ≈ 255 / 5.0 ≈ 51


Applying s = 51·log(1 + r) compresses the huge dynamic range into the visible [0, 255] band while still preserving
relative differences among the small, previously invisible values — which is exactly why log transformation is the
standard way to visualise Fourier spectra.

Page 7
Module 2 — Image Transforms

3. Histogram Processing
3.1 What Is a Histogram?

Definition
The histogram of a digital image with gray levels in the range [0, L − 1] is a discrete function:

h(rk) = nk
● rk = the k-th intensity (gray) level
● nk = the number of pixels in the image with gray level rk
In simple terms, a histogram is a bar graph that shows how many pixels in an image occur at each intensity value
— it reveals the tonal distribution of the picture without retaining any information about where those pixels are
located spatially. Two completely different-looking images (say, a checkerboard and a photograph of clouds) can
have identical histograms if they happen to use the same intensities in the same proportions; the histogram
summarises "how much of each tone" is present, not "where" it is. It is common to normalise a histogram by
dividing each of its values by the total number of pixels in the image, M × N:

p(rk) = nk / (M × N), for k = 0, 1, ..., L − 1


p(rk) gives an estimate of the probability of occurrence of gray level rk; the sum of all p(rk) values equals 1.
Working with this normalised form, rather than the raw counts nk, is convenient because it makes the histogram
independent of image size — a 100×100 image and a 4000×4000 image of the same scene will have very similar
p(rk) curves even though their raw nk counts differ by a factor of 1600.

3.2 Properties of an Image Histogram


Because a histogram is such a compact summary of an image, its overall shape alone tells an experienced viewer
a great deal about how the image is likely to look, even before it has been displayed:

● Total pixels: The sum of all bin counts equals the total number of pixels: Σ nk = M × N. This is simply a
consistency check — every pixel in the image contributes to exactly one bin.
● Left-skewed (mass concentrated at low gray levels) → the image looks dark, since most of its pixels sit
near the black end of the range.
● Right-skewed (mass concentrated at high gray levels) → the image looks bright / washed out, since most
of its pixels sit near the white end of the range.
● Narrow, clustered histogram → low contrast, because only a small band of the available gray levels is
actually being used, so neighbouring regions of the image tend to look similar to one another. Wide,
spread-out histogram → high contrast, because the full range of tones is being exploited, giving strong
visual separation between light and dark regions.
● A well-exposed image typically has a histogram spread fairly evenly across the full range, with no large
empty gaps and no extreme spike concentrated in one narrow band — this is precisely the property that
histogram equalisation (Section 3.4 onward) tries to engineer for an image that does not already have it.

Page 8
Module 2 — Image Transforms

3.3 Types of Histogram Processing


Histogram-based enhancement techniques reshape the intensity distribution of an image. Two common
approaches:

Technique Description

Linearly rescales the existing range of intensities to span the full [0,
Histogram Stretching
L−1] range. A simple contrast-expansion technique.

A non-linear transform that redistributes intensities using the


Histogram Equalisation cumulative distribution function (CDF), so that the output histogram is
approximately uniform.

3.4 Histogram Equalisation

Definition
Histogram Equalisation is a point-processing technique that increases the global contrast of an image by
transforming its intensity values so that the output histogram is as close as possible to a uniform
distribution — spreading out the most frequent intensity values over the full available range.

Why Do We Need It?


Many images — medical scans, satellite photos, poorly-lit photographs — have pixel intensities crowded into a
narrow band. This produces low contrast: details are hard to see even though the information is present in the
data. Crucially, the information has not been lost or destroyed — the underlying scene still contains real
differences between neighbouring structures — it is simply compressed into such a small range of gray levels
that the human eye (and many downstream algorithms) cannot perceive it. The task of histogram equalisation is
to take that same information and re-express it using a much larger share of the available intensity range,
without inventing any new detail that was not already implicitly present in the data.

● Pixel values occupy only a small sub-range of [0, L − 1].


● Neighbouring objects have very similar gray levels, giving poor visual separation.
● Simple linear stretching helps, but does not account for how frequently each value occurs.
● Histogram equalisation reassigns levels based on cumulative frequency, giving more "spread" to
commonly occurring values.

3.5 Mathematical Basis


For a continuous variable, if r is thought of as a random variable in [0, L − 1] with probability density function
pr(r), the transformation:

s = T(r) = (L − 1) ∫₀ʳ pr(w) dw


produces an output variable s that has a uniform probability density in [0, L − 1]. For digital (discrete) images,
the integral is replaced by a summation, giving the discrete equalisation transformation used in practice:

sk = T(rk) = (L − 1) Σ(j=0 to k) pr(rj) = (L − 1)/(M×N) · Σ(j=0 to k) nj


Page 9
Module 2 — Image Transforms

3.6 Algorithm: Step by Step


● Step 1 — Compute the histogram: count nk, the number of pixels at each gray level rk, for k = 0 … L − 1.
● Step 2 — Compute the PDF: normalise, p(rk) = nk / (M×N), giving the probability of each intensity.
● Step 3 — Compute the CDF: form the running (cumulative) sum, CDF(rk) = Σ(j=0..k) p(rj).
● Step 4 — Scale to the output range: multiply by (L − 1) and round to the nearest integer, sk = round[(L −
1)·CDF(rk)].
● Step 5 — Remap every pixel: replace each pixel of intensity rk in the original image with the new
intensity sk.

3.7 Worked Example


Consider a 64 × 64 image (so M×N = 4096 pixels) with 3-bit gray levels (L = 8, levels 0–7), with the following
histogram data (this is the classic example used in the Gonzalez & Woods textbook):

rk 0 1 2 3 4 5 6 7

nk 790 1023 850 656 329 245 122 81

p(rk) = nk / 4096 0.19 0.25 0.21 0.16 0.08 0.06 0.03 0.02

CDF 0.19 0.44 0.65 0.81 0.89 0.95 0.98 1.00

sk = round(7·CDF) 1 3 5 6 6 7 7 7

Reading the last row: pixels originally at level 6 or 7 (dark, rare, high-cumulative levels) both map to output level
7 — several input levels can merge into one output level, which is expected in discrete equalisation. In this
example, the 8 original levels collapse into effectively 5 distinct output levels (1, 3, 5, 6, 7), but they are spread
across a wider span of the [0, 7] range — boosting overall contrast.

Fig. 3.1 — Original histogram (concentrated at low levels, dark/low-contrast image) versus equalised histogram (spread across the full
range, higher global contrast).

Visual effect: the original image looks flat and hazy because most pixels share nearly the same gray value. After
equalisation, the same scene shows sharper-looking edges and more visible detail — the underlying scene
content is unchanged, only how the intensities are distributed across the display range.

3.8 Applications

Page 10
Module 2 — Image Transforms

Application area How histogram equalisation helps

Enhancing contrast in X-ray, CT, and MRI scans so subtle tissue or


Medical Imaging
bone details become visible.

Improving visibility of terrain, cloud, and land-use features captured


Satellite & Aerial Imagery
under low or variable lighting.

Automatic contrast correction in cameras and photo-editing


Photography Enhancement
software for backlit or foggy shots.

Sharpening fingerprint ridges and low-quality surveillance footage


Forensics & Biometrics
for identification.

Highlighting defects or cracks in machine-vision quality-control


Industrial Inspection
systems.

Used as a standard preprocessing step before edge detection,


Preprocessing for CV / ML
segmentation, or feature extraction.

3.9 Advantages
● Fully automatic — no parameters to tune manually.
● Computationally simple and fast (a single pass to build the histogram, plus a running CDF).
● Effective for images that genuinely suffer from low global contrast.
● Uses the full available dynamic range of the display.
● Well understood mathematically; easy to implement and explain.

Page 11
Module 2 — Image Transforms

4. Fundamentals of Spatial Filtering


4.1 What Is Spatial Filtering?

Definition
Spatial filtering is an image processing technique in which the value of each pixel is modified based on the
values of its neighbouring pixels, using a small matrix called a kernel (or mask).

Spatial filtering works by moving a small kernel over the input image. At each position, the neighbourhood pixels
are combined with the kernel values to compute one output pixel. Repeating this process across the entire
image produces the filtered image. This is the true generalisation of the point-processing idea from Section 1.3:
instead of a 1×1 neighbourhood where the output depends on a single input pixel, spatial filtering uses an m×n
neighbourhood, so the output at every location can depend on a whole block of surrounding pixels. This is what
allows spatial filters to distinguish genuine structure (edges, boundaries) from isolated, spatially inconsistent
noise — something point processing alone can never do. The general form of the operation is:

g(x, y) = Σ Σ f(x+s, y+t) · w(s, t)


Applications of spatial filtering include noise removal, image sharpening, edge detection, and feature extraction
— the exact effect depends entirely on the values chosen for the kernel w. A kernel whose weights are all
positive and sum to 1 tends to smooth and blur (Section 5); a kernel whose weights sum to zero and contain
both positive and negative values tends to highlight change and sharpen (Section 6). Choosing the kernel is
therefore the central design decision in spatial filtering — the sliding, multiply-and-sum mechanism itself stays
exactly the same regardless of which effect is desired.

4.2 Spatial Correlation

Definition
Correlation is a spatial filtering operation in which the kernel is moved across the image without flipping.
The kernel is applied exactly as it is — it is not rotated or flipped; it is simply slid across the image, and at
each position the weighted sum of the overlapping pixels is computed.

g(x, y) = Σ(s,t) f(x+s, y+t) · w(s, t)


Symbol Meaning

g(x, y) Output (filtered) image pixel at location (x, y)

f(x+s, y+t) Pixel value of the input image within the neighbourhood

w(s, t) Kernel (filter) value at position (s, t)

(x, y) Coordinates of the current pixel being processed

(s, t) Offset (row and column) inside the kernel

Σ Sum of all products between the kernel and the corresponding image pixels

Page 12
Module 2 — Image Transforms

It is worth being very precise about the indexing convention here: the offsets s and t run over the kernel's own
coordinate system (for example, from −1 to +1 in each direction for a 3×3 kernel centred at the origin), and for
every kernel position (s, t) the corresponding input pixel f(x+s, y+t) is looked up and multiplied by the kernel
weight w(s, t) sitting at that same relative position. Because the sign in front of s and t is positive, the kernel's
top-left weight always lines up with the neighbourhood's top-left pixel, its centre weight always lines up with the
neighbourhood's centre pixel, and so on — the kernel is never mirrored or rotated before use. This direct,
unflipped alignment is the defining feature that separates correlation from convolution (Section 4.3).

Worked Example — Correlation


Consider the following 3 × 3 input image and a 2 × 2 kernel. The kernel is placed at successive positions across
the image, and at each position the overlapping values are multiplied element-by-element and summed to
produce one output pixel — exactly the mechanism shown step by step in Fig. 4.1 below:

Fig. 4.1 — Step-by-step correlation of a 3×3 input image with a 2×2 kernel, producing a 2×2 output. Each output value is the sum of
element-wise products between the kernel and the pixels it currently overlaps.

For the top-left kernel position, the input patch [[2, 3], [1, 0]] is combined with the kernel [[1, 0], [0, 1]]: (2×1) +
(3×0) + (1×0) + (0×1) = 2. Sliding the kernel across all valid positions produces the full output matrix. Notice that
the kernel values themselves are used exactly as given — no flipping is applied.

Page 13
Module 2 — Image Transforms

4.3 Spatial Convolution

Definition
Convolution is similar to correlation, except that the kernel is rotated by 180° before the multiply–sum
operation is performed.

Fig. 4.2 — Kernel flipping: the original kernel (left) is rotated by 180° — top-to-bottom and left-to-right — to give the flipped kernel (right)
used in true convolution.

Formally, 2-D discrete convolution is written as:

g(x, y) = f(x, y) * w(x, y) = Σ(s,t) f(x−s, y−t) · w(s, t)


The negative signs in the index (x−s, y−t) are exactly what perform the 180° rotation of the kernel relative to
correlation. For kernels that are symmetric (e.g. the average filter, or the Laplacian filter used later in this
module), the flipped kernel is identical to the original, so correlation and convolution give the same result —
which is why, in practice, many image-processing texts use the two terms loosely interchangeably for symmetric
kernels.

4.4 Correlation vs Convolution


Correlation Convolution

Kernel is not flipped Kernel is flipped (rotated 180°)

Measures similarity Performs filtering

Used in template matching Used in CNNs, general filtering

Simpler operation True mathematical convolution

Less used in deep learning Most commonly used

Page 14
Module 2 — Image Transforms

5. Smoothing Filters (Low-Pass Filters)

Definition
Smoothing filters reduce sharp intensity transitions between neighbouring pixels. Because both noise and
fine detail correspond to high spatial frequencies, averaging a pixel with its surroundings suppresses them
— producing a softer, blurred image.

The label "low-pass" comes directly from frequency-domain thinking: slowly-varying regions of an image (large
flat areas, gentle gradients) correspond to low spatial frequencies, while rapid pixel-to-pixel fluctuations (fine
texture, sharp edges, and random noise) correspond to high spatial frequencies. A smoothing filter allows the
low-frequency content to pass through relatively unchanged while attenuating the high-frequency content —
hence "low-pass". This is exactly why smoothing is effective against noise (which is almost entirely high-
frequency) but always comes at the cost of also softening genuine edges and fine detail, which are high-
frequency too.

5.1 Common Smoothing Filters


Filter Description

Replaces each pixel with the mean of its neighbourhood. Removes random
Average / Mean filter pixel-level noise such as Gaussian or salt-and-pepper noise. (Focus of this
module.)

Gives more weight to pixels closer to the centre; softens fine texture and
Weighted average filter
small unwanted artefacts.

Weights follow a Gaussian bell curve, giving smoother results and better
Gaussian filter
edge preservation than a plain average.

Non-linear; replaces a pixel with the neighbourhood median. Particularly


Median filter
effective against salt-and-pepper noise.

5.2 The Average (Mean) Filter

Definition
The average filter is the simplest linear smoothing filter. Every pixel in the output image is set to the
arithmetic mean of the pixel values within an m × n neighbourhood (kernel) in the input image, including
the pixel itself.

g(x, y) = (1 / mn) · Σ Σ f(x+i, y+j)


where mn is the total number of pixels in the m × n kernel window. For a standard 3 × 3 average kernel, every
one of the 9 weights equals 1/9, so the kernel weights sum to exactly 1 (which preserves the overall image
brightness). This weight-sum-equals-1 property is important and general: any smoothing kernel whose weights
sum to 1 will leave a perfectly uniform (flat) region of the image completely unchanged, since averaging identical
values simply reproduces that same value — it is only in regions where intensity varies (edges, noise, texture)
that the averaging operation actually does something, by pulling outlier values toward the local mean.

Page 15
Module 2 — Image Transforms

Fig. 5.1 — Left: 3×3 average (mean) kernel — each weight is 1/9. Centre and right: the 4-connected and 8-connected Laplacian kernels
(used later in Section 6).

How the Average Filter Works


● Step 1 — Place the kernel: centre the m×n kernel over a pixel of the input image f(x, y).
● Step 2 — Multiply & sum: multiply each neighbourhood pixel by its corresponding kernel weight (1/mn)
and add the results.
● Step 3 — Write the output: store the sum as the new pixel value g(x, y) in the output image.
● Step 4 — Slide & repeat: move the kernel one pixel at a time across the entire image (this sliding,
multiply-and-sum procedure is the convolution operation).

Worked Example — 3×3 Average Filter


Suppose a 3×3 neighbourhood of the input image has the pixel values 10, 20, 30, 40, 50, 60, 70, 80, 90 (read row
by row). Their sum is 450. Applying the 3×3 average kernel (each weight = 1/9):

New pixel value = 450 × (1/9) = 50


The centre pixel (originally 50) is replaced by the average of itself and its 8 surrounding neighbours — which
happens to also be 50 in this symmetric example.

Effect of Kernel Size on Smoothing


A larger averaging window removes more noise but also destroys more fine detail — a direct trade-off between
noise reduction and sharpness.

Page 16
Module 2 — Image Transforms

Fig. 5.2 — Top-left: original noisy image. Top-right: 3×3 average filter. Bottom-left: 7×7 average filter. Bottom-right: 11×11 average filter.
As kernel size grows, noise disappears but edges soften and blur increases.

As the kernel size grows (3×3 → 7×7 → 11×11), noise disappears but edges soften and blur increases. In practice,
one should choose the smallest kernel that adequately suppresses the noise present.

Applications & Limitations


● Pre-processing / de-noising before edge detection or segmentation.
● Removing sensor or transmission noise from scanned images.
● Creating deliberate blur effects and background softening.
● Limitation: averaging blurs edges along with noise, so fine detail and sharp boundaries are lost as the
kernel grows larger.

Page 17
Module 2 — Image Transforms

6. Sharpening Filters (High-Pass Filters)

Definition
Sharpening filters accentuate intensity transitions in an image. Rather than averaging, they emphasise
differences between a pixel and its neighbours — boosting edges, fine detail, and texture that smoothing
would otherwise remove.

Sharpening is, in a very real sense, the mirror image of smoothing: where a low-pass (smoothing) filter
attenuates high spatial frequencies and lets low frequencies through, a high-pass (sharpening) filter does the
opposite — it suppresses the slowly-varying, low-frequency parts of the image (flat backgrounds, gentle
shading) and amplifies the rapidly-varying, high-frequency parts (edges, lines, fine texture). Because derivatives
measure the rate of change of a signal, and rate of change is exactly what defines a spatial frequency,
sharpening filters in the spatial domain are built directly from discrete approximations to image derivatives —
which is why the Laplacian, a second-derivative operator, is the natural and classical choice studied here.

6.1 Common Sharpening Filters


Filter Description

Second-derivative operator; an isotropic edge detector. (Focus of this


Laplacian filter
module.)

Sobel / Prewitt filters First-derivative gradient operators used for directional edge detection.

Unsharp masking Subtracts a blurred copy of the image from the original to boost fine detail.

High-boost filtering Amplifies high-frequency content while still retaining the original image.

6.2 The Laplacian Filter

Definition
The Laplacian is a second-order derivative operator. It measures how fast the rate of intensity change itself
is changing, making it highly sensitive to edges, lines, and fine detail. It is isotropic, meaning it responds
equally in all directions.

For a continuous function f(x, y), the Laplacian is defined as:

∇²f = ∂²f/∂x² + ∂²f/∂y²


In digital image processing, this is approximated using discrete second differences, which leads directly to the
well-known Laplacian kernels shown below (already introduced in Fig. 5.1, and reproduced here for reference):

Page 18
Module 2 — Image Transforms

Fig. 6.1 — 3×3 kernels: (left) average filter; (centre) 4-connected Laplacian; (right) 8-connected Laplacian.

In both Laplacian kernels, the weights sum to 0, so a uniform (flat) region of the image produces an output of 0
— only regions where intensity changes abruptly produce a strong (positive or negative) response. The 8-
connected version also accounts for the diagonal neighbours, giving a stronger response to diagonal edges than
the 4-connected version.

How the Laplacian Sharpens an Image


● Step 1 — Convolve with kernel: apply the Laplacian kernel to the image to compute ∇²f at every pixel.
● Step 2 — Detect edges: large positive or negative responses mark locations of rapid intensity change;
flat regions stay near zero.
● Step 3 — Subtract from original: combine the Laplacian response back with the original image to boost
those edges.
The sharpening formula used is:

g(x, y) = f(x, y) − ∇²f(x, y)


The minus sign is used because the standard Laplacian kernel's centre weight is negative (e.g. −4 or −8);
subtracting a negative response effectively adds back the edge energy at that location. The result: edges and
fine details appear amplified, while smooth, flat regions stay nearly unchanged (their Laplacian response is close
to zero).

Example Result

Fig. 6.2 — Left: original image f(x,y). Centre: Laplacian response |∇²f| (outlines only, flat regions are black). Right: sharpened result f − ∇²f
— object outlines and shape edges are visibly crisper than in the original.

Notice how the object outlines, the circular boundary, and the other shape edges are visibly crisper in the
sharpened result compared with the original — while the flat interior regions of each shape remain essentially
unchanged.

Page 19
Module 2 — Image Transforms

Page 20
Module 2 — Image Transforms

7. Comparison: Average Filter vs. Laplacian Filter


Aspect Average Filter Laplacian Filter

Category Smoothing (low-pass) Sharpening (high-pass)

Order Zeroth-order (direct averaging) Second-order derivative

Kernel weight sum Equals 1 (preserves brightness) Equals 0 (flat areas → 0)

Effect on edges Blurs / softens edges Enhances / detects edges

Effect on noise Suppresses random noise Amplifies noise

Typical use De-noising, pre-processing Edge detection, detail enhancement

Page 21
Module 2 — Image Transforms

8. Quick-Revision Summary of Key Equations


Topic Key Equation

General spatial process g(x,y) = T[f(x,y)]

Point processing s = T(r)

Image negative s=L−1−r

Log transformation s = c·log(1 + r)

Histogram h(rk) = nk ; p(rk) = nk / (M×N)

Histogram equalisation (CDF) sk = round[(L−1) · Σ(j=0..k) p(rj)]

Correlation g(x,y) = ΣΣ f(x+s, y+t) · w(s,t)

Convolution g(x,y) = ΣΣ f(x−s, y−t) · w(s,t)

Average filter g(x,y) = (1/mn) ΣΣ f(x+i, y+j)

Laplacian operator ∇²f = ∂²f/∂x² + ∂²f/∂y²

Laplacian sharpening g(x,y) = f(x,y) − ∇²f(x,y)

Exam tip
For numerical problems, be ready to: (1) apply s = L−1−r or s = c·log(1+r) to a given pixel value; (2) build a
full histogram-equalisation table (nk → p(rk) → CDF → sk) for a small image; (3) hand-compute a 3×3
correlation or convolution output for a given kernel and image patch; and (4) compute a 3×3 average or
Laplacian filter output for a given neighbourhood of pixel values.

Page 22

You might also like