0% found this document useful (0 votes)
7 views54 pages

Lec004 Enhancement GrayLevelTrans Part-2

Uploaded by

aj713
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)
7 views54 pages

Lec004 Enhancement GrayLevelTrans Part-2

Uploaded by

aj713
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/ 54

CSD 212

Digital Image Processing

Image Enhancement :
Gray-Level Transformations
Part-2
Gray-Level Transformations

Histogram processing
– What is a histogram ?

Probability theory refresher
– What can it achieve ?
Gray-Level Transformations

Histogram processing
– What can it achieve ?
Gray-Level Transformations

Histogram processing
– What can it achieve ?
Gray-Level Transformations

Histogram processing
– What can it achieve ?
Gray-Level Transformations

Histogram processing
– What can it achieve ?
Gray-Level Transformations

Histogram processing
– What is a histogram ?

Probability theory refresher (very brief)
– Probability mass/density function
– Random variables
– Random experiments
– Sample space, events, probability functions
– Transformation of a random variable
Gray-Level Transformations

Random experiment = an experiment whose
outcome isn’t certain
– Flip of a coin
– Throw of a die


Sample space = set of all possible outcomes of a
random experiment
– Coin flip : { head, tail }
– Die throw : { 1, 2, 3, 4, 5, 6 }
Gray-Level Transformations

Random experiment
– Select a pixel location in an image

Sample space
– Set of all pixel locations
{ (1,1), (1,2), … , (1,8),
(2,1), (2,2), … , (2,8),

(8,1), (8,2), … , (8,8) }
Gray-Level Transformations

Event is a subset of a sample space
– Event of getting a head on a coin toss = { head }
– Event of getting an even number on a die roll = ?
= { 2, 4, 6 }
– Event of getting a pixel in the left half of the image


Event space = set of all possible events
Gray-Level Transformations

Probability function P(.)
– A probability function on sample space Ω
assigns every event A ⊆ Ω
a number ∈ [0,1] s.t.
● P (Ω) = 1

P (A U B) = P (A) + P (B) when A ∩ B = 0
– P(A) is the probability that event A occurs
– Examples
● Probability function for coin toss = ?

● Probability function for die roll = ?


Gray-Level Transformations

Random variable = a function
– X:Ω→R
– Domain = sample space
– Range = set of real numbers
Gray-Level Transformations

Random variable is an abstraction
– We don't care about outcomes (directly)
– We only care about values mapped to outcomes
– Examples

We don't care about die value, just even or odd

We don't care about pixel location, just pixel intensity !
Gray-Level Transformations

Defining events using random variables
– Example: Sum of a pair of dice
– Sample Space: Ω = { (i,j) : 1 <= i,j <= 6 }
– Probability function: P ( (i,j) ) = 1/36
– Random variable: X ( (i,j) ) = i + j
– Event { X=a } = { w ∈ Ω : X(w)=a }

P (X = 5)
= P ( { (1,4), (2,3), (3,2), (4,1) } )
= P ((1,4)) + P ((2,3)) + P ((3,2)) + P ((4,1))
= 4 / 36
Gray-Level Transformations

Defining events using random variables
– Example:
Intensity at a randomly-chosen pixel in 8x8 image f(x,y)
– Sample Space: Ω = { (x,y) : 1 <= x,y <= 8 }
– Probability function: P ( (x,y) ) = 1/64
– Random variable: X ( (x,y) ) = f (x,y)
– Event { X > 100 } = { w ∈ Ω : X(w) > 100 }
Gray-Level Transformations

Discrete random variable (RV)
– Maps outcomes to values in a countable set
– Probability mass function p : R → [0,1]
● Probability that the RV takes a value 'a'
● p (a) = P (X=a) = ∑w: X(w) =a P(w)
– Cumulative distribution function F : R → [0,1]
● Probability that the RV takes a value less than x
● F (a) = P (X <= a) = ∑w: X(w) <= a P(w)
● F (a) = P (X <= a) = ∑b : b <= a P(X=b)
Gray-Level Transformations

Continuous random variable (RV)
– Maps outcomes to values in an uncountable set

Sample space itself is uncountable
– e.g., continuous image function X(.) defined on [0,1]x[0,1]
– Probability density function p : R → R

p (x) is NOT probability (p(x) can be > 1)
● Events, of interest, are subsets of the form { x : a < x < b }
● p (a < x < b) = ∫a<x<b p (x) dx
– Cumulative distribution function F : R → [0,1]

Probability that the RV takes a value less than c
– p (x < c) = ∫x<c p (x) dx
– p (x < c) = ∫w: X(w) <= c P (w) dw
Gray-Level Transformations

Histogram equalization : Motivation
Gray-Level Transformations

Histograms are related to photograph exposure
– Aperture size (amount of light per unit time)
– Shutter speed (time of exposure)
Gray-Level Transformations

Histograms are related to photograph exposure
– Aperture size
– Shutter speed
Gray-Level Transformations

Histogram equalization
– Assume continuous distributions (and image)
– Given histogram p (a)
– Design function T (a) = b
such that
p (b) = uniform distribution
– Assume 0 < a < 1, 0 < b < 1
– Then, we want p (b) = 1

