EE409_4_Contrast_Enhancement

Page 1

EE409 – Digital Image Processing 2017-2018 Spring

4. Image Enhancement in Spatial Domain a) Contrast Enhancement

by: Dr. Gökhan Koray GÜLTEKİN

Matlab Built-in Images      

pout.tif (grayscale) moon.tif (grayscale) cameraman.tif (grayscale) peppers.png (color) coins.png (grayscale) saturn.png (grayscale)

Note: By default, imshow can only display double images in the range of [0, 1] and uint8 images in the range of [0-255]

1


Main Applications of DIP 

Image Enhancement

DIP – Dr. Arıöz

Main Applications of DIP  1. 

Two principal applications Improvement of pictorial information for human interpretation E.g. Contrast Enhancement

2


Application (I): Digital Photography

Application (II): Iris Recognition

before

after

3


Histogram Its ‘Histogram’ is obtained by counting the number of Consider the following image that

pixels of each color

include ‘dark blue’, ‘medium blue’ and ‘light blue’ pixels

(3, 8, 5)

Histogram •

Example:

f =

Use hist(f(:)) command

4


Histogram Plotting

Histogram of an image:

Histogram imhist(f)

h(rk) = nk Where: rk : kth gray level nk : # of pixels with having gray level rk

Gray levels

5


Histogram of an image: For example: we have 600 pixels having the intensity value ≈ 160 ďƒ h(160) = 600

h(rk) = nk Where: rk : kth gray level nk : # of pixels with having gray level rk

Histogram of an image: 3000 2500 2000 1500 1000 500 0 0

50

100

150

200

250

A visually pleasant image

6


Histogram of an image: 4

x 10 4 3.5 3 2.5 2 1.5 1 0.5 0 0

50

100

150

200

250

It is a baby in the cradle!

Histogram information reveals that image is under-exposed

Histogram of an image: 7000 6000 5000 4000 3000 2000 1000 0 0

50

100

150

200

250

Over-exposed image

7


Histogram of an image:  Low contrast image:

 High contrast image:

Point Processing: Arithmetic operations  These operations act by applying a simple function y=f(x) to each gray value in the image.  Simple functions include adding or subtracting a constant value to each pixel: y = x±C (imadd, imsubtract)  Multiplying each pixel by a constant: y = C·x (immultiply, imdivide)  Complement: For a grayscale image is its photographic negative.

8


Data types

 Assume we have an 8-bit grayscale image (uint8:0-255)

Arithmetic operations: Lazy man operation  yx y L

L

x

It does absolutely nothing at all! 18

9


Arithmetic operations: Addition, subtraction

y = x + 128

y = x - 128

Arithmetic operations: Multiplication, division

10


Complement

Addition Example

Image: I

Image: I+50

11


Subtraction Example

Image: I

Image: I-80

Multiplication Example

Image: I

Image: I*3

12


Division Example

Image: I

Image: I/2

Complement Example

Image: I

Image: 255-I

13


Bit planes • Greyscale images can be transformed into a sequence of binary images by breaking them up into their bit-planes. • We consider the grey value of each pixel of an 8-bit image as an 8-bit binary word. • The 0th bit plane consists of the last bit of each grey value. • This bit has the least effect (least significant bit plane). • The 7th bit plane consists of the first bit of each value (most significant bit plane).

Bit-Plane Slicing (example) 100

We have to use bitget and bitset to extract 8 images; 01100100 Image of bit1: 00000000

0

Image of bit2: 00000000

0

4

Image of bit6: 00100000

Image of bit5: 00000000

0

Image of bit3: 00000100

32

Image of bit4: 00000000

0

Image of bit8: 00000000

Image of bit7: 01000000

64

0

14


Bit-Plane Slicing in Matlab Example: Apply bit-plane slicing in Matlab. Read cameraman image, then extract the image of bit 6. Solution: x=imread('cameraman.tif'); y=x*0; [w h]=size(x); for i=1:w for j=1:h b=bitget(x(i,j),6); y(i,j)=bitset(y(i,j),6,b); end end figure, imshow(x); figure, imshow(y);

Initial Image

15


Bit plane 0

Bit plane 4

16


Bit plane 7

Gray Level Slicing Purpose: Highlight a specific range of gray values Two approaches:

1. Display high value for range of interest, low value else (‘discard background’)

2. Display high value for range of interest, original value else (‘preserve background’)

17


Gray Level Slicing

Output gray level

Thresholding function: g(x,y) = L if f(x,y) > t, 0 else t = ‘threshold level’

Input gray level

Gray Level Slicing

18


Gray Level Slicing Example: Read ‘cameraman’ image into Matlab, then if the pixel intensity in the old image is between (100  150) convert it in the new image into 255 (white). Otherwise it leaves it the same.

