Download presentation
Presentation is loading. Please wait.
1
Image Histograms Cumulative histogram
Effect of gray-level mapping on histogram Histogram equalization Histogram specification Local enhancement Color processing
2
Intensity Histogram The histogram of a digital image with gray levels in the range [0,L-1] is a discrete function h(rk) = nk, where rk is the kth gray level and nk is the number of pixels in the image having gray level rk. 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 the distribution of pixels amongst those greyscale values.
3
Histogram Processing - How It Works
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 1. Assign zero values to all element of the array hf ; 2. For all pixels (x,y) of the image f , increment hf [f(x,y)] by 1 .
4
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]++;
5
Intensity Histogram - Guidelines for Use
Histograms 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 the histogram 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 a good segmentation can be produced by thresholding. The intensity histogram for the input image is
6
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.
7
Intensity Histogram - Guidelines for Use
The histogram is the the same but with the y-axis expanded to show more detail. It is clear that a threshold value of around 120 should segment the picture nicely as can be seen in
8
Intensity Histogram - Guidelines for Use
The 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
9
Intensity Histogram - Guidelines for Use
The histogram is used and altered by many image enhancement 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 the full intensity range to display the maximum contrast.
10
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.
11
Intensity Histogram and Contrast stretching
Contrast stretching the image yields which has a clearly improved contrast. The corresponding histogram is
12
Intensity Histogram and Contrast stretching
Multiplication of gray levels by a constant gain will spread out the histogram evenly if a>1, increasing the spacing between occupied bins,or compress it if a<1, which can have the effect of merging bins
13
Intensity Histogram and Contrast stretching
If we expand the y-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 pixel values, 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.
14
Intensity Histogram and Contrast stretching
The present image also has low contrast. However, if we look at its 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 the intensity values is used by only a few pixels.
15
Intensity Histogram and histogram equalization
The idea of histogram 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 flat histogram. The image results from the histogram equalization
16
Intensity Histogram - Conclusions
consider the image intensities as random variables with a probability density function (pdf). we can estimate the pdf from the empirical data given in the image itself . record the frequency distribution of gray levels in an image. for a b-bit image, you need an array of size 2b loop through every pixel, recording the number of times a particular gray level occurs.
17
Intensity Histogram - Conclusions
4. normalize the histogram by dividing each entry by the total number of pixels - gives an estimate for the pdf - each element of the array gives the probability of that gray level occurring at a randomly selected pixel . 5. contains global information about the image 6. discards all spatial information 7. an image has only one histogram, but many images may have the same histogram
18
Cumulative histogram - Conclusions
- each array element gives the number of pixels with a gray-level less than or equal to the gray level corresponding to the array element - easily constructed from the histogram Cumulative frequencies , cj, are computed from histogram counts, hi using,
19
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 the histogram
20
Effect of gray-level mapping on histogram - Conclusions
1. adding a bias shifts the histogram 2. gain > 1 stretches the histogram (increasing contrast) 3. gain < 1 compresses histogram (reducing contrast) 4. nonlinear mapping stretches some regions and compresses others
21
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-linear and 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.
22
Histogram Equalization
Histogram equalization involves finding a grey scale transformation function that creates an output image with a uniform histogram (or nearly so).
23
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 T that maps grey values r in the input image F to grey values s = T(r) in the transformed image . It is assumed that T is single valued and monotonically increasing, and for The inverse transformation from s to r is given by : r = T-1(s).
24
An example of such a transfer function is illustrated in the Figure
25
Histogram Equalization - Discrete Formulation
We 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, and N is the total number of pixels in the image. The transformation now becomes Note that ,the index k=0,1,2,…255, and The values of sk will 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 of sk to the nearest integer will mean that the transformed image will not have a perfectly uniform histogram.
26
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 Thus, an image which is transformed using its cumulative histogram yields an output histogram which is flat . See Algorithm 6.4 p 125 Efford’s book
27
The original image and its histogram, and the equalized versions
The original image and its histogram, and the equalized versions. Both images are quantized to 64 grey levels.
28
Histogram Equalization Guidelines for Use
The histogram confirms what we can see by visual inspection: this image has 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.)
29
Histogram Equalization Guidelines for Use
In order to improve the contrast of this image, without affecting the structure (i.e. geometry) of the information contained therein, we can apply the histogram equalization operator.
30
Histogram Equalization Guidelines for Use
Note 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 narrow histograms 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 linear contrast stretching operator After contrast stretching After equalization operator
31
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.
32
Histogram Equalization - Example
The histogram equalization operator defines a mapping based on the cumulative histogram
33
Histogram Equalization - Example
After histogram equalization While histogram equalization has enhanced the contrast of the sky regions in the image, the picture now looks artificial because there is very 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.
34
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.
35
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 and smoother, 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 perform Local Enhancements
36
Histogram Equalization - Conclusions
- use the cumulative histogram to generate a nonlinear gray-level mapping - cumulative histogram has a steep slope in densely populated parts of the histogram - cumulative histogram has a gradual slope in sparsely populated parts of the histogram - scale the entries based on bits per pixel and number of pixels - EqualizeOp.java - convenient because no user input is required - histogram equalization doesn't always get us the desired results - can enhance noise and other image artefacts
37
Histogram Specification
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 in order 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 distribution as an intermediate stage using a histogram equalized image The first step in histogram specialization, is to specify the desired output density function and write a transformation g(c). defines a mapping from the equalized levels of the original image, Then It is possible to combine these two transformations such that the image need not be histogram equalized explicitly:
38
Histogram Specification - Conclusions
1.We can specify the shape of the histogram we want our image to have 2. 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
39
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 in sufficient 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 small neighborhood around the pixel to be mapped - apply histogram equalization using this cumulative histogram
40
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 the intensity band
41
References http://www.netnam.vn/unescocourse/computervision/22.htm
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.