0% found this document useful (0 votes)
4 views63 pages

Lecture02-Part II

The document discusses various intensity transformation methods used in image processing, including well-defined mathematical functions and arbitrary user-defined functions. It covers techniques such as logarithmic, exponential, and power-law transformations, as well as contrast stretching and bit-plane slicing. Additionally, it explains the importance of histograms in analyzing image contrast and the process of histogram stretching for contrast enhancement.

Uploaded by

Zyad Samy
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)
4 views63 pages

Lecture02-Part II

The document discusses various intensity transformation methods used in image processing, including well-defined mathematical functions and arbitrary user-defined functions. It covers techniques such as logarithmic, exponential, and power-law transformations, as well as contrast stretching and bit-plane slicing. Additionally, it explains the importance of histograms in analyzing image contrast and the process of histogram stretching for contrast enhancement.

Uploaded by

Zyad Samy
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/ 63

DATA SCIENCE PROGRAM

DS617

Image Processing

Lecture 2 – Part II
Intensity Transformation Methods
 They take the form of: s = T(r)
Where s refers to the enhanced output image pixel value and r refers
to the original input image pixel value.
 Because T depends only on the intensity (gray-level) value at a pixel
and not explicitly on its spatial coordinates (x,y) and T is referred to
as a intensity (gray-level) transformation function.
 They are divided into two types:
Well-Defined Mathematical Function Based
Arbitrary User-Defined (Piecewise Linear) Function Based

r
Well-Defined Mathematical Function Based Transformation
 There are many different kinds of them where the most common:
 Linear
 Negative
 Identity

 Logarithmic
 Log
 Inverse Log (Exponential)

 Power-Law
 nth root (Same as Log)
 nth power (Same as Inverse Log)
Image Negative
 The negative of an image with gray levels in range [0,L-1] is obtained
by the following negative transformation expression:
s=L–1–r
 Reversing the intensity levels of an image.

 Useful for enhancing white or gray detail embedded in dark regions


of an image, especially when the black areas are dominant in size.

Original Negative
Image s = Intsmax - r Image
Image Negative Example
Logarithmic (Log) Transformation
• The simplified form of logarithmic transformation is:
s = c x log(1 + r)
Where c > 0 is a constant that scales the output s by increasing its
brightness over the image quantization range (0-255) and r ≥ 0.

• The scaling constant c can be calculated based on the maximum


allowed output pixel value (255 for a gray-level image) and the
maximum pixel value present in the input image, max(r), as follows:
c = 255 / log[1 + max(r)]

• In practice, as the natural logarithm function is undefined for r = 0, so


the addition of 1 is included to prevent such problems.

• Logarithm transform replaces each pixel value in a given input image


with its natural logarithm (ln) value to compress the dynamic range of
images with large variations in pixel values.
Logarithmic (Log) Transformation (2)
• The general form of logarithmic transform is:
s = c * ln[1 + (eσ – 1) * r]
Where 0 < σ < 1 is a scaling factor controls the level of dynamic range
compression for pixels values of the input image.

• As the logarithmic function is close to linear near the origin, the


compression achieved is smaller for an image containing a low range
of pixel values than one containing a high range of pixel values.
Logarithmic (Log) Transformation (3)
• Logarithmic transformation increases (expands) a narrow range of
low gray-level values (darker regions) in the input image into a wider
range of gray-level values in the output image.

• Logarithmic transformation decreases (compresses) a wider range of


high gray-level values (lighter regions) in the input image into a
narrow range of gray-level values in the output image.

• A common variant which achieves a broadly similar result is the


square-root transform which similarly compresses high-value pixel
ranges and spreads out low-value pixel ranges.
s = c x sqrt(1 + r)

• Square-root transform replaces each pixel value in a given input


image with its square-root value to compress the dynamic range of
images with large variations in pixel values.
Logarithmic (Log) Transformation Example
• By applying the logarithmic transform we brighten the foreground of
this image by spreading its pixel values over a wider range and reveal
more of its detail whilst compressing the background pixels range.
Exponential (Inverse Logarithmic) Transformation
• The simplified form of exponential transformation is:
s = c x br
Where b is the basis, c > 0 scales the output s by increasing its
brightness over the image quantization range (0-255) and r ≥ 0.

