0% found this document useful (0 votes)
35 views

Ch03 IntensityTransformations

This document discusses digital image processing techniques for intensity transformation. It begins with an overview of basic intensity transformations like image negative, log transformations, power-law (gamma) transformations, and piecewise-linear transformation functions. It then covers histogram processing techniques like contrast stretching, intensity-level slicing, bit-plane slicing, and histogram equalization. Histogram equalization maps the intensity levels of an image such that the output image contains a uniform distribution of intensities. The document provides examples and illustrations of these intensity transformation and histogram processing concepts.

Uploaded by

joaolevi777
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)
35 views

Ch03 IntensityTransformations

This document discusses digital image processing techniques for intensity transformation. It begins with an overview of basic intensity transformations like image negative, log transformations, power-law (gamma) transformations, and piecewise-linear transformation functions. It then covers histogram processing techniques like contrast stretching, intensity-level slicing, bit-plane slicing, and histogram equalization. Histogram equalization maps the intensity levels of an image such that the output image contains a uniform distribution of intensities. The document provides examples and illustrations of these intensity transformation and histogram processing concepts.

Uploaded by

joaolevi777
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
You are on page 1/ 112

Digital Image Processing

Intensity Transformation

Prof. Tiago Vieira

Universidade Federal de Alagoas


[email protected]

November 11, 2021


Contents

Background

Some basic intensity transformations

Histogram processing

Fundamentals of spatial filtering

Smoothing spatial filters

Sharpening spatial filters

Combining spatial enhancement methods

Fuzzy logic for intensity transf. and filtering


Spatial domain processes can be denoted by

g (x, y ) = T [f (x, y )] (1)

I f (x, y ) - Input image.


I g (x, y ) - Output image.
I T [·] - Operator on f defined over a neighborhood of point
(x, y ).
Spatial domain processes can be denoted by

g (x, y ) = T [f (x, y )] (2)

I Spatial filtering using a 3 × 3 mask.


I Smallest neighborhood size 1 × 1.
I In this case, we have an intensity transformation function

s = T (r ). (3)

where s and r denote the intensity of g and f at point (x, y ),


respectively.
Examples of contrast stretching and thresholding.
Basic intensity transformations:
Image negative

s =L−1−r (4)
particularly suited for enhancing white or gray detail embedded in
dark regions.
Log transformations

s = c log(1 + r ), (5)

I Where c is a constant and it is assumed that r ≥ 0.


