brighten darken - tau
TRANSCRIPT
31
61
Dr. Yoram Tal � � � � � � � � � � � � � �� � � � � � � � � � � � � !
"minmax
min255
−
−⋅=II
IIIout
brighten darken
62
Dr. Yoram Tal# $ % & ' ( ) * + , - . * / $ 0 * & $ ' 1 2 3 4Adam
17
33
Dr. Yoram Tal
Histograms
A histogram of a discrete (integer) data set is a frequency table which counts the number of appearances of each member
First introduced by Abu Yusuf Yaqub ibnIshaq al-Sabbah Al-Kindi as a tool for deciphering the substitution code – a breakthrough at that time, 850 AD. (see: simon singh “the code book” 1999)
Who invented it and why?
34
Dr. Yoram Tal
Which Histogram ?
0 5 0 1 0 0 1 5 0 2 0 0 2 5 0
0 50 100 150 200 250
0
0
0
0
0
0
0 5 0 1 0 0 1 5 0 2 0 0 2 5 0
Red Histogram: imhist(im(:,:,1))
Green Histogram: imhist(im(:,:,2))
Blue Histogram: imhist(im(:,:,3))
0 50 100 150 200 250
Gray Histogram: (rgb2gray)
24
47
Dr. Yoram Tal � � � � � � � �Given an array of numbers: �� �� ��� ��������� �������� !� �""��# $#�"�����
A = { }Find the frequency of each number:
%&'()*+,-. /01223/202Number:
Count:
48
Dr. Yoram Tal4 5 6 7 8 9 : ; < = > 8 : < ; ? @x image matr ix (intensity)
imhist (x) display histogram[count, bin] = imhist (x) ;
Gray level
Count# pixels
25
49
Dr. Yoram Tal A B C D E F G H I C J K L M N O PThe histogram of an image contains valuable informationconcerning the distr ibution of gray levels
I t does not contain any spatial information
All the following images have exactly the same histograms!
50
Dr. Yoram Tal
Q R S T U V W X Y S X S Z U T R [ VA histogram is a result of voting it counts the number of supporters (i.,e., pixels) of each candidate (graylevel)
In the simple case of a binary image there are only two candidates: Mr zero and Ms one.
Voting has many useful applications in image processing (as well as in democracy).
26
51
Dr. Yoram Tal
\ ] ^ _ ` _ a b c ^ a d ` e b f ] ^ g h b i j k l m
Too dark
Too bright
52
Dr. Yoram Tal
n o p q r q s t u p s v r w t x o p y z t { | } ~ �
Low contrast
High contrast
27
53
Dr. Yoram Tal� � � � � � � � � � � � � � � � � � �I
I = imread('pout.tif');a = min(I(:));b = max(I(:));J = 255*(I-a)/(b-a);J = uint8(J);
a = 74 b = 224
Histogram of I
255minmax
min ⋅−
−=II
IIJ
54
Dr. Yoram Tal
� � � � � � � � � � � � � � � � � � � � � � � � � �J Histogram of J
Histogram of I
28
55
Dr. Yoram Tal� � � � � � � � � � � � � � � � � � � ¡¢ £ ¤ ¥ £ ¤ ¦ ¦ § ¨ § © ª« ¬ ® ¯ ° ± ² ³ ± °´ µ ¶ ® ¯ ±· ° ¸ ¬ ¹ ± ¬ º ¶ ° ® ¯
The minimum is 0 and the maximum is 255
56
Dr. Yoram Tal» ¼ ½ ¾ ¿ À Á Â Ã Â Ä Å Æ ½ ¾ Ã Ç È ¾
a = 74
Histogram of I
255 if I i >= b
255*(I-a)/(b-a) if a <= I i < b
0 if I i < a
b = 170
K =
K = imadjust(I,[0.3 0.67],[]);
This is a non-linearoperation
29
57
Dr. Yoram TalÉ Ê Ë Ì Í Î Ï Ð Ñ Ð Ò Ó Ô Ë Ì Ñ Õ Ö Ì × Ø Ù Ú Û Ü ÝI J K
58
Dr. Yoram TalÞ ß à á â ã ä å æ ç è é å ê ß ë å á ß â ìy = histeq(x,256);
30
59
Dr. Yoram Tal í î ï ð ñ ò ó î ô õ ð ö ÷ ø ù ðOriginal Histogram
Equalized Histogram
n = prod(size(x))tf = cumsum(255*h/n )
h
tf
60
Dr. Yoram Talú û û ü ý þ ÿ � � � � � ú ý ÿ �
X (in [0 255])
Linear approx. of tf
L(1:150) = 0;L(151:240) = linspace (0,255 , 90) ;L(241:255) = 255;
y = L(x+1);
y
tf
L
32
63
Dr. Yoram Tal5 6 7 8 9 : ; < = > ? @ < A 6 B < 8 6 9 C D E FPout
64
Dr. Yoram Tal
G H I J K L M N O P Q R N S H T N J H K U V W XY Z [ Z \ ] ^Y Z [ Z \ ] ^ _ _ ^ _ ` [ a Z ` \ b c d^ _ ` [ a Z ` \ b c d e e b f Z g \ Z e ^ d ^ h _ h ib f Z g \ Z e ^ d ^ h _ h i b b d e b _ _ Z \d e b _ _ Z \
paper Histogram of paper
18
35
Dr. Yoram Tal
Histogram Manipulation
• Correct illumination problems • Correct contrast problems
• Use histogram information to create a Look-Up Table (LUT)
• Apply LUT to the image
Image
Histogram LUT
New_imge = LUT(image)
Why?
How?
36
Dr. Yoram Tal
Gamma Correction(point operation)
γ
minmax
min255 ⎟⎟⎠
⎞⎜⎜⎝
⎛−−
⋅=II
IIIout
brighten darken
Input graylevelOut
put
gray
leve
l
[H, b] = imhist(I);p = H/sum(H); (p is in [0,1])LUT = p.^gamma
Iout = LUT(I+1); (if Imin is 0)(gamma + stretching)
19
37
Dr. Yoram Tal
Option Ioperate on each channel separately
R = brighten(I(:,:,1),0.4);G = brighten(I(:,:,2),0.4);B = brighten(I(:,:,3),0.4);
RGB = cat(3,R,G,B);
Warning: distortion of colors!
38
Dr. Yoram Tal
Option IIoperate on the intensity channel
RGB Image HSV Image V = HSV(:,:,3);
Correct V => Vc
rgb2hsv
HSV(:,:,3) = Vc;RGB Imagehsv2rgb
brighten
20
39
Dr. Yoram Tal
Histogram Equalization
Assumption: A “good” image has a “flat” histogram, i.e., all graylevels have the same probability.
How ?See histeq
40
Dr. Yoram Tal
Histogram Equalization - Lemma
• Let I be an image having N pixels and and G+1 graylevels such that g is a graylevel of I iff
g ε {0, 1, 2, …, G}
• Let h be the histogram of I where h(g) is the number of pixels in I having graylevel g.
• Let H be the cumulative histogram of I:
• Then L(x) = (G/N) H(x) is a lookup table which transforms I into a histogram equalized image.
( )0
H ( )g x
gx h g
=
=
= ∑
21
41
Dr. Yoram Tal
Histogram Equalization - how
[H, b] = imhist(I);p = cumsum(H); p = p/p(end);LUT = p*255;
LUT
graylevel
1 Make LUT 2 Apply LUT
Iout = LUT(I+1); (if I is uint8)
In this case, a similar effect could be obtained with imadjust(use stretchlim to find thresholds)
The same result can be achieved with histeq
42
Dr. Yoram Tal
Histogram Equalization problem: a narrow histogram
22
43
Dr. Yoram Tal
Histogram Equalizationresult: too mach contrast
LUT
Resulting histogram
44
Dr. Yoram Tal
CLHEContrast Limited Histogram Equalization
Source histogram Cut at some threshold(the histogram is very high & therefore the LUT is steep)
Redistribute the “left over”Now integrate
Original LUT“softer” LUT
23
45
Dr. Yoram Tal
CLHE - Result
Source HE
CLHE
46
Dr. Yoram Tal
CLAHE Contrast Limited Adaptive Histogram equalization
Problem: a big illumination difference between the two sides of the image (High Dynamic Range).
24
47
Dr. Yoram Tal
Try Histogram Equalization
It certainly helps, but does not solve the main problem.
48
Dr. Yoram Tal
Adaptive Histogram Equalizationrgb => hsv;v1 = adapthisteq(v,{parameters});hsv1 => rgb1
• The image is partitioned into blocks.
• Each block is enhanced with CLHE.
• The results are stitched back smoothly.
“Parameters” are very important!
25
49
Dr. Yoram Tal
CLAHE – another exampleSource image Histogram Eq. adapthisteq
50
Dr. Yoram Tal