• From the formula, r = 0 yields s = c, so to avoid the resulting offset:


s = c x (br-1)

• The choice of b depends on the level of dynamic range compression


required; b ≥ 1 are suitable for photographic image enhancement.

• In the exponential transformation, each pixel intensity value in the


enhanced output image is equal to a basis value raised to the value of
the corresponding pixel value in the original input image, to compress
the dynamic range of images with large variations in pixel values.
Exponential (Inverse Logarithmic) Transformation (2)
• The general form of exponential transform is: s = c * [(1+α)r - 1]
Where (1+α) is the basis and 0 < α < 1 is a constant controls the level
of dynamic range compression for pixels values of the input image.

• As the exponential function is close to linear near the origin, the


compression is greater for an image containing a lower range of pixel
values than one containing a higher range of pixel values.

• Exponential transformation enhances details in brighter regions of


high gray-level values whilst decreasing the dynamic range in darker
regions of low gray-level values (inverse logarithmic transformation).
Exponential (Inverse Logarithmic) Transformation Example
• The contrast of the background in the original image can be improved
by applying the exponential transform, but at the expense of contrast
in the darker areas of the image.
• The background is a high-valued area of the image (bright), whilst the
darker regions have low pixel values.
Power-Law (Gamma) Transformation
• Power-law transformation have the
following form: s = c * r γ
Where c and γ are positive
constants

• When γ < 1, enhances the contrast


of low-value portions of the image
at the expense of high-value
portions (logarithmic
transformation)

• When γ > 1, enhances the contrast


of high-value portions of the image
at the expense of low-value
regions (inverse logarithmic or
exponential transformation)

• Varying γ gives a whole family of


curves, so it’s called gamma
correction transformation.
Power-Law Transformation Example
Power-Law Transformation Example (2)
• The images to the right show a magnetic resonance image (MRI) of a
fractured human spine

• Different curves highlight different s = r 0.6


detail with c = 1 in all cases

• As gamma decreased, as more detail

s = r 0.3
became visible (more brighter)
Power-Law Transformation Example (3)
• An aerial photo of a
runway is shown

• This time, power law s = r 3.0


transforms are used
to darken the image

s = r 5.0
• As gamma increased,
as more detail became
lost (more darker)
Arbitrary User-Defined (Piecewise Linear) Transformation
 Rather than using a well-defined mathematical function we can use
arbitrary user-defined transformation (piecewise linear function).

 An advantage of these functions is that they can be complex while a


disadvantage is that they require more user input.

 Contrast stretching, gray-level slicing and bit-plane slicing are


simple forms of the spatial piecewise linear transformation functions.

 Low-contrast images can result from poor illumination or lack of


dynamic range (the difference between the smallest and largest
pixel values within the image) in the imaging sensor.

 The idea of contrast stretching based enhancement is increasing the


dynamic range of the gray-levels values in the image being processed.
Piecewise Linear Transform: Contrast Stretching Example
 The images below show a piecewise linear transformation based
contrast stretching to add contrast to a poor quality image.

 The locations of (r1,s1) and (r2,s2) control the shape of transform


with the condition that r1 ≤ r2 and s1 ≤ s2 to preserve the gray-levels
order and to prevent the creation of intensity artefacts in the output
processed image.

 By setting (r1,s1) = (rmin,0) and (r2,s2) = (rmax,L-1) where rmin and rmax
are the minimum and maximum gray-levels in the image, this
transform stretches gray-levels linearly to the full range [0,L-1].
Piecewise Linear Transform: Gray-Level Slicing Example
 Highlights a specific range of gray-levels for certain feature enhancing
by thresholding or brightening the desired range of gray levels.
Bit-Plane Slicing
 Highlights the contributions made to total image appearance by
specific bits for analyzing the relative importance played by each bit
in order to determine the adequacy of number of bits needed to
quantize each pixel for image compression.

 Because each pixel’s gray-level in an intensity image is quantized by


8-bits, bit-plane 1 contains the all lowest order bits in the bytes
comprising the pixels and bit-plane 8 contains all the highest order
bits in the same bytes also comprising the pixels.
Bit-Plane Slicing Example
 Consider the image “coins.png” and the pixel representation of it:

 Consider the pixels that are bounded within the yellow line. The