– Consider a monotonically increasing


intensity-transformation function T(.)
Gray-Level Transformations
p(a)

Histogram equalization
T(a)

p(b)
– Let b = T(a) a

– Mass conservation implies: p(a) da = p(b) db


– Integrate left hand side from 0 to a'
– Integrate right hand side from 0 = T (a') = b'
– Left hand side = CDFa (a')
– Right hand side = CDFb (b')
Gray-Level Transformations

Histogram equalization
– If we want p (b) = 1, then CDFb (b') = b'
– So, CDFa (a') = CDFb (b') = b'
– So, T (a) = CDFa (a)
– So, transformation function =
CDF of intensities in original image
Gray-Level Transformations

Histogram equalization example (3-bit image)
Rounding required,
if output needs to
be 3 bit

= CDF(r) * 7
Gray-Level Transformations
Gray-Level Transformations
Gray-Level Transformations

Why is the output histogram NOT exactly uniform ?
– Because of discretization of space and intensity
– Theoretically

Contradicts the assumption of continuous distributions
(i.e., continuous spatial domain, continuous intensities)

We used that to derive transformation for histogram equalization
– Practical problem (1 of 2)

Imagine 8-bit images → 256 intensities

Imagine an input image containing only 100 different intensities
● Uniform histogram must contain some pixels for each intensity
● How can we map 100 values to 256 values ?
– No systematic way to do that !
Gray-Level Transformations

Why is the output histogram NOT exactly uniform ?
– Because the set of intensities in digital images is discrete
– Practical problem (2 of 2)

Imagine 8-bit images → 256 intensities

Imagine an input image containing 256 different intensities and
2560 pixels

Uniform histogram must contain an equal number of (10) pixels
for each intensity

If some intensity “a” in input image has 20 pixels,
then intensity b=T(a) in output image will have >= 20 pixels

How can we decide which 10 of those >=20 pixels should be
assigned intensity “b” ?
– No systematic way to do that !
Gray-Level Transformations

Histogram matching
– Sometimes, we don't want to equalize
– But, we want to match the histogram of one image to
another chosen histogram (NOT uniform)

e.g., applications in medical imaging
– In that case, CDFa (a) = CDFb (b) implies
b = CDFb-1 (CDFa (a))
Gray-Level Transformations

Histogram matching
Gray-Level Transformations

Limitations of histogram equalization
– Images has lots of dark pixels or / and lots of bright pixels
– Then the “middle” intensities don't get contrast enhanced
– How can we get better output ? e.g., top right image

???

Hist. Eq.
Gray-Level Transformations

Limitations of histogram equalization
– Images has lots of dark pixels or / and lots of bright pixels
– Then the “middle” intensities don't get contrast enhanced

Hist. Eq.
Gray-Level Transformations

Adaptive histogram equalization (AHE)
– Localized analysis
– Algorithm:
For each pixel “p”

Construct a window of size NxN around the pixel

Perform (partial) histogram equalization within that window
(1) Compute histogram within window
(2) Compute CDF within window
(3) Map the intensity of the center pixel “p” based on the CDF
– Window size N is a user-defined parameter
● User-defined parameter is also called “free” parameter
● How to choose N ?
Gray-Level Transformations

Adaptive histogram equalization (AHE)
Gray-Level Transformations

Adaptive histogram equalization (AHE)
– Variations in local histograms
Gray-Level Transformations

Input image Global Hist. Eq.

● On next slide:
AHE with square windows of widths 25, 64, 100, 200
AHE
AHE

Input Image Hist. Eq.


Gray-Level Transformations

Adaptive histogram equalization (AHE)
Gray-Level Transformations

Limitations of adaptive histogram equalization
– Small window size → bring out more detail
– Small window size → amplify noise in constant patches


How to try to get the best of both worlds ?
– We want to enhance texture, without amplifying noise
Gray-Level Transformations

Contrast-limited adaptive histogram equalization
(CLAHE)
– Principle: Contrast amplification in the vicinity of a given
pixel value is given by:

Slope of the transformation function
= Slope of the CDF

But CDF slope depends on histogram (PDF) value
Gray-Level Transformations

Contrast-limited adaptive histogram equalization
(CLAHE)
– Limits the amplification by:
(1) Clip the histogram at a predefined value (free parameter)
(2) Redistribute the mass uniformly throughout the range
(3) Then, compute the CDF
AHE
CLAHE Gray-Level Transformations
Gray-Level Transformations

(CL)AHE is computationally expensive
– Computes PDF (+ CDF) at window around at every pixel

Approximations to (CL)AHE for speedup
(1) Split image into MxM non-overlapping tiles

e.g., M = 9
(2) Compute CDF for each tile
(3)Bilinearly interpolate transformation for all pixels based
on distances from tile centers
Gray-Level Transformations

Approximations to CLAHE for speedup
(1) Split image into MxM non-overlapping tiles
(2) Compute CDF for each tile
(3)Bilinearly interpolate transformation for all pixels based
on distances from tile centers

You might also like