I The log transform maps a narrow range of low intensity values
in the input into a wider range of output levels.
I Used to expand the dark pixels in an image while compressing
the higher-level values.
I The opposite is true of the inverse log transformation.
I Compresses the dynamic range of images with large variations
in pixel values.
Classical application of the log transform; Fourier Spectra:
I It has values typically within range ∈ [0, 106 ] or higher.
I Such wide range cannot be faithfully represented without the
aid of a transform:
Power-lay (gamma) transformation
Basic form:
s = cr γ , (6)
where c and γ are positive constants.
Gamma correction.
I Cathode Ray Tube (CRT) have intensity-to-voltage response
that is a power function (exponents ∈ [1.8, 2.5].
I Example of gamma-correction using s = r 1/2.5 = r 0.4 :
Gamma correction is important:
I Accurately display an image in a computer screen.
I An image shown in a website is seen by millions of different
screens.
I Varying gamma affects color.
Piecewise-Linear Transformation Functions

I Piece-wise linear functions can be arbitrarily complex.


I Require, however, considerably more user input.
Contrast stretching

Low-contrast images can result from;


I poor illumination;
I lack of dynamic range in the imaging sensor, or even a;
I wrong setting of a lens aperture during image acquisition.

Contrast stretching
Process that expands the range of intensity levels in an image so
that it spans the full intensity range of the recording medium or
display device.
Picewise-linear transformation.
I r1 = s1 and r2 = s2 → linear
transformation, i. e., no
change.
I r1 = r2 , s1 = 0 and
s2 = L − 1 → thresholding.
I In general, r1 ≤ r2 and
s1 ≤ s2 , preserving the order
of intensity levels and
preventing the creation of
intensity artifacts.
Scanning electron microscope image of pollen ×700.
1. (r1 , s1 ) = (rmin , 0) and (r2 , s2 ) = (rmax , L − 1).
2. (r1 , s1 ) = (m, 0) and (r2 , s2 ) = (m, L − 1).
Intensity-level slicing

Highlight specific ranges of intensity;


1. binarize range of interest, or;
2. brightens (or darkens) desired range leaving the rest
unchanged.
Aortic angiogram near the kidney area.
Bit-plane slicing

Highlight the contribution made to total image appearance by


specific bits.
An example application of bit slicing: Image compression:

I Notice that the 4 most significant bits are sufficient to


reasonably “reconstruct” the original image (a reduction of
50% in bit memory storage);
Histogram processing

I The histogram of a digital image with intensity levels in the


range [0, L − 1] is a discrete function h(rk ) = nk where rk is
the kth intensity value and nk is the number of pixels in the
image with intensity rk .
I The histogram is commonly normalized by 1/n, with n = MN.
I The probability of occurrence of intensity value rk is
p(rk ) = nk /n, for k = 0, . . . , L − 1.
Examples:
Histogram is an important tool for image processing. It is used in
I Image enhancement.
I Statistical processing.
I Compression.
I Segmentation.
Furthermore:
I It is simple to compute.
I Cheap hardware implementation.
I Automatic.
Histogram equalization

I Consider (momentarily) continuous intensity values.


I r ∈ [0, L − 1] denotes the intensities of an image to be
processed.
I Consider intensity mappings of the form

s = T (r ) 0 ≤ r ≤ L − 1. (7)
Assume:
1. T (r ) is monotonically
increasing in the interval
0 ≤ r ≤ L − 1, and;
2. 0 ≤ T (r ) ≤ L − 1 for
0 ≤ r ≤ L − 1.
Considering the inverse

r = T −1 (s) (8)
I Intensity levels in an image may be viewed as random
variables in the interval [0, L − 1].
I Let pr (r ) and ps (s) denote the Probability Density Functions
(PDFs) of r and s.
I From probability theory, if pr (r ) and T (r ) are known, and
T (r ) is continuous and differentiable over the range of values
of interest, then the PDF of the transformed variable s can be
obtained using
dr
ps (s) = pr (r ) . (9)
ds
Consider the transformation function
Z r
s = T (r ) = (L − 1) pr (w )dw , (10)
0

which is the Cumulative Distribution Function (CDF) of random


variable r , which satisfies previous conditions.
From previous equation, one can derive
Z r 
ds d
= (L − 1) pr (w )dw = (L − 1)pr (r ). (11)
dr dr 0

dr
Substituting this result in ps (s) = pr (r ) yields. . .
ds
dr
ps (s) = pr (r )
ds
1
pr (r )
(L − 1)pr (r )
1
ps (s) = , 0 ≤ s ≤ L − 1. (12)
L−1
which is a uniform probability density function.
In other words, using the transformation
Z r
s = T (r ) = (L − 1) pr (w )dw ,
0

yields a random variable s characterized by a uniform PDF.


Note that:
I T (r ) depends on pr (r ), but;
I the resulting ps (s) is always uniform, independently of pr (r ).
nk
pr (rk ) = , k = 0, 1, . . . , L − 1.
n
k
X
sk = T (rk ) = (L − 1) pr (rj ).
j=0

k
(L − 1) X
sk = nj , k = 0, 1, . . . , L − 1. (13)
n
j=0

where
n = MN
Each input intensity rk is mapped into a level sk in the output
image, using Eq. (13).
Example: Hypothetical 64 × 64 = 4096 image with L = 8 intensity
levels.
rk nk nk /n sk sk
0 790 0.19 1.35 1
1 1023 0.25 3.10 3
2 850 0.21 4.55 5
3 656 0.16 5.67 6
4 329 0.08 6.23 6
5 245 0.06 6.65 7
6 122 0.03 6.86 7
7 81 0.02 7.00 7
Illustration of histogram equalization:

Figure: Illustration of histogram equalization of a 3-bit (8 intensity levels)


image. (left) Original histogram. (middle) Transformation function.
(right) Equalized histogram.
Step-by-step histogram equalization:
1. Compute image’s probabilities pr (rk ) = nk /n.
2. Compute cumulative
P probability distribution
sk = [(L − 1) /n] kj=0 nj .
3. Map pixels with values rk to intensity values (sk ).

Notice
Histogram equalization has the tendency to wider the range of the
intensity values, enhancing the contrast.
Figure: Original (left) and histogram equalized image (right).
Figure: Transformations (1) through
(4) were obtained from the
histograms of the images
(top-bottom) in the left column of
Pk
using sk = (L − 1/MN) j=0 nj , j =
0, 1, . . . , L − 1.
Histogram matching

Histogram equalization:
I Automatically determines a transformation function that seeks
to produce an output image that has a uniform histogram.
I If automatic enhancement is desired, this is a good approach
because;
I the results from this technique are predictable, and;
I the method is simple to implement.
I However:

Histogram matching
Sometimes it is useful to be able to specify the shape of the
histogram that we wish the processed image to have.
Histogram matching is:
I A trial-and-error process.
I Sometimes, the user might know what an “average”
histogram should look like.
I There are no general rules to specifying histograms, varying
between different cases.
Local histogram processing

I Histogram equalization and matching are global techniques.


I How to enhance details locally? Consider small windows
centered on each pixel.
I The global techniques presented can be applied locally.
Using histogram statistics for image enhancement
Statistics obtained from an image can be used for image
enhancement:
I r denotes a discrete random variable representing intensities
within range [0, L − 1].
I p(ri ) denotes the normalized histogram corresponding to
intensity ri .
I The mean
L−1
X
m= ri p(ri ). (14)
i=0
I The nth moment
L−1
X
µn = (ri − m)n p(ri ). (15)
i=0
The second moment is particularly important:
L−1
X
µ2 = σ 2 = (ri − m)2 p(ri ). (16)
i=0

I The mean m is a measure of average intensity.


I The variance σ 2 is a measure of contrast.
Notation when computing mean and moment on sub-images:
X
mSxy = rs,t p(rs,t ). (17)
(s,t)∈Sxy

X n
µnSxy = rs,t − mSxy p (rs,t ) (18)
(s,t)∈Sxy

As before, the local mean is a measure of average intensity in


neighborhood and the local variance σ 2 = µ2 is a measure of
intensity contrast in that neighborhood.
Consider the SEM image of a
tungsten filament.
We want to enhance areas which
I Have low intensity average
wrt the whole image.
I Have low contrast.
I Have not a constant
contrast.

E · f (x, y ) if mSxy ≤ k0 mG and k1 σG ≤ σSxy ≤ k2 σG
g (x, y ) = .
f (x, y ) otherwise
(19)
Where E increases (or decreases) the gray levels satisfying (19).
Values (require experimentation):
I E = 4.0. Sxy is a 3 × 3 region.
I k0 = 0.4, k1 = 0.02, k2 = 0.4.
Spatial filtering

I Spatial filtering is often used for image enhancement.


I Term filtering was borrowed from the frequency domain.
I Spatial filtering can be used for non-linear filtering, which
cannot be done in the frequency domain.
A spatial filter consists in
1. A neighborhood.
2. A predefined operation.
The spatial filter can be;
I linear, or;
I nonlinear.
a
X b
X
g (x, y ) = w (s, t)f (x + s, y + t), ∀ x, y . (20)
s=−a t=−b

Where:
I a = (m − 1)/2 and b = (n − 1)/2 form the window dimension
m × n (both odd numbers).
I Also called convolution.
I Note: the result of the operation does not change the original
image.
The basic procedure consists in summing the products between the
mask coefficients and the gray levels at the local image region.

R = w1 z1 + w2 z2 + . . . + w9 z9 .

In general;

R = w1 z1 + w2 z2 + . . . + wmn zmn
mn
X
R= wk zk
k=1

R = wT z (21)
Smoothing filters

I Smoothing filters are used for blurring and noise reduction.


I Blurring is used in pre-processing stages to remove small
details for object extraction.
I Noise reduction can be obtained also with non-linear filtering.
I Low-pass filtering.
I Neighborhood average.
I Results in a blurred image.
Smoothing filter mask examples:
Example: average filter (mask
sizes = 3, 5, 9, 15, 35).
Notice:
I Blurring.
I Blending.
I Noise reduction.
I Object elimination.
I Black border.
Gross representation of objects. Note:
Non-linear filters

Median filter:
I Useful for elimination of salt-and-pepper (or impulse) noise.
I The median ξ of a set of values is such that half the values in
the set are less than or equal to ξ and half are greater than or
equal to ξ.
I I. e., its main function is to force points with distinct intensity
levels to be more like their neighbors.
Salt and pepper noise removal using the median filter:
Sharpening spatial filters

Sharpening filters aim at:


I Enhancing fine details.
I Recovering information compromised by blurring.
Applications:
I Electronic printing.
I Medical imaging.
I Industrial inspection.
In the spatial domain:
I Blurring (averaging) is analogous to integration.
I Sharpening is analogous do differentiation.

Image differentiation enhances edges and other discontinuities


(e.g., noise) and deemphasizes areas with slowly varying intensities.
A first derivative:
I Must be zero in areas of constant intensity.
I Must be nonzero at the onset of an intensity step or ramp.
I Must be nonzero along ramps.
Basic definition of a first-order derivative of a one-dimensional
function:
∂f
= f (x + 1) − f (x). (22)
∂x
A second derivative:
I Must be zero in constant areas.
I Must be nonzero at the onset and end of an intensity step or
ramp.
I Must be zero along ramps of constant slope.
Definition of second order derivative
∂2f
= f (x + 1) + f (x − 1) − 2f (x). (23)
∂x 2
Notes on derivatives:
I 1st derivative:
I Produces thicker borders.
I Higher response to big differences (e.g., step).
I Often used for border detection.
I 2nd derivative
I More sensitive to finer details.
I Better for image enhancement, since its more sensitive.
I Produces double response to step.
Simplest isotropic 1 derivative operator: The Laplacian:

∂2f ∂2f
∇2 f = + . (24)
∂x 2 ∂y 2
Since:
∂2f
= f (x + 1) + f (x − 1) − 2f (x)
∂x 2
and
∂2f
= f (y + 1) + f (y − 1) − 2f (y ).
∂y 2
We have

∇2 f = f (x + 1, y ) + f (x − 1, y ) + f (x, y + 1) + f (x, y − 1) − 4f (x, y ) .


(25)

1
Independent of orientation
∇2 f = f (x + 1, y ) + f (x − 1, y ) + f (x, y + 1) + f (x, y − 1) − 4f (x, y )
Because the Laplacian is a derivative operator:
I It highlights intensity discontinuities in an image.
I De-emphasizes regions with slowly varying intensity levels.
The basic way to use the Laplacian for image sharpening is:

g (x, y ) = f (x, y ) + c∇2 f (x, y ) (26)

where:
I f (x, y ) and g (x, y ) are the input and sharpened images.
I c is −1 or +1 if the center of the filter is negative or positive,
respectively.
High-boost2 filtering

1. Blur the original image.


2. Subtract the blurred image from the original (the resulting
difference is called the mask).
3. Add the mask to the original.

2
“Alto reforço”
More formally:

gmask = f (x, y ) − f (x, y )


| {z }
Blurred image

g (x, y ) = f (x, y ) + k · gmask (x, y ). (27)


Where:
I k ≥ 0.
I k = 1, we have unsharp masking.
I When k > 1 we have highboost filtering.
Note: In fig 3.40 (d) and (e), k=1 and 4.5.
Examples with k =1.1, 1.15 and 1.2.
The gradient of f (x, y ) is defined as the two dimensional column
vector:
∂f
 
 
gx ∂x 
∇f ≡ = (28)

gy ∂f 
∂y
This vector points in the direction of the greatest rate of change of
f at (x, y ).
The magnitude of vector ∇f is
q
M(x, y ) = mag (∇f ) = gx2 + gy2 . (29)

is the value at (x, y ) of the rate of change in the direction of the


gradient vector.
Note that M(x, y ) is an image of the same size as the original.
In some implementations, it is more suitable computationally to
approximate the squares and square root operations by absolute
values:
M(x, y ) ≈ |gx | + |gy |. (30)
Now we define discrete approximations to the preceding equations
and formulate the masks.
I The smallest filter masks are of size 3 × 3.
Approximations to gx and gy using a 3 × 3 neighborhood centered
on z5 are as follows (The Sobel operators):

∂f
gx = = (z7 + 2z8 + z9 ) − (z1 + 2z2 + z3 ) (31)
∂x
and
∂f
gy = = (z3 + 2z6 + z9 ) − (z1 + 2z4 + z7 ) (32)
∂y
The Sobel operators:

Notes:
I The weight of 2 in the center coefficient is to achieve some
smoothing by giving more importance to the center point.
I The magnitude of the gradient is obtained with:

M(x, y ) ≈ |gx | + |gy |. (33)


Note
The coefficients in all masks sum to 0 (null response in an area of
constant intensity).
Application: Industrial inspection.
I Aid humans.
I Automatic detection.
Example: Sharpening an image
of nuclear whole body bone scan
(detect bone infection and
tumors).
Observe:
I Narrow dynamic range.
I High noise.
Strategy:
1. Laplacian to enhance detail.
2. Gradient to enhance borders.
Figure: ∇2 f (x, y ) Figure: g (x, y ) =
Figure: f (x, y )
(scaled). f (x, y ) − c∇2 f (x, y )
The Laplacian:
I Second-order derivative operator capable of enhancing fine
details.
I Noisy.
Figure: f (x, y ) Figure: M(x, y ) = |gx | + |gy |.
The gradient:
I Stronger average response in areas of significant image
transition (ramps and steps).
I Lower response to noise and fine detail.
Conclusions:
I Processes can be linked to achieve results better than single
techniques.
I Strategy depends on the application.
Applications
I Radiology.
I Physicians are unlikely to derive diagnosis from enhanced
images, but they serve as clues for further investigations.
Areas where the enhanced images are used:
I Printing industry.
I Image-based product inspection.
I Forensics.
I Microscopy.
I Surveillance.
Application of fuzzy sets to:
I Intensity transformation.
I Spatial filtering.
Definitions:
I A set is a collection of elements.
I Set theory conveys tools dealing with operations on and
among sets.
I Crispy set membership: an element is or isn’t inside a set.
Example:
I Z = set of all people.
I A = subset of young people.
I Suppose threshold = 20 years.
I Someone 20 years (and 1 second) old?!
A person now can be:
I Young.
I Relatively young.
I 50% young.
I Not so young.
I Not young, etc.
Fuzzy
Infinite valued membership functions;
I are the foundation of fuzzy logic, and;
I the sets generating them may be viewed as fuzzy sets.
Define:
I Z = set of elements.
I z = generic element of Z ; Z = {z}.

Definition
A fuzzy set in Z is characterized by a membership function µA (z),
that associates with each element of Z a real number in the
interval [0, 1].
I The value of µA (z) represents the grade of membership of z
in A.
An element z is;
I A full member of A if µA (z) = 1.
I Not a member of A if µA (z) = 0.
I A partial member of A if 0 < µA (z) < 1.
I Crispy sets are a particular case of Fuzzy sets.
Basic definitions:
I Empty set: A fuzzy set is empty if and only if its
membership function is identically zero in Z .
I Equality: Two fuzzy sets A and B are equal, written A = B,
if and only if µA (z) = µB (z) for all z ∈ Z .
I Complement: The complement (NOT) of a fuzzy set A,
denoted by Ā, or NOT(A), is defined as the set whose
membership function is

µĀ (z) = 1 − µA (z), ∀z ∈ Z .


Basic definitions:
I Subset: A fuzzy set A is a subset of a fuzzy set B if and only
if
µA (z) ≤ µB (z), ∀z ∈ Z .
I Union: The union (OR) of two fuzzy sets A and B, denoted
A ∪ B, or A OR B, is a fuzzy set U with membership function

µU (z) = max [µA (z), µB (z)] , ∀z ∈ Z .


Basic definitions:
I Intersection: The intersection (AND) of two fuzzy sets A
and B, denoted, A ∩ B or A AND B, is a fuzzy set I with
membership function

µU (z) = min [µA (z), µB (z)] , ∀z ∈ Z .

You might also like