intensity histogram
TRANSCRIPT
-
8/14/2019 Intensity Histogram
1/41
-
8/14/2019 Intensity Histogram
2/41
Intensity Histogram
This histogram is a graph showing the number of pixels in an image at
each different intensity value found in that image.
For an 8-bit greyscale image there are 256 different possible intensities,
and so the histogram will graphically display 256 numbers showing thedistribution of pixels amongst those greyscale values.
The histogram of a digital
image with gray levels in
the range [0,L-1] is a
discrete function h(rk) = n
k,
where rk
is the kth gray
level and nk
is the number
of pixels in the image
having gray level rk.
-
8/14/2019 Intensity Histogram
3/41
s ogram rocess ng - owWorks
The operation is very simple. The image is scanned in a single pass
and a running count of the number of pixels found at each intensity
value is kept. This is then used to construct a suitable histogram.
The histogram of an 8-bit image, for example can be thought of as a
table with 256 entries, or bins, indexed from 0 to 255. In bin 0 we
record the number of times a gray level of 0 occurs; in bin 1 we
record the number of times a grey level of 1 occurs, and so on, up to
bin 255. See algorithm 6.3
2. For all pixels (x,y) of the image f, increment hf[f(x,y)] by 1 .
1. Assign zero values to all element of the
array hf ;
-
8/14/2019 Intensity Histogram
4/41
Another way to get the histogram is to
use the C code, as following:
char image[rows][cols];
int histogram[256];
int row, col, i;
for (i = 0; i < 256; i++) histogram[j]=0;
for (row = 0; row < rows; row++)for(col = 0; col < cols; col++)
histogram[(int) image[row][col]++;
-
8/14/2019 Intensity Histogram
5/41
Intensity Histogram - Guidelines for UseHistograms have many uses. One of the more common is to decide what
value of threshold to use when converting a greyscale image to a binary
one by thresholding. If the image is suitable for thresholding then thehistogram will be bi-modal--- i.e. the pixel intensities will be clustered
around two well separated values. A suitable threshold for separating
these two groups will be found somewhere in between the two peaks in
the histogram. If the distribution is not like this then it is unlikely that agood segmentation can be produced by thresholding.
The intensity histogram for the input image is
http://www.dai.ed.ac.uk/HIPR2/images/wdg2.gif -
8/14/2019 Intensity Histogram
6/41
Intensity Histogram - Guidelines for Use
The object being viewed is dark in color and it is placed on a light
background, and so the histogram exhibits a good bi-modal
distribution. One peak represents the object pixels, one represents the
background.
http://www.dai.ed.ac.uk/HIPR2/images/wdg2.gif -
8/14/2019 Intensity Histogram
7/41
Intensity Histogram - Guidelines for Use
The histogram is the the same but with the y-axisexpanded to show more detail. It is clear that a threshold
value of around 120 should segment the picture nicely as
can be seen in
http://www.dai.ed.ac.uk/HIPR2/images/wdg2thr2.gif -
8/14/2019 Intensity Histogram
8/41
Intensity Histogram - Guidelines for UseThe histogram of image is
This time there is a significant incident illumination gradient across the
image, and this blurs out the histogram. The bi-modal distribution has
been destroyed and it is no longer possible to select a single global
threshold that will neatly segment the object from its background.Two failed
thresholding
segmentations are
shown in
http://www.dai.ed.ac.uk/HIPR2/images/wdg3thr2.gifhttp://www.dai.ed.ac.uk/HIPR2/images/wdg3thr1.gifhttp://www.dai.ed.ac.uk/HIPR2/images/wdg3.gif -
8/14/2019 Intensity Histogram
9/41
Intensity Histogram - Guidelines for Use
The histogram is used and altered by many imageenhancement operators. Two operators which are
closely connected to the histogram are contrast
stretching and histogram equalization They are
based on the assumption that an image has to use thefull intensity range to display the maximum contrast.
-
8/14/2019 Intensity Histogram
10/41
Intensity Histogram and Contrast stretching
Contrast stretching takes an image in which the
intensity values don't span the full intensity range and
stretches its values linearly.
The histogram shows that most of the pixels have rather high intensity
values.
-
8/14/2019 Intensity Histogram
11/41
Intensity Histogram and Contrast stretching
Contrast stretching the image yields
which has a clearly improved contrast.
The corresponding histogram is
-
8/14/2019 Intensity Histogram
12/41
Intensity Histogram and Contrast stretching
Multiplication of
gray levels by a
constant gain will
spread out the
histogram evenly if
a>1, increasing thespacing between
occupied bins,or
compress it if a
-
8/14/2019 Intensity Histogram
13/41
Intensity Histogram and Contrast stretchingIf we expand they-axis, as was done in
We can see that now the pixel values are distributed over the
entire intensity range. Due to the discrete character of the pixelvalues, we can't increase the number of distinct intensity
values.
That is the reason why the stretched histogram shows the gaps
between the single values.
-
8/14/2019 Intensity Histogram
14/41
Intensity Histogram and Contrast stretching
The present image also has low contrast. However, if we look atits histogram, we see that the entire intensity range is used and
we therefore cannot apply contrast stretching. On the other hand,
the histogram also shows that most of the pixels values are
clustered in a rather small area, whereas the top half of theintensity values is used by only a few pixels.
-
8/14/2019 Intensity Histogram
15/41
Intensity Histogram and histogram
equalizationThe idea ofhistogram equalization is that the pixels should
be distributed evenly over the whole intensity range, i.e. the
aim is to transform the image so that the output image has a
flathistogram. The image results from the histogramequalization
-
8/14/2019 Intensity Histogram
16/41
Intensity Histogram - Conclusions
1. consider the image intensities as randomvariables with a probability density function
(pdf).2. we can estimate the pdf from the empirical
data given in the image itself .
3. record the frequency distribution of gray
levels in an image.
o for a b-bit image, you need an array of size2b
o loop through every pixel, recording the
-
8/14/2019 Intensity Histogram
17/41
Intensity Histogram - Conclusions
4. normalize the histogram by dividing eachentry by the total number of pixels
- gives an estimate for the pdf
- each element of the array gives the probabilityof that gray level occurring at a randomlyselected pixel .
5. contains global information about the image
6. discards all spatial information
7. an image has only one histogram, but manyimages may have the same histogram
-
8/14/2019 Intensity Histogram
18/41
Cumulative histogram -Conclusions
Cumulative histogram
- each array element gives the number ofpixels with a gray-level less than or equal tothe gray level corresponding to the arrayelement
- easily constructed from the histogram
=
=j
i
ij hc0
Cumulative frequencies, cj, are computed from histogram
counts, hi using,
-
8/14/2019 Intensity Histogram
19/41
Cumulative histogram -Conclusions
- cumulative histogram has a steep slope
in densely populated parts of the
histogram
- cumulative histogram has a gradual
slope in sparsely populated parts of thehistogram
-
8/14/2019 Intensity Histogram
20/41
Effect of gray-level mapping onhistogram - Conclusions
1. adding a bias shifts the histogram
2. gain > 1 stretches the histogram (increasingcontrast)
3. gain < 1 compresses histogram (reducingcontrast)
4. nonlinear mapping stretches some regionsand compresses others
-
8/14/2019 Intensity Histogram
21/41
Histogram Equalization
Histogram modeling techniques (e.g. histogram equalization)provide a sophisticated method for modifying the dynamic range
and contrast of an image by altering that image such that its
intensity histogram has a desired shape. Unlike contrast
stretching , histogram modeling operators may employ non-linearand non-monotonic transfer functions to map between pixel
intensity values in the input and output images. Histogram
equalization employs a monotonic, non-linear mapping which
re-assigns the intensity values of pixels in the input image such
that the output image contains a uniform distribution of
intensities (i.e. a flat histogram). This technique is used in image
comparison processes (because it is effective in detail enhancement)
and in the correction of non-linear effects introduced by, say, a
digitizer or display system.
-
8/14/2019 Intensity Histogram
22/41
Histogram Equalization
Histogram equalization involves finding a grey scale
transformation function that creates an output image with a
uniform histogram (or nearly so).
-
8/14/2019 Intensity Histogram
23/41
How do we determine this grey scale transformation function?Assume our grey levels are continuous and have been normalized to
lie between 0 (black) and 1 (white).
We must find a transformation Tthat maps grey values rin the input ima
Fto grey valuess = T(r) in the transformed image .
It is assumed that
T is single valued and monotonically increasing, and
for
The inverse transformation froms to ris given by :
r= T-1(s).
-
8/14/2019 Intensity Histogram
24/41
An example of such a transfer function is
illustrated in the Figure
-
8/14/2019 Intensity Histogram
25/41
Histogram Equalization - Discrete FormulationWe first need to determine the probability distribution
of grey levels in the input image.
where nk
is the number of pixels having grey level k, andNis the
total number of pixels in the image.
The transformation now becomes
Note that
,the index k=0,1,2,255, andThe values ofs
kwill have to be scaled up by 255 and rounded to the
nearest integer so that the output values of this transformation will
range from 0 to 255. Thus the discretization and rounding ofsk
to the
nearest integer will mean that the transformed image will not have a
-
8/14/2019 Intensity Histogram
26/41
Histogram Equalization - Discrete Formulation
The mapping function we need is obtained simply by
rescaling the cumulative histogram so that its values
lie in the range 0-255.
Thus, an image which is transformed using its
cumulative histogram yields an output histogram
which is flat .
See Algorithm 6.4 p 125 Effords book
-
8/14/2019 Intensity Histogram
27/41
The original image and its histogram, and the equalized versions. Both
images are quantized to 64 grey levels.
-
8/14/2019 Intensity Histogram
28/41
Histogram EqualizationGuidelines for Use
The histogram confirms what we can see by visual inspection: this imagehas poor dynamic range. (Note that we can view this histogram as a
description of pixel probability densities by simply scaling the vertical
axis by the total number of image pixels and normalizing the horizontal
axis using the number of intensity density levels (i.e. 256). However, the
shape of the distribution will be the same in either case.)
-
8/14/2019 Intensity Histogram
29/41
Histogram EqualizationGuidelines for UseIn order to improve the contrast of this image, without affecting the
structure (i.e. geometry) of the information contained therein, wecan apply the histogram equalization operator.
-
8/14/2019 Intensity Histogram
30/41
Histogram EqualizationGuidelines for UseNote that the histogram is not flat (as in the examples from the
continuous case) but that the dynamic range and contrast have been
enhanced. Note also that when equalizing images with narrowhistograms and relatively few gray levels, increasing the dynamic range
has the adverse effect of increasing visual grainyness. Compare this
result with that produced by the linearcontrast stretching operator
Aftercontrast stretchingAfterequalization operator
-
8/14/2019 Intensity Histogram
31/41
Histogram Equalization - Example
Although the contrast on the building is acceptable, the sky region is
represented almost entirely by light pixels. This causes most
histogram pixels to be pushed into a narrow peak in the upper
graylevel region.
-
8/14/2019 Intensity Histogram
32/41
Histogram Equalization - ExampleThe histogram equalization
operator defines a mapping
based on the cumulativehistogram
http://www.dai.ed.ac.uk/HIPR2/images/bld1heq1.gif -
8/14/2019 Intensity Histogram
33/41
Histogram Equalization - Example
While histogram equalization has enhanced the contrast of the sky
regions in the image, the picture now looks artificial because there isvery little variety in the middle graylevel range. This occurs because
the transfer function is based on the shallow slope of the cumulative
histogram in the middle graylevel regions (i.e. intensity density levels
100 - 230) and causes many pixels from this region in the original
image to be mapped to similar graylevels in the output image.
After
histogram
equalization
http://www.dai.ed.ac.uk/HIPR2/images/bld1heq1.gif -
8/14/2019 Intensity Histogram
34/41
Histogram Equalization - Example
We can improve on this if we define a mapping
based on a sub-section of the image which
contains a better distribution of intensity
densities from the low and middle range
graylevels. If we crop the image so as to isolate
a region which contains more building than
sky.
We can then define a histogram equalization
mapping for the whole image based on the
cumulative histogram of this smaller region.
Rather than saying that equalisation
flattens a histogram, it is more
accurate to say that it linearises the
cumulative frequency distribution.
-
8/14/2019 Intensity Histogram
35/41
Histogram Equalization - Example
Since the cropped image contains a more even distribution of dark
and light pixels, the slope of the transfer function is steeper andsmoother, and the contrast of the resulting image is more natural. This
idea of defining mappings based upon particular sub-sections of the
image is taken up by another class of operators which performLocal
Enhancements
http://www.dai.ed.ac.uk/HIPR2/images/bld1heq1.gif -
8/14/2019 Intensity Histogram
36/41
Histogram Equalization - Conclusions
- use the cumulative histogram to generate a nonlinear
gray-level mapping- cumulative histogram has a steep slope in denselypopulated parts of the histogram
- cumulative histogram has a gradual slope in sparselypopulated parts of the histogram
- scale the entries based on bits per pixel and number ofpixels
- EqualizeOp.java
- convenient because no user input is required
- histogram equalization doesn't always get us the desired
results
-
8/14/2019 Intensity Histogram
37/41
Histogram equalization is limited in that it is capable of producing only
one result: an image with a uniform intensity distribution. Sometimes it
is desirable to be able to control the shape of the output histogram inorder to highlight certain intensity levels in an image.This can be accomplished by the histogram specialization operator
which maps a given intensity distribution
into a desired distributionusing a histogram equalized image
The first step in histogram specialization, is to specify the desired
output density function and write a transformationg(c).
as an intermediate
stage
It is possible to combine these two transformations such that
the image need not be histogram equalized explicitly:
Then defines a mapping from the equalized
levels of the original image,
Histogram Specification
-
8/14/2019 Intensity Histogram
38/41
Histogram Specification - Conclusions
1.We can specify the shape of the histogram we want our
image to have2. Specify (perhaps interactively) the histogram we
would like
3. compute the cumulative histogram from the desired
histogram
4. find the inverse of the desired cumulative histogram
(may not be single-valued)
5. two-step process
- perform histogram equalization on the image
- perform a gray-level mapping using the inverse of the
desired cumulative histogram
-
8/14/2019 Intensity Histogram
39/41
Local enhancement
1. histogram equalization and histogram specification
techniques are based on gray-level distribution over the
entire image
2. gray-levels containing important information in a small
neighborhood (region of interest) may not be present insufficient quantities to affect the computation of a
mapping based on global information
3. at each pixel do the following
- compute the cumulative histogram based on a smallneighborhood around the pixel to be mapped
- apply histogram equalization using this cumulative
histogram
-
8/14/2019 Intensity Histogram
40/41
Color processing
1.can apply histogram equalization to color images
2. don't want to apply it using the RGB color model
- equalizing R, G, and B bands independently
causes color shifts
3. must convert to a color model that separates
intensity information from color information (e.g.
HSI)
4. can then apply histogram equalization on theintensity band
-
8/14/2019 Intensity Histogram
41/41
References
http://www.netnam.vn/unescocourse/computervision/22.htm
http://homepages.inf.ed.ac.uk/rbf/HIPR2/histeq.htm
http://www.netnam.vn/unescocourse/computervision/22.htmhttp://www.netnam.vn/unescocourse/computervision/22.htm