Module2 Notes
Module2 Notes
MODULE II
Image Transforms
Page 1
Module 2 — Image Transforms
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.
● 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.
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.
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.
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).
The syllabus for this module focuses on the two simplest and most illustrative of these: the image negative and
the log 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.
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
Definition
The general form of the log transformation is:
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:
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:
● 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
Technique Description
Linearly rescales the existing range of intensities to span the full [0,
Histogram Stretching
L−1] range. A simple contrast-expansion technique.
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.
rk 0 1 2 3 4 5 6 7
p(rk) = nk / 4096 0.19 0.25 0.21 0.16 0.08 0.06 0.03 0.02
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
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
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:
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.
f(x+s, y+t) Pixel value of the input image within the neighbourhood
Σ 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).
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
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.
Page 14
Module 2 — Image Transforms
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.
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.
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.
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).
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.
Page 17
Module 2 — Image Transforms
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.
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.
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.
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.
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
Page 21
Module 2 — Image Transforms
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