Sei sulla pagina 1di 52

EECS490: Digital Image Processing

Lecture #5

• Point transformations (cont.)


• Histogram transformations
– Equalization
– Specification
– Local vs. global operations
• Intro to neighborhoods and spatial filtering
EECS490: Digital Image Processing

Brightness & Contrast

© 2002 R. C. Gonzalez & R. E. Woods


EECS490: Digital Image Processing

Point Ops via Functional Mappings

Image: I , point
J J = [I ]
operator

Input Output

If I (r, c )= g
function,
Pixel: I(r,c) f J(r,c)
and f (g )= k
The transformation of image I into image J is then J (r, c )= k .
accomplished by replacing each input intensity, g, with
a specific output intensity, k, at every location (r,c)
where I(r,c) = g.
The rule that associates k with g is usually
specified with a function, f, so that f (g) = k.

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Ops via Functional Mappings

One-band Image J (r, c )= f (I (r, c )),


for all pixels locations (r, c ).

Three-band Image J (r, c, b)= f (I (r, c, b)), or


J (r, c, b)= f b (I (r, c, b)),
for b = 1,2,3 and all (r, c ).

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Ops via Functional Mappings

One-band Image J (r, c )= f (I (r, c )),


Either all 3 bands for all pixels locations (r, c ).
are mapped through
the same function,
f, or …
Three-band Image J (r, c, b)= f (I (r, c, b)), or
J (r, c, b)= f b (I (r, c, b)),
for b = 1,2,3 and all (r, c )…. each band is
mapped through
a separate func-
tion, fb.

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Ops via Functional Mappings

A look-up table (LUT) … then the LUT


implements a that implements f
functional mapping. is a 256x1 array
whose (g +1)th
value is k = f (g).
If k = f (g ),
for g = 0,…, 255,
To remap a 1-band
and if k takes on
image, I, to J :
values in {0,…, 255}, … J = LUT(I + 1)

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Ops via Functional Mappings

If I is 3-band, then
a) each band is mapped separately using the same
LUT for each band or
b) each band is mapped using different LUTs – one
for each band.

a) J = LUT(I + 1), or
b) J (:,:, b)= LUTb (I (:,:, b)+ 1) for b = 1,2,3.

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Ops via Functional Mappings


255

E.g.: index value


... ...
output value

101 64
102 68
127

103 69
104 70
105 70
106 71
0

0 127 255 ... ...


input value input output

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Ops via Functional Mappings

input output
...0 ... 0
cell index

contents
64
...32
a pixel with ...
is mapped to
this value this value
128 128
... ...
192 224
... ...
255 255

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

How to Generate a Look-Up Table

For example:
Let a = 2.
Let x {0,…,255}

 (x ; a )=
255
1 + e  a ( x 127 ) / 32

Or in Matlab:
a = 2;
x = 0:255; This is just
LUT = 255 ./ (1+exp(-a*(x-127)/32));
one example.

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Processes: Increase Brightness


R+G+ B
I=
3

255
127
 I k (r, c )+ g , if I k (r, c )+ g < 256
J k (r, c )= 
g
255, if I k (r, c )+ g > 255

0
g  0 and k {1,2 ,3 } is the band index.
0 127 255
transform mapping

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Processes: Decrease Brightness

255

255-g
127
0, if I k (r, c ) g < 0
J k (r, c )= 
 I k (r, c ) g , if I k (r, c )

0
g  0 and k {1,2 ,3 } is the band index.
0 127 255
transform mapping

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Processes: Increase Contrast

255
127
Let Tk ( r, c ) = a [I k (r, c ) 127]+ 127, where a > 1.0
0, if Tk (r, c ) < 0,

J k (r, c ) = Tk (r, c ), if 0  Tk (r, c )  255,

0
0 127 255
255, if Tk (r, c ) > 255. k  {1,2 ,3 } transform mapping


1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Processes: Decrease Contrast

255
127
Tk ( r, c ) = a[I k (r, c ) 127]+ 127,

where 0  a < 1.0 and k  {1, 2, 3 }.


0
0 127 255
transform mapping

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Processes: Contrast Stretch

255
MJ

127
Let mI = min[I (r, c )], M I = max[I (r, c )],
mJ = min[J (r, c )], M J = max[J (r, c )].
Then,
I (r, c ) mI mJ

0
J (r, c )= (M J  mJ ) + mJ . 0 mI 127 MI 255
M I  mI transform mapping

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Information Loss from Contrast


Adjustment

orig

lo-c

hi-c

histograms
1999-2007 by Richard Alan Peters II
EECS490: Digital Image Processing

Information Loss from Contrast


Adjustment
orig lo-c hi-c abbreviations:
original
low-contrast
high-contrast
restored
difference
orig lo-c lo-c
difference between
original and restored
rest diff low-contrast

