DIP Lecture-3-6

64
Digital Image Processing: Image Enhancement Dr. Faraz Akram The University of Faisalabad Lecture -3

description

Digital Image Processing lecture 3-6

Transcript of DIP Lecture-3-6

Page 1: DIP Lecture-3-6

Digital Image Processing:Image Enhancement

Dr. Faraz AkramThe University of Faisalabad

Lecture-3

Page 2: DIP Lecture-3-6

2 Image enhancement

Image is NOT Perfect Sometimes

Page 3: DIP Lecture-3-6

3 Image enhancement

Image Enhancement is the process that improves the quality of the image for a specific application.

e.g.) A method that is quite useful for enhancing x-ray images may not necessarily be the best approach for enhancing pictures of Mars transmitted by a space probe.

There is no general theory of image enhancement.

- When an image is processed for visual interpretation, the viewer is the ultimate judge of how well a particular method works.

- Subjective

Page 4: DIP Lecture-3-6

4 Image Enhancement Methods

Spatial Domain Methods (Image Plane)Techniques are based on manipulation of pixels in an image. direct

Frequency Domain MethodsTechniques are based on modifying the Fourier transform of the image.

Combination MethodsThere are some enhancement techniques based on various combinations of methods from the first two categories.

Page 5: DIP Lecture-3-6

5 Spatial Domain Methods

Spatial domain methods are procedures that operate directly on these pixels. Spatial domain processes will be denoted by the expression:

In addition, T can operate on a set of input images.

Output Image Input Image (= function)

Operator

Page 6: DIP Lecture-3-6

6 Basic grayscale transformations

1- Image Negatives:

Pixels of the output Image

Pixels of the Input Image

Operator

(0,1,2,…,254,255)(255,254,…,1,0)

Page 7: DIP Lecture-3-6

7 Basic grayscale transformations

2- log Transformations:

• Compress the dynamic range of the image.• e.g. to Visualize Fourier spectra

Page 8: DIP Lecture-3-6

8 Basic grayscale transformations

3- Power-Law (gamma) Transformation:

• The exponent is called gamma (γ)• Gamma correction

• reduce contrast• enhance contrast

Page 9: DIP Lecture-3-6

9 Example: contrast enhancement

=0.6

=0.4 =0.3

• reduce contrast

Page 10: DIP Lecture-3-6

10 Example: contrast enhancement

enhance contrast

=3

=5=4

Page 11: DIP Lecture-3-6

12 Assignment #1

Task

1) Apply negative transformation on image ‘test1.jpg’. 2) Apply log transformation on image ‘Test-2.png’3) Apply gamma correction to enhance the image “Test3.jpg” using different values of gamma.

Page 12: DIP Lecture-3-6

13 Solution to assignment # 1

original image Image negative

Task

1) Apply negative transformation on image ‘test1.jpg’.

%% Image Negativer=imread('Test1.jpg');L=256;s=(L-1)-r;

subplot(1,2,1);imshow(r);title('original image');

subplot(1,2,2);imshow(s);title('Image negative');

Page 13: DIP Lecture-3-6

14 Solution to assignment # 1

Task

2) Apply log transformation on image ‘Test-2.png’

original image Log Transform

%% Log Transformr=imread('Test2.PNG');c=1;s=c*log10(double(1+r));

figure;subplot(1,2,1);imshow(r);title('original image');

subplot(1,2,2);imshow(s);title('Log Transform');

Page 14: DIP Lecture-3-6

15 Solution to assignment # 1

Task

3) Apply gamma correction to enhance the image “Test3.jpg” using different values of gamma. Original gamma correction

%% Gamma Correction r = imread ('Test3.jpg'); c=10; gamma=2.9; r=im2double(r); s=c*(r.^gamma);

figure subplot(1,2,1) imshow(r); title('Original');

subplot(1,2,2) imshow(s) title(‘gamma correction');

Original gamma correction

Page 15: DIP Lecture-3-6

Digital Image Processing:Image Enhancement

Dr. Faraz AkramThe University of Faisalabad

Lecture-4

Page 16: DIP Lecture-3-6

17

Basic gray level transformations1) Linear (negative and Identity)

2) Logarithmic (log and Inverse log)

3) Power law transformation

Piecewise-linear transformations4) Contrast stretching and thresholding

5) Intensity-Level Slicing

6) Bit-Plane Slicing

Histogram processing7) Histogram sliding

8) Histogram stretching

9) Histogram equalization

10) ……….

11) ……….

Page 17: DIP Lecture-3-6

18

Piecewise-linear transformations1. Contrast stretching and thresholding

2. Intensity-Level Slicing (gray level slicing)

3. Bit-Plane Slicing

Page 18: DIP Lecture-3-6

19 Piecewise linear transformation

1- Contrast stretching and thresholding:

(r1, s1)

(r2, s2) (r2, s2)

(r1, s1)

Thresholding:Contrast stretching

(r1, s1)

(r2, s2)

Page 19: DIP Lecture-3-6