binary formats for those values are (8-bit representation):
Bit-Plane Slicing Example (2)
 The binary format for the pixel value 167 is 10100111 and similarly,
for 144 it is 10010000

 This 8-bit image is composed of eight 1-bit planes.

 Plane 1 (left) contains the lowest order bit of all the pixels in the
image, and plane 8 (right) contains the highest order bit of all the
pixels in the same image.
Bit-Plane Slicing Example (3)
Bit-Plane Slicing Example (4)
 The nth plane in the pixels are multiplied by the constant 2n-1, i.e., for
10100111, multiply the 8 bit plane with 128 and 7 bit plane with 64.
(1x128)+(0x64)+(1x0)+(0x0)+(0x0)+(1x0)+(1x0)+(1x0)=128.

Image reconstructed using Image reconstructed using


7 and 8 bit planes 5, 6, 7 and 8 bit planes
Bit-Plane Slicing Example (5)
Bit-Plane Slicing Example (6)
Spatial Pixel Distribution: Histogram
 An image histogram is a plot of the relative frequency of occurrence
of each of the permitted pixel values in the image against the values
themselves.

 For a simple gray-scale image, the histogram can be constructed by


simply counting the number of times each gray-scale value (0–255)
occurs within the image.

 Visual inspection of an image histogram can reveal the basic contrast


that is present in the image and any potential differences in the gray
distribution of the image foreground and background components.

 In a dark image, the gray-levels (and hence the histogram) would be


clustered at the lower end of the dynamic range.
Spatial Pixel Distribution: Histogram (2)
 In a bright image, the gray-levels would be clustered at the upper end
of the dynamic range.

 In a well contrasted image, the gray-levels would be well spread out


over much of the dynamic range.
Spatial Pixel Distribution: Histogram (3)

4
x 10
4

3.5

2.5

1.5

0.5

0 50 100 150 200 250

It is a baby in the cradle!

 Histogram information reveals that image is under-exposed

29
Spatial Pixel Distribution: Histogram (4)

7000

6000

5000

4000

3000

2000

1000

0 50 100 150 200 250

 Histogram information reveals that image is over-exposed

30
Spatial Pixel Distribution: Histogram Example
 We see a histogram plot with two distinctive peaks: a high peak in the
lower range of pixel values (dark pixels) corresponds to the
background and a lower peak in the higher range of pixel values
(bright pixels) corresponds to the foreground objects (coins).
Histogram Stretching Based Contrast Enhancement
 In order to perform histogram stretching (normalization) based
contrast enhancement, first we must know the new lower and
upper pixel value limits over which the image is to be stretched
(normalized), denoted c and d respectively.

 Compute the histogram of the input image and select c and d such
that 5% of image pixels will be less than c and 5% greater than d).

 Second, we must scan the input image to determine the minimum


and maximum pixel values that we want to stretch (normalize),
denoted a and b respectively.

 Based on these four values (a, b, c and d), the image pixel dynamic
range is linearly stretched according to the following formula:
𝐼𝑖𝑛𝑝𝑢𝑡 𝑖,𝑗 −𝑎
𝐼𝑜𝑢𝑡𝑝𝑢𝑡 𝑖, 𝑗 = 𝑑−𝑐 +c
𝑏−𝑎
Histogram Stretching Based Contrast Enhancement (2)
• Pixel values less than a are all converted to c, and pixel values greater
than b are all converted to d.
Histogram Stretching Based Contrast Enhancement (3)
 The stretching from the old [a,b] range to the new [c,d] range is not
necessarily linear, but it can also be nonlinear using gamma option
where gamma (γ) ≠ 1.

 The nonlinear stretching formula is:


𝐼𝑖𝑛𝑝𝑢𝑡 𝑖,𝑗 −𝑎 𝛾
𝐼𝑜𝑢𝑡𝑝𝑢𝑡 𝑖, 𝑗 = 𝑑−𝑐 +c
𝑏−𝑎
Histogram Stretching Example
 Histogram stretching works as follows:
 Suppose we have an image with the histogram shown below,
