Histogram
Histogram
Image Histogram
Li Yicheng
LIACS
[email protected]
Abstract
This one here introduces the image Histogram. Normally when we talk about image histogram we talk
about image enhancement. We normalize the histogram or we reulationize the histogram. Since it is not
hard to understand what an image histogram is , you can just refer to it as a statistic way to analyse an
image. I basicly focus more on how to constract a histogram in this part.
I.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
double a , b ;
if ( contrast > 0 )
{
double d e l t a = 1 2 7 . c o n t r a s t / 1 0 0 ;
a = 2 5 5 . / (2 5 5 . delta 2) ;
b = a ( brightness delta ) ;
}
else
{
double d e l t a = 128. c o n t r a s t / 1 0 0 ;
a = (256. d e l t a 2 ) / 2 5 5 . ;
b = a ( brightness + delta ) ;
}
Mat dst , h i s t ;
image . convertTo ( dst , CV_8U , a , b ) ;
imshow ( " image " , d s t ) ;
a and b. And they matters to the function image.convertTo and this would be discussed in
the later in API.
II.
I. imread
The function is used in each of the previous
project but I did not talk a lot about it.
1 Mat imread ( c o n s t S t r i n g& filename , i n t
f l a g s =IMREAD_COLOR )
II. convertTo
Image Histogram
In our program:
1 image . convertTo ( dst , CV_8U , a , b ) ;
1
2
3
r = a this( x, y) + b
= a this( x, y) + a (brightness delta)
= a (this( x, y) delta + brightness)
= a (this( x, y) delta)
Since the contrast is 100 then the delta is 127
and a is 255
According to the saturate_cast,
if this( x, y) > 127,
this( x, y) delta > 1,
r > 255,
I ( x, y) = 255,
else this( x, y) < 127,
this( x, y) delta < 0,
r < 0,
I ( x, y) = 0
And that is how the constrast is formed. if
delta = 0 then a = 1, and r can get all the
values from 0 to 255.
III.
calcHist
Parameters:
channels -> List of the dims channels
used to compute the histogram. The first
array channels are numerated from 0 to
images[0].channels()-1 , the second array channels are counted from images[0].channels() to
images[0].channels() + images[1].channels()-1,
and so on.
mask -> Optional mask. If the matrix is not
empty, it must be an 8-bit array of the same
size as images[i] . The non-zero mask elements
mark the array elements counted in the histogram.
hist -> Output histogram, which is a dense or
sparse dims -dimensional array.
dims -> Histogram dimensionality that
must be positive and not greater than
CV_MAX_DIMS (equal to 32 in the current
OpenCV version).
histSize -> Array of histogram sizes in each
dimension.
uniform -> Flag indicating whether the
histogram is uniform or not (see above).
accumulate -> Accumulation flag. If it is set,
the histogram is not cleared in the beginning
when it is allocated. This feature enables you
to compute a single histogram from several
sets of arrays, or to update the histogram in
time.
so the code
1 c a l c H i s t (& dst , 1 , 0 , Mat ( ) , h i s t , 1 , & h i s t S i z e
,0) ;
Image Histogram
V. rectangle
1 void r e c t a n g l e ( InputOutputArray img , P o i n t
pt1 , P o i n t pt2 , c o n s t S c a l a r& c o l o r ,
i n t t h i c k n e s s =1 , i n t l i n e T y p e=LINE_8 ,
i n t s h i f t =0 )
2 void r e c t a n g l e ( Mat& img , Rect rec , c o n s t
S c a l a r& c o l o r , i n t t h i c k n e s s =1 , i n t
l i n e T y p e=LINE_8 , i n t s h i f t =0 )
1 r e c t a n g l e ( histImage , P o i n t ( i binW ,
h i s t I m a g e . rows ) ,
2
P o i n t ( ( i +1) binW , h i s t I m a g e .
rows cvRound ( h i s t . at <
f l o a t >( i ) ) ) ,