DIP Lecture-3-6
description
Transcript of DIP Lecture-3-6
Digital Image Processing:Image Enhancement
Dr. Faraz AkramThe University of Faisalabad
Lecture-3
2 Image enhancement
Image is NOT Perfect Sometimes
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
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.
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
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)
7 Basic grayscale transformations
2- log Transformations:
• Compress the dynamic range of the image.• e.g. to Visualize Fourier spectra
8 Basic grayscale transformations
3- Power-Law (gamma) Transformation:
• The exponent is called gamma (γ)• Gamma correction
• reduce contrast• enhance contrast
9 Example: contrast enhancement
=0.6
=0.4 =0.3
• reduce contrast
10 Example: contrast enhancement
enhance contrast
=3
=5=4
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.
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');
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');
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
Digital Image Processing:Image Enhancement
Dr. Faraz AkramThe University of Faisalabad
Lecture-4
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) ……….
18
Piecewise-linear transformations1. Contrast stretching and thresholding
2. Intensity-Level Slicing (gray level slicing)
3. Bit-Plane Slicing
19 Piecewise linear transformation
1- Contrast stretching and thresholding:
(r1, s1)
(r2, s2) (r2, s2)
(r1, s1)
Thresholding:Contrast stretching
(r1, s1)
(r2, s2)
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.
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
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
23 Example: Thresholding
24 Example: Thresholding
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
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
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
28
3- Bit-Plane Slicing
Remember that pixels are digital numbers composed of bits.
8-bit Image composed of 8 1-bit planes
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
30 Example: Bit-Plane Slicing
31
BRIGHTNESS AND CONTRAST
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.
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
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.
Digital Image Processing:Image Enhancement
Dr. Faraz AkramThe University of Faisalabad
Lecture-5
36
HISTOGRAM PROCESSING
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.
38 Example
Reg # Grade
001 A
002 D
003 B
004 A
005 C+
006 A-
007 B+
Result
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
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');
41 Examples: Histogram
42 Examples: Histogram
43 Examples: Histogramimage
80 85 90 95 100 105 110 115 1200
1
2
3
4x 10
5 Histogram
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.
45 Histogram sliding
Increasing brightness using histogram sliding
46 Histogram sliding
Decreasing brightness using histogram sliding
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.
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
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
50 Example: Histogram Equalizaion
51 Example
Digital Image Processing:Image Enhancement
Dr. Faraz AkramThe University of Faisalabad
Lecture-6
53
Histogram stretching:
54 Example: Histogram Stretching
Now we calculate contrast from this image.
Contrast = 225.
Contrast = 240
Contrast = 225
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
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
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)
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?
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
60 Example
Original4Upper-orderBit
ErrorHE ofError
61 Image Averaging
Idea: Average multiple pictures of the same scene to reduce noise
62
Bitwise AND & OR :
63 OR
OR =
64
Bitwise AND and OR :
Digital Image Processing:Image Enhancement
Dr. Faraz AkramThe University of Faisalabad
Lecture-7