associated with the following table of the numbers ni of grey values
Histogram Stretching Example (2)
 We can stretch the grey levels in the center of the range out by
applying the piecewise linear function shown in the next slide.

 This function has the effect of stretching the grey levels 5-9 to grey
levels 2-14 according to the following equation:

 Where i is the input grey level and j is the output grey level.
Input grey level i: 5 6 7 8 9
Output grey level j: 2 5 8 11 14

 Grey levels outside this range are either left alone (as in this case) or
transformed piecewise linearly according to the linear functions at
the both ends of the graph shown in the next slide.
Histogram Stretching Example (3)
Histogram Stretching Example (4)
 Since the gray levels are all clustered together in the center of the
histogram, the image is poorly contrasted, as indeed it.
 Given a poorly contrasted image, we would like to enhance its
contrast, by spreading out its histogram.
Histogram Stretching Example (5)
Lookup Table (LUT) Based Contrast Enhancement
 A lookup table (LUT) is a table that contains a set of all possible (full
range) input values arranged in increasing order R = { r0=0, r1=1,r2=2,
…, rk=k, …, rL-1=L-1}, and a corresponding set of output (mapped,
reassigned) values S = {s0, s1, s2, …, sk, …, sL-1} into which the input
values are correspondingly mapped.

 LUT operation can be implemented by replacing each pixel value by


the corresponding value in the LUT by indexing into this LUT.

 For operating on grayscale images of type uint8, such a table consists


of a single array of 256 intensity values, where each value is an
integer in the range [0,255]. So the above LUT operation (mapping)
can be generally written as Y=Intensity_Transform(X, LUT) where X is
the input image and Y is the output (modified input) image with LUT
being the input-to-output mapping LUT.
Lookup Table (LUT) Based Contrast Enhancement (2)

 There is a need to compute and populate the LUT based on a desired


input-output intensity-mapping function or graph.

 LUT mapping function corresponding to division by 2 looks like:

This means, for example, that a pixel with value 4 will be replaced
with 2; a pixel with value 253 will be replaced with value 126.
Lookup Table (LUT) Based Contrast Enhancement (3)
 LUT mapping graph looks like:
Lookup Table (LUT) Based Contrast Enhancement (3)
 As an example, suppose we wish to apply an LUT to implement the
contrast stretching graph shown below.
Lookup Table (LUT) Based Contrast Enhancement (4)
 The three equations of three lines are:
x ϵ [0,96]

x ϵ [97,160]

x ϵ [161,255]

These three equations can be written more simply as:


x ϵ [0,96]

x ϵ [97,160]

x ϵ [161,255]
Histogram Equalization Based Contrast Enhancement
 The trouble with the histogram-stretching and look-up table methods of
contrast enhancement is that they requires user input.

 A histogram equalization is an entirely automatic procedure to change


the histogram to one in which each grey level occurs with the same
frequency (uniform/flat).

 It is a sophisticated technique that can be used to improve the


dynamic range and hence the contrast of an image by non-linearly
reassigning pixel intensity values in the image under the subjection
to constraints that preserve image integrity.

• The image integrity is preserved by not allowing the reassignments


to affect the intensity information structure with respect to the
pixel geometry within the image under consideration.
Histogram Equalization Based Contrast Enhancement (2)
 More specifically, the main step in “histogram equalization” is to
obtain the LUT and then performing the remapping (reassignment) of
the image based on this LUT.
Histogram Equalization Based Contrast Enhancement (3)
 Histogram equalization works as follows:

 Suppose that an image has L different grey levels 0, 1, 2, …, L-1, and


grey level i occurs ni times in the image.

 Suppose also that the total number of pixels in the image is n so that
n0 + n1 + n2 +…+ nL-1 = n

 To transform grey levels to obtain a better contrasted image, change


𝒏𝟎 + 𝒏𝟏 + 𝒏𝟐 + …+ 𝒏𝒊
grey level i to: 𝑳−𝟏
𝒏
and this number is rounded to the nearest integer.
Histogram Equalization Based
Contrast Enhancement Example
 Suppose a 4-bit greyscale image has the histogram shown below