Gray Level Slicing Example: Read ‘cameraman’ image into Matlab, then if the pixel intensity in the old image is between (100  200) convert it in the new image into 255 (white). Otherwise it leaves it the same. Solution: x=imread('cameraman.tif'); y=x; [w h]=size(x); for i=1:w for j=1:h if x(i,j)>=100 && x(i,j)<=200 y(i,j)=255; else y(i,j)=x(i,j); end end end figure, imshow(x); figure, imshow(y);

19


Gray Level Slicing Example: Read ‘cameraman’ image into Matlab, then if the pixel intensity in the old image is between (100  200) convert it in the new image into 255 (white). Otherwise convert it to 0 (black).

Piecewise Linear Transformations

20


Piecewise Linear Transformations x   y    ( x  a)  ya   ( x  b)  y b 

0 xa a xb b xL

yb ya a b

0

41

L

x

a  50, b  150,   0.2,   2,   1, ya  30, yb  200

Piecewise Linear Transformations Clipping: 0 xa  0  y   ( x  a) a  x  b   (b  a) b  x  L 

42

0

a b

L

x

a  50, b  150,   2

21


Transformations Operation on the set of image-pixels

• The easiest case of operators • g(x,y) = T(f(x,y)) depends only on the value of •

f at (x,y) T is called a gray-level or intensity transformation function

Transformations T transforms the given image f(x,y) into another image g(x,y) T

f(x,y)

g(x,y)

22


Transformations Remember dividing image by a number

As we have an image, we can apply transformations to this function, e.g. T(f(x,y)) = f(x,y) / 2

Transformation function

Image

Power Law(Gamma) Transformations

T(f) = c*f ď §

23


Power Law(Gamma) Transformations

• •

varying gamma () obtains family of possible transformation curves >1 • Compresses dark values • Expands bright values <1 • Expands dark values • Compresses bright values

Log Transformations: T(f) = c * log (1+ f)

f: f(x,y) image

24


Log Transformations: y  c log10 (1  x) 0

c=100

L

x

49

Histogram Processing 

Histogram Equalization 

For discrete case 

Probabilities and summations instead of PDFs and integrals

The discrete version of the transformation

In general does not yield a uniform histogram, but spreads the histogram so that it spans a fuller range

25


Histogram Equalization 

We are interested in equal use of all gray level N pixels, range 0,..K-1 nk : number of pixels in level k Histogram

Accumulative Histogram

0

graylevels

255

1

#p < level

#p < level

#p in level

sk

Normalized Accumulative Histogram

0

graylevels

255

0

k

y k= ∑ n i

sk =

i= 1

graylevels

1 rk=k/K

yk k ni k =  =  p(rk ) N i=1 N i=1

Histogram Equalization Equalize: For every original gray level k     

Calculate the image histogram Find the cumulative sum of the histogram values - yk (in Matlab – cumsum(vec)) Normalize the values of the histogram accumulative sum by dividing in the total number of pixels Multiply the normalized vector in the maximal gray level value (K-1) and round (shift back to the original gray level range) Map the gray level values to the result of step (3) Normalized Accumulative Stretch the values back to the range 1,..K histogram 1 (improve contrast in the end of this process) sk

1 k sk = ni  (L 1) N i=1

s k=

1 N

k

∑ ni

#p < level

rk=k/K

i= 1 0

rk

sk

1

26


Histogram Equalization Example: No. of pixels 6

2

3

3

2

4

2

4

3

3

2

3

5

3

2

4

2

4

2

5 4

1

4x4 image Gray scale = [0,9]

Gray level 0 1 2 3 4 5 6 7 8 9

DIP-Dr. Tora

histogram

Histogram Equalization Example:

DIP-Dr. Tora

27


Histogram Equalization Example: No. of pixels

3

6

6

3

8

3

8

6

6

3

6

9

3

8

3

8

Output image Gray scale = [0,9]

6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9

Gray level Histogram equalization DIP-Dr. Tora

Histogram Equalization  In most discrete images it is impossible to obtain uniform histogram, we want to get as close as possible to uniform.  The number of bins can only decrease: bins can never split and small bins in the histogram may be united (but the effect is not visibly disturbing since it involves a very small number of pixels)  The histogram equalization process is monotonic (as the process involves accumulative sum) and therefore the relative brightness of a pixel is preserved 

28


When will this fail ? 

In General: On images with gray level distribution that is not ‘standard’ we may get unwanted results from the histogram equalization process.

Equalization results

29


Locally Adaptive Histogram Equalization 

Instead of doing histogram equalization using the whole image, compute the distribution for a moving window around the given pixel.

Avoids effect of bright light at one corner washing out everything in the image.

Matlab: ‘adapthisteq(f)’

Questions

?

30


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.