20 Contrast stretchingPixels above 180 become 255

Pixels less than 90 become 0

Example: in the graph, suppose we have the following intensities : a=90, b=180, m=100

if r is above 180 , it becomes 255 in s.

If r is below 90 , it becomes 0,

If r is between 90, 180 , T applies as follows:

when r < 100 , s closes to zero (darker)

when r > 100 , s closes to 255 (brighter)

If r >180; s =255If r <180 and r<90; s=T(r)If r <90; s =0

T=

This is called contrast stretching, which means that the bright pixels in the image will become brighter and the dark pixels will become darker, this means : higher contrast image.

Page 20: DIP Lecture-3-6

21 Example: Contrast Stretching

Image (r(Image (s( after applying T (contrast stretching)

Notice that the intensity transformation function T, made the pixels with dark intensities darker and the bright ones even more brighter, this is called contrast stretching

Page 21: DIP Lecture-3-6

22 Thresholding

Example: suppose m= 150 (called threshold),

if r (or pixel intensity in image f) is above this threshold it becomes 1 in s (or pixel intensity in image g), otherwise it becomes zero.

Pixels above 150 become 1

Pixels less than 150 become 0

If r >150; s =1If r <150; s =0

T=

This is called thresholding

Can you guess the output of thresholding? Binary Image

Page 22: DIP Lecture-3-6

23 Example: Thresholding

Page 23: DIP Lecture-3-6

24 Example: Thresholding

Page 24: DIP Lecture-3-6

25

2- Intensity-Level Slicing (gray level slicing)

Highlighting a specific range of intensities in an image. Approach 1 Approach 2

Display in one value(e.g white) all the values in the range of interest , and in another (e.g black) all other intensities

Brightens or darkens the desired range of intensities but leaves all other intensity levels in the image unchanged

Page 25: DIP Lecture-3-6

26 Example: Intensity level slicing

If the pixel intensity in the old image is between (100 150) convert it in the new image into 255 (white). Otherwise convert it to 0 (black).

Approach-1

Page 26: DIP Lecture-3-6

27 Example: Intensity level slicing

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.

Approach 1Approach-2

Page 27: DIP Lecture-3-6

28

3- Bit-Plane Slicing

Remember that pixels are digital numbers composed of bits.

8-bit Image composed of 8 1-bit planes

Page 28: DIP Lecture-3-6

29 Example: Bit-Plane Slicing100

0 1 1 0 0 1 0 0

0 0 4 0

0 32 64 0

Image of bit1: 00000000

Image of bit2: 00000000 Image of bit4:

00000000

Image of bit5: 00000000

Image of bit6: 00100000

Image of bit7: 01000000

Image of bit8: 00000000

Image of bit3: 00000100

Page 29: DIP Lecture-3-6

30 Example: Bit-Plane Slicing

Page 30: DIP Lecture-3-6

31

BRIGHTNESS AND CONTRAST

Page 31: DIP Lecture-3-6

32 Brightness

Brightness is a relative term. Brightness can be defined as intensity of light emit by a particular light source.

Just have a look at both of these images, and compare which one is brighter.

Page 32: DIP Lecture-3-6

33 How to make an image brighter?

Brightness can be simply increased or decreased by simple addition or subtraction, to the image matrix.

0 0 0 0 0

0 0 0 0 0

0 0 0 0 0

0 0 0 0 0

0 0 0 0 0

50 50 50 50 50

50 50 50 50 50

50 50 50 50 50

50 50 50 50 50

50 50 50 50 50

+100100 100 100 100 100

100 100 100 100 100

100 100 100 100 100

100 100 100 100 100

100 100 100 100 100

+50

+100150 150 150 150 150

150 150 150 150 150

150 150 150 150 150

150 150 150 150 150

150 150 150 150 150

+50

Page 33: DIP Lecture-3-6

34 Contrast

Contrast can be simply explained as the difference between maximum and minimum pixel intensity in an image.

100 100 100 100 100

100 100 100 100 100

100 100 100 100 100

100 100 100 100 100

100 100 100 100 100

The maximum value in this matrix is 100.The minimum value in this matrix is 100.Contrast = maximum pixel intensity(subtracted by) minimum pixel intensity= 100 (subtracted by) 100= 0

0 means that this image has 0 contrast.

Page 34: DIP Lecture-3-6

Digital Image Processing:Image Enhancement

Dr. Faraz AkramThe University of Faisalabad

Lecture-5

Page 35: DIP Lecture-3-6

36

HISTOGRAM PROCESSING

Page 36: DIP Lecture-3-6

37 Histogram

A histogram is a graph that shows frequency of anything. Usually histogram have bars that represent frequency of occurring of data in the whole data set.

Page 37: DIP Lecture-3-6

38 Example

Reg # Grade

001 A

002 D

003 B

004 A

005 C+

006 A-

007 B+

Result

Page 38: DIP Lecture-3-6

39

Histogram of an image, like other histograms also shows frequency. But an image histogram, shows frequency of pixels intensity values.

In an image histogram, the x axis shows the gray level intensities and the y axis shows the frequency of these intensities.

Histogram of an image

Page 39: DIP Lecture-3-6

40 Histogram of an image

Histogram of a digital image:

r = imread ('Test3.jpg'); figuresubplot(2,1,1)imshow(r); title('image');subplot(2,1,2)

[hist1, bins1] = hist(double(r(:)),256);bar(bins1,hist1);title('Histogram');

Page 40: DIP Lecture-3-6

41 Examples: Histogram

Page 41: DIP Lecture-3-6

42 Examples: Histogram

Page 42: DIP Lecture-3-6

43 Examples: Histogramimage

80 85 90 95 100 105 110 115 1200

1

2

3

4x 10

5 Histogram

Page 43: DIP Lecture-3-6

44 Histogram Processing

1-Histogram sliding:In histogram sliding , we just simply shift a complete histogram rightwards or leftwards. Due to shifting or sliding of histogram towards right or left, a clear change can be seen in the brightness.

In order to bright it, we will slide its histogram towards right, or towards whiter portion. In order to do we need to add a value (e.g. 50) to this image.

Page 44: DIP Lecture-3-6

45 Histogram sliding

Increasing brightness using histogram sliding

Page 45: DIP Lecture-3-6

46 Histogram sliding

Decreasing brightness using histogram sliding

Page 46: DIP Lecture-3-6

47 Histogram Equalization

Histogram equalization is a technique for adjusting image intensities to enhance contrast.

In histogram equalization the idea is to spread out the histogram so that it makes full use of the dynamic range of the image.

For example, if an image is very dark, most of the intensities might lie in the range 0-50. By choosing f to spread out the intensity values, we can make fuller use of the available intensities, and make darker parts of an image easier to understand.

Page 47: DIP Lecture-3-6

48 Histogram Equalization

Histogram Equalization:

Where,

g(x) : the new image after equalization

L: No of gray levels 2n

N: No of pixels

T(x): cumulative sum of each gray level

Page 48: DIP Lecture-3-6

49 Histogram Equalization

G(x) T(X)X

Gray level

L gray

levels

0 1 1 0

0 4 3 1

1 9 5 2

2 15 6 3

4 21 6 4

5 27 6 5

6 29 2 6

7 32 3 7

Assume that we have (3bits per pixels) or 8 levels of grayscale, and we want to equalize the following image example (total pixels 32).

G(x)=(L/n). T(X) -1

=(8/32). T(x) -1

Page 49: DIP Lecture-3-6

50 Example: Histogram Equalizaion

Page 50: DIP Lecture-3-6

51 Example

Page 51: DIP Lecture-3-6

Digital Image Processing:Image Enhancement

Dr. Faraz AkramThe University of Faisalabad

Lecture-6

Page 52: DIP Lecture-3-6

53

Histogram stretching:

Page 53: DIP Lecture-3-6

54 Example: Histogram Stretching

Now we calculate contrast from this image.

Contrast = 225.

Contrast = 240

Contrast = 225

Page 54: DIP Lecture-3-6

55 Failing of histogram stretching

• This technique fails on some cases. • when pixel intensity 0 and 255 are present in the

image• Because when pixel intensities 0 and 255 are

present in an image, then in that case they become the minimum and maximum pixel intensity which ruins the formula like this

Page 55: DIP Lecture-3-6

56

Enhancement Using Arithmetic/Logic Op.

Arithmetic/logic operations involving images are performed on a pixel-by-pixel basis between two or more images.

Arithmetic Operations

Addition, Subtraction, Multiplication, and Division

Logic Operations

AND, OR, NOT

Page 56: DIP Lecture-3-6

57 Addition

Used to create double-exposures or composites

g(x, y) = f1(x, y) + f2(x, y)

Can also do a weighted blend:

g(x, y) = α1f1(x, y) + α2f2(x, y)

Page 57: DIP Lecture-3-6

58 Subtraction

• Useful for finding changes between two images g(x, y) = f1(x, y) − f2(x, y)

• Sometimes more useful to use absolute difference

g(x, y) = |f1(x, y) − f2(x, y)|

• What’s changed?

Page 58: DIP Lecture-3-6

59 Example: Subtraction

Digital Subtraction Angiography:1. Take an x-ray

2. Inject patient with a radio-opaque dye (and tell them not to move!)

3. Take another x-ray

4. Subtract the two

Page 59: DIP Lecture-3-6

60 Example

Original4Upper-orderBit

ErrorHE ofError

Page 60: DIP Lecture-3-6

61 Image Averaging

Idea: Average multiple pictures of the same scene to reduce noise

Page 61: DIP Lecture-3-6

62

Bitwise AND & OR :

Page 62: DIP Lecture-3-6

63 OR

OR =

Page 63: DIP Lecture-3-6

64

Bitwise AND and OR :

Page 64: DIP Lecture-3-6

Digital Image Processing:Image Enhancement

Dr. Faraz AkramThe University of Faisalabad

Lecture-7