associated with the following table of the numbers ni of grey values
with n = 360:
Histogram Equalization Based
Contrast Enhancement Example (2)
 To equalize this histogram, we form running totals of the ni , and
multiply each by 15/360 = 1/24:
Histogram Equalization Based
Contrast Enhancement Example (3)
 We now have the following transformation of grey values, obtained
by reading off first and last columns in the table in the previous slide
Histogram Equalization Based
Contrast Enhancement Example (4)
Adaptive Histogram Equalization (AHE)
 Sometimes the overall histogram of an image may have a widely
spread distribution whilst the histogram of local regions is highly
skewed towards one end of the gray spectrum (regions that are
significantly lighter or darker than most of the image).

 It is often desirable to enhance the contrast of these local regions but


global histogram equalization is ineffective because it works well
when the distribution of pixel values is similar throughout the image.

 AHE improves on this by computing several histograms, each


corresponding to a distinct section of the image, and uses them to
redistribute the intensity values of the image.

 Therefore AHE is more suitable for improving the local contrast and
enhancing the definitions of edges in each region of an image.
Adaptive Histogram Equalization (AHE) (2)
 After Applying the global
histogram equalization to the
original image on the top, it is
true that the background
contrast has improved in the
equalized image on the bottom.

 But comparing the statue face in


both images inferring that most
of the information of the statue
face were lost due to over-
brightness and this is because its
histogram is not confined to a
particular region.
Adaptive Histogram Equalization (AHE) (3)

 The above image shows the result of applying AHE to the top original
image in the previous slide.

 AHE transforms each pixel with the ordinary histogram equalization


derived from a square neighborhood region surrounding the pixel.

 Pixels near the image boundary have to be treated specially, because


their neighborhood would not lie completely within the image.
Adaptive Histogram Equalization (AHE) (4)
 It works as follows:

1. The image is broken down into relatively equally sized small adjacent
blocks called “tiles” or local NxM (i.e., 8x8) neighborhood regions.

2. Each tile is histogram-equalized separately.

 A disadvantage of this method is that “block artifacts” can occur at


the boundaries between the tiles as a result of processing each such
tile in isolation, which gives impression of an image consisting of a
number of slightly incompatible blocks.

 The solution to these artifacts can be reduced by applying the


bilinear interpolation.
Adaptive Histogram Equalization (AHE) (5)
 Another disadvantage of this method is that it may increase contrast
too much and amplify noise in near-constant regions of the image,
since the histogram in such regions is highly peaked.

 The solution to contrast over-amplifying is to apply a limit, c, that is


placed on the overall increase in contrast applied to any given region.

 Contrast limiting is applied as follows:


 If any histogram bin frequency is above the specified contrast
limit, c (by default 40), those pixels are clipped and distributed
uniformly to other bins before applying histogram equalization.

 The addition of this contrast limiting extension to AHE produces the


contrast-limited adaptive histogram equalization (CLAHE).
Contrast-Limited Adaptive Histogram Equalization (CLAHE)
Based Enhancement Example
 Differing effects of the specified contrast limit c.
Histogram Matching Based Contrast Enhancement
 It is also called histogram specification based contrast enhancement.

 It is an automatic enhancement method in which the required


transformation of the input image is derived from a pre (an user)-
specified reference histogram, not necessarily being equalized,
taken from any arbitrary image of a similar kind that not necessarily
being of the same size, so that the histogram of the transformed
image matches the pre (user)-specified reference histogram.

 The previously explained histogram equalization method is a special


case of histogram specification in which the specified reference
histogram is uniformly distributed (equalized) and it must be of the
same total number of pixels.
Histogram Matching Based Contrast Enhancement (2)
 the main step in “histogram specification or matching” is to obtain
the LUT that would result in the image histogram of the input image
becoming the same as that of a target image (histogram-wise).

 Given the gray-levels r and z of the input and the target (reference)
images with their corresponding probability density functions (pdfs)
are pr(r) and pz(z).
Histogram Matching Example (3)
 The actual histogram of the output new image does not exactly but
only approximately matches with the specified reference histogram
because of dealing with discrete histograms.
Histogram Matching Example (4)
Histogram Equalization Vs Histogram Matching Example
The End

Questions?

You might also like