orig hi-c hi-c


difference between
original and restored
rest diff high-contrast

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Processes: Increased Gamma

255
127
1/ 
I (r, c )
J (r, c ) = 255   for  > 1.0
 255 
0
0 127 255
transform mapping

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Point Processes: Decreased Gamma

255
127
1/ 
I (r, c )
J (r, c ) = 255   for  < 1.0
 255 
0
0 m 127 M 255
transform mapping

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Gamma Correction: Effect on


Histogram

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

The Probability Density Function of an Image

255
Let A =  hI k (g + 1).
g =0

Note that since hI k (g + 1)is the number of pixels in


I k (the k th color band of image I ) with value g,
A is the number of pixels in I . That is if I is
R rows by C columns then A = R  C.

Then, This is the probability


pdf 1 that an arbitrary pixel
pI k (g + 1) = hI k (g + 1)
[lower case] A from Ik has value g.
is the graylevel probability density function of I k .

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

The Probability Density Function of an Image

• pband(g+1) is the fraction of pixels in (a specific band of) an


image that have intensity value g.
• pband(g+1) is the probability that a pixel randomly selected
from the given band has intensity value g.
• Whereas the sum of the histogram hband(g+1) over all g from
1 to 256 is equal to the number of pixels in the image, the
sum of pband(g+1) over all g is 1.
• pband is the normalized histogram of the band.

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

The Probability Distribution Function of an


Image

Let q = [q1 q2 q3] = I(r,c) be the value of a PDF


randomly selected pixel from I. Let g be a
[upper case]
specific gray level. The probability that qk 
g is given by
g

g g  h ( + 1)
Ik

PI k (g + 1) =  pI k ( + 1) =  hI k ( + 1) =
1  =0
255 ,
 h ( + 1)
 =0 A  =0
Ik
 =0

where hIk( +1) is


the histogram of
This is the probability that
the kth band of I. any given pixel from Ik has
value less than or equal to g.

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

The Probability Distribution Function of an


Image

Let q = [q1 q2 q3] = I(r,c) be the value of a Also called CDF


randomly selected pixel from I. Let g be a for “Cumulative
specific gray level. The probability that qk  Distribution
g is given by
Function”.
g

g g  h ( + 1)
Ik

PI k (g + 1) =  pI k ( + 1) =  hI k ( + 1) =
1  =0
255 ,
 h ( + 1)
 =0 A  =0
Ik
 =0

where hIk( +1) is


the histogram of
This is the probability that
the kth band of I. any given pixel from Ik has
value less than or equal to g.

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

The Probability Distribution Function of an


Image
A.k.a. Cumulative Distribution Function.

• Pband(g+1) is the fraction of pixels in (a specific band of) an


image that have intensity values less than or equal to g.
• Pband(g+1) is the probability that a pixel randomly selected from
the given band has an intensity value less than or equal to g.
• Pband(g+1) is the cumulative (or running) sum of pband(g+1)
from 0 through g inclusive.
• Pband(1) = pband(1) and Pband(256) = 1; Pband(g+1) is non-
decreasing.
Note: the Probability Distribution Function (PDF, capital letters) and the Cumulative Distribution Function (CDF)
are exactly the same things. Both PDF and CDF will refer to it. However, pdf (small letters) is the density function.

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Intensity Transform Requirements

a) A monotonically increasing intensity transformation prevents an


intensity reversal which could cause artifacts in the transformed
image.
b) A strictly monotonically increasing intensity transformation
guarantees that the inverse transformation (from s=T(r) back to
r) will be 1:1 preventing ambiguities

© 2002 R. C. Gonzalez & R. E. Woods


EECS490: Digital Image Processing

Uniform Histogram Transform

These are pdf’s.


Gonzalez uses PDF
instead of pdf.

s = T ( r ) = ( L  1)  pr ( w ) dw L is the number of
gray levels.
0
Cumulative Distribution Function (CDF)

© 2002 R. C. Gonzalez & R. E. Woods


EECS490: Digital Image Processing

Histogram Equalization Example

Note: this same 3-bit (8 gray level) 64x64 pixel image will
be used for several examples

© 2002 R. C. Gonzalez & R. E. Woods


EECS490: Digital Image Processing

Histogram Equalization Example

( )
0

pdf s0 = T ( r0 ) = ( 8  1)  pr rj = 7 pr ( r0 ) = 7 ( 0.19 ) = 1.33


= T ( r ) = ( 8  1)  p ( r ) = 7 p ( r ) + 7 p ( r ) = 7 ( 0.19 ) + 7 ( 0.25 ) = 1.33 + 1.75 = 3.08
j1= 0
s1 1 r j r 0 r 1
j=0

= T ( r ) = ( 8  1)  p ( r ) = 7 ( 0.19 ) + 7 ( 0.25 ) + 7 ( 0.21) = 1.33 + 1.75 + 1.47 = 4.55


2
s2 2 r j
j=0
s3 = 5.67 s4 = 6.23 s5 = 6.65 s6 = 6.86 s7 = 7.00

Discrete CDF (transformation)


Input Output Discrete Output
0 1.33 1
1 3.08 3
2 4.55 5
3 5.67 6
4 6.23 6
Computed PDF 5 6.65 7
6 6.86 7
7 7.00 7

© 2002 R. C. Gonzalez & R. E. Woods 1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Histogram Equalization

Resulting histogram
when trying to achieve
uniform* equalized
histogram

*Resulting histogram
( )
k
sk = T ( rk ) = ( L  1)  pr rj
j=0 is usually not uniform
due to discrete
Must round off to nature of transform.
nearest integer value In this case we only
since only L integer
levels in output have five output
levels.

© 2002 R. C. Gonzalez & R. E. Woods


EECS490: Digital Image Processing

Histogram Equalization

dark

light

Low contrast

high contrast

© 2002 R. C. Gonzalez & R. E. Woods


EECS490: Digital Image Processing

Histogram Equalization

( )
k
sk = T ( rk ) = ( L  1)  pr rj
j=0
EECS490: Digital Image Processing

Histogram Specification

G(z) would be a
straight line for
equalization.

3. Compute CDF vq for desired histogram

1. Compute pdf (histogram) for input


image Inverting a discrete function is
far easier than inverting a
2. Compute CDF sk for this PDF continuous function

4. Match CDF’s for each sk to


create mapping table by
inverting G
© 2002 R. C. Gonzalez & R. E. Woods
EECS490: Digital Image Processing

Histogram Specification

Specified pdf

Original pdf

Actual transformed
CDF of specified pdf
image pdf
EECS490: Digital Image Processing

Histogram Specification Example


1. Compute the PDF of the image to be transformed

( )
0
s0 = T ( r0 ) = ( 8  1)  pr rj = 7 pr ( r0 ) = 7 ( 0.19 ) = 1.33
= T ( r ) = ( 8  1)  p ( r ) = 7 p ( r ) + 7 p ( r ) = 7 ( 0.19 ) + 7 ( 0.25 ) = 1.33 + 1.75 = 3.08
j1= 0
s1 1 r j r 0 r 1
j=0

= T ( r ) = ( 8  1)  p ( r ) = 7 ( 0.19 ) + 7 ( 0.25 ) + 7 ( 0.21) = 1.33 + 1.75 + 1.47 = 4.55


2
s2 2 r j
j=0
s3 = 5.67 s4 = 6.23 s5 = 6.65 s6 = 6.86 s7 = 7.00

Discrete CDF of input histogram


Input Output Discrete Output
0 1.33 1 Rounded off
1 3.08 3
2 4.55 5
3 5.67 6
4 6.23 6
Output CDF 5 6.65 7
(not discrete) 6 6.86 7
7 7.00 7

© 2002 R. C. Gonzalez & R. E. Woods 1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Histogram Specification Example


2. Compute the PDF for the specified histogram

( )
0
G ( z0 ) = ( 8  1)  pz z j = 7 pz ( z0 ) = 7 ( 0 ) = 0
G ( z ) = ( 8  1)  p ( z ) = 7 p ( z ) + 7 p ( z ) = 7 ( 0 ) + 7 ( 0 ) = 0
j1= 0

1 z j z 0 z 1
j=0

G ( z ) = ( 8  1)  p ( z ) = 7 ( 0 ) + 7 ( 0 ) + 7 ( 0 ) = 0
2

2 z j
j=0
G ( z3 ) = 1.05 G ( z4 ) = 2.45 G ( z5 ) = 4.55 G ( z6 ) = 5.95 G ( z7 ) = 7.00

Discrete CDF of desired histogram


Input Output Discrete Output
0 0 0 Rounded off
1 0 0
2 0 0
3 1.05 1
4 2.45 2
5 4.55 5
6 5.95 6
7 7.00 7

© 2002 R. C. Gonzalez & R. E. Woods 1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Histogram Specification Example


3. Match the PDFs to get the transformation

Discrete CDF desired


Discrete CDF of input histogram Pixel CDF Discrete CDF
Input CDF Discrete CDF 0 0 0
0 1.33 1 1 0 0
1 3.08 3 2 0 0
2 4.55 5 3 1.05 1
3 5.67 6 4 2.45 2
4 6.23 6 5 4.55 5
5 6.65 7 6 5.95 6
6 6.86 7 7 7.00 7
7 7.00 7

Discrete CDF of input histogram


Input CDF input CDF desired New Value
0 1 (1.33) 1 (1.05) 3
1 3 (3.08) 2 (2.45) 4
2 5 (4.55) 5 (4.55) 5
3 6 (5.67) 6 (5.95) 6
4 6 (6.23) 6 (5.95) 6
5 7 (6.65) 7 (7.00) 7
6 7 (6.86) 7 (7.00) 7
7 7 (7.00) 7 (7.00) 7
EECS490: Digital Image Processing

Histogram Specification Example


4. Put mapping in a LUT

Input Transformed Value


0 --> 3
1 --> 4
2 --> 5
3 --> 6
4 --> 6
5 --> 7
6 --> 7
7 --> 7
EECS490: Digital Image Processing

MATLAB: Histogram Equalization

HISTOGRAM EQUALIZATION IN MATLAB

>> f=imread(‘fig10.10(a).jpg’); % load in figure 3.15(a)


>> imshow(f) % show image in a window
>> figure, imhist(f) % show histogram in a new window
% This histogram is not normalized.
>> ylim(‘auto’) % set histogram tick marks and
% axis limits automatically
>> g=histeq(f,256); % Create histogram equalized image
% you can also do this with
% the cumsum function
>> hnorm=imhist(f)./numel(f); % compute normalized histogram
>> figure, imshow(g) % show this figure in a new window
>> figure, imhist(g) % generate a histogram of
% the equalized image
>> ylim(‘auto’) % set limits again

SEE GWE, Section 3.3.3 for a discussion of histogram specification using MATLAB
EECS490: Digital Image Processing

MATLAB: Useful Transformations

THRESHOLDING

>> f=imread(‘fig10.10(a).jpg’); % load in an image


>> g=(f>100)*255 % show figure in a new window

(f>100) evaluates to 1 (true) if the pixel is >100, or 0 (false) if the pixel is 100

Multiplying by 255 is necessary to have a uint8 255 level image.

ROTATION

>> f=imread(‘fig10.10(a).jpg’); % load in an image


>> g=imrotate(f,angle,’method’); % rotate it by angle

%Supports methods: ‘nearest’, ‘bilinear’, ’bicubic’


bilinear
EECS490: Digital Image Processing

MATLAB: Getting Picture Coordinates

INPUT CURSOR VALUES


%(Very useful for specifying reference points in an image)
>> [x,y]=ginput
%Displays the graph window, displays a cross hair. Will input
%coordinate pairs from the graph window until you type return.
%Position cursor using mouse and click to input each coordinate pair.

x=
778.3362
619.7249
844.4242
465.5196

y=
213.0831
327.6357
470.8264
609.6112

>> [x,y]=ginput(n)
Will input n coordinate pairs until you press return
EECS490: Digital Image Processing

Examples of Point Processing

- gamma - brightness original + brightness + gamma

histogram mod - contrast original + contrast histogram EQ


1999-2007 by Richard Alan Peters II
EECS490: Digital Image Processing

Histogram
EECS490: Digital Image Processing

Histogram Equalization
EECS490: Digital Image Processing

Histogram Specification

Manually
specified
histogram h

(1) CDF sk=G(zq)


corresponding to h
(2) Inverse transform z=G-1(sk)
for intensity mapping

Resulting
histogram
EECS490: Digital Image Processing

Local Histogram Operations


EECS490: Digital Image Processing

Local Histogram Operations

 Ei f ( x, y ) if mSxy  k0 mg AND k1 G   Sxy  k2 G


g ( x, y ) = 
 f ( x, y ) otherwise

compare to global
mean mG and standard
deviation G
EECS490: Digital Image Processing

Spatial Neighborhoods

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Spatial Filtering

Let I and J be images such that J = T [I].


T [·] represents a transformation, such that,

J (r, c ) = T [I ](r, c ) =
f ({I (u, v ) u  {r  s,..., r,...r + s}, v  {c  d ,..., c,...c + d }}).

That is, the value of the transformed image, J, at pixel location


(r,c) is a function of the values of the original image, I, in a 2s+1
 2d+1 rectangular neighborhood centered on pixel location (r,c).

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Moving Windows

• The value, J(r,c) = T[I](r,c), is a function of a rectangular


neighborhood centered on pixel location (r,c) in I.
• There is a different neighborhood for each pixel location,
but if the dimensions of the neighbor-hood are the same for
each location, then trans-form T is sometimes called a
moving window transform.

1999-2007 by Richard Alan Peters II


EECS490: Digital Image Processing

Spatial Filtering

© 2002 R. C. Gonzalez & R. E. Woods


EECS490: Digital Image Processing

Moving-Window Transformations

Neutral
Buoyancy We’ll take a
Facility at section of
NASA this image to
Johnson demonstrate
Space
the MWT
Center

photo: R.A.Peters II, 1999

1999-2007 by Richard Alan Peters II

Potrebbero piacerti anche