Color histogram

Last updated

In image processing and photography, a color histogram is a representation of the distribution of colors in an image. For digital images, a color histogram represents the number of pixels that have colors in each of a fixed list of color ranges, that span the image's color space, the set of all possible colors.

Contents

The color histogram can be built for any kind of color space, although the term is more often used for three-dimensional spaces such as RGB or HSV. For monochromatic images, the term intensity histogram may be used instead. For multi-spectral images, where each pixel is represented by an arbitrary number of measurements (for example, beyond the three measurements in RGB), the color histogram is N-dimensional, with N being the number of measurements taken. Each measurement has its own wavelength range of the light spectrum, some of which may be outside the visible spectrum.

If the set of possible color values is sufficiently small, each of those colors may be placed on a range by itself; then the histogram is merely the count of pixels that have each possible color. Most often, the space is divided into an appropriate number of ranges, often arranged as a regular grid, each containing many similar color values. The color histogram may also be represented and displayed as a smooth function defined over the color space that approximates the pixel counts.

Like other kinds of histograms, the color histogram is a statistic that can be viewed as an approximation of an underlying continuous distribution of color values.

Overview

Color histograms are flexible constructs that can be built from images in various color spaces, whether RGB, rg chromaticity or any other color space of any dimension. A histogram of an image is produced first by discretization of the colors in the image into a number of bins, and counting the number of image pixels in each bin. For example, a Red–Blue chromaticity histogram can be formed by first normalizing color pixel values by dividing RGB values by R+G+B, then quantizing the normalized R and B coordinates into N bins each. A two-dimensional histogram of Red-Blue chromaticity divided into four bins (N=4) might yield a histogram that looks like this table:

 red
0-6364-127128-191192-255
blue0-634378180
64-1274567332
128-19112758258
192-255140474713

A histogram can be N-dimensional. Although harder to display, a three-dimensional color histogram for the above example could be thought of as four separate Red-Blue histograms, where each of the four histograms contains the Red-Blue values for a bin of green (0-63, 64-127, 128-191, and 192-255).

The histogram provides a compact summarization of the distribution of data in an image. The color histogram of an image is relatively invariant with translation and rotation about the viewing axis, and varies only slowly with the angle of view. [1] By comparing histogram signatures of two images and matching the color content of one image with the other, the color histogram is particularly well suited for the problem of recognizing an object of unknown position and rotation within a scene. Importantly, translation of an RGB image into the illumination invariant rg-chromaticity space allows the histogram to operate well in varying light levels.

1. What is a histogram?

A histogram is a graphical representation of the number of pixels in an image. In a more simple way to explain, a histogram is a bar graph, whose X-axis represents the tonal scale(black at the left and white at the right), and Y-axis represents the number of pixels in an image in a certain area of the tonal scale. For example, the graph of a luminance histogram shows the number of pixels for each brightness level(from black to white), and when there are more pixels, the peak at the certain luminance level is higher.

2. What is a color histogram?

A color histogram of an image represents the distribution of the composition of colors in the image. It shows different types of colors appeared and the number of pixels in each type of the colors appeared. The relation between a color histogram and a luminance histogram is that a color histogram can be also expressed as “Three Luminance Histograms”, each of which shows the brightness distribution of each individual Red/Green/Blue color channel.

Characteristics of a color histogram

A color histogram focuses only on the proportion of the number of different types of colors, regardless of the spatial location of the colors. The values of a color histogram are from statistics. They show the statistical distribution of colors and the essential tone of an image.

In general, as the color distributions of the foreground and background in an image are different, there might be a bimodal distribution in the histogram.

For the luminance histogram alone, there is no perfect histogram and in general, the histogram can tell whether it is over-exposure or not, but there are times when you might think the image is over exposed by viewing the histogram; however, in reality it is not.

Principles of the formation of a color histogram

The formation of a color histogram is rather simple. From the definition above, we can simply count the number of pixels for each 256 scales in each of the 3 RGB channel, and plot them on 3 individual bar graphs.

In general, a color histogram is based on a certain color space, such as RGB or HSV. When we compute the pixels of different colors in an image, if the color space is large, then we can first divide the color space into certain numbers of small intervals. Each of the intervals is called a bin. This process is called color quantization. Then, by counting the number of pixels in each of the bins, we get the color histogram of the image.

The concrete steps of the principles can be viewed in Example 1.

Examples

Example 1

Given the following image of a cat (an original version and a version that has been reduced to 256 colors for easy histogram purposes), the following data represents a color histogram in the RGB color space, using four bins.

Bin 0 corresponds to intensities 0-63

Bin 1 is 64-127

Bin 2 is 128-191 and Bin 3 is 192-255.

A picture of a cat Odd-eyed cat by ihasb33r.jpg
A picture of a cat
Color histogram of the above cat picture with x-axis being RGB and y-axis being the frequency. Odd-eyed cat histogram.png
Color histogram of the above cat picture with x-axis being RGB and y-axis being the frequency.
A picture of a cat reduced to 256 colors in the RGB color space Odd-eyed cat by ihasb33r-2.gif
A picture of a cat reduced to 256 colors in the RGB color space
RedGreenBluePixel Count
Bin 0Bin 0Bin 07414
Bin 0Bin 0Bin 1230
Bin 0Bin 0Bin 20
Bin 0Bin 0Bin 30
Bin 0Bin 1Bin 08
Bin 0Bin 1Bin 1372
Bin 0Bin 1Bin 288
Bin 0Bin 1Bin 30
Bin 0Bin 2Bin 00
Bin 0Bin 2Bin 10
Bin 0Bin 2Bin 210
Bin 0Bin 2Bin 31
Bin 0Bin 3Bin 00
Bin 0Bin 3Bin 10
Bin 0Bin 3Bin 20
Bin 0Bin 3Bin 30
Bin 1Bin 0Bin 0891
Bin 1Bin 0Bin 113
Bin 1Bin 0Bin 20
Bin 1Bin 0Bin 30
Bin 1Bin 1Bin 0592
Bin 1Bin 1Bin 13462
Bin 1Bin 1Bin 2355
Bin 1Bin 1Bin 30
Bin 1Bin 2Bin 00
Bin 1Bin 2Bin 1101
Bin 1Bin 2Bin 2882
Bin 1Bin 2Bin 316
Bin 1Bin 3Bin 00
Bin 1Bin 3Bin 10
Bin 1Bin 3Bin 20
Bin 1Bin 3Bin 30
Bin 2Bin 0Bin 01146
Bin 2Bin 0Bin 10
Bin 2Bin 0Bin 20
Bin 2Bin 0Bin 30
Bin 2Bin 1Bin 02552
Bin 2Bin 1Bin 19040
Bin 2Bin 1Bin 247
Bin 2Bin 1Bin 30
Bin 2Bin 2Bin 00
Bin 2Bin 2Bin 18808
Bin 2Bin 2Bin 253110
Bin 2Bin 2Bin 311053
Bin 2Bin 3Bin 00
Bin 2Bin 3Bin 10
Bin 2Bin 3Bin 2170
Bin 2Bin 3Bin 317533
Bin 3Bin 0Bin 011
Bin 3Bin 0Bin 10
Bin 3Bin 0Bin 20
Bin 3Bin 0Bin 30
Bin 3Bin 1Bin 0856
Bin 3Bin 1Bin 11376
Bin 3Bin 1Bin 20
Bin 3Bin 1Bin 30
Bin 3Bin 2Bin 00
Bin 3Bin 2Bin 13650
Bin 3Bin 2Bin 26260
Bin 3Bin 2Bin 3109
Bin 3Bin 3Bin 00
Bin 3Bin 3Bin 10
Bin 3Bin 3Bin 23415
Bin 3Bin 3Bin 353929

Example 2

Symcamera1.jpg
Symcamera2.jpg
Symcamera3.jpg

Application in camera:

Nowadays, some cameras have the ability to show the 3 color histograms when we take photos.

We can examine clips (spikes on either the black or white side of the scale) in each of the 3 RGB color histograms. If we find one or more clipping on a channel of the 3 RGB channels, then this would result in a loss of detail for that color.

To illustrate this, consider this example:

1. We know that each of the three R, G, B channels has a range of values from 0-255 (8 bit). So consider a photo that has a luminance range of 0-255.

2. Assume the photo we take is made of 4 blocks that are adjacent to each other and we set the luminance scale for each of the 4 blocks of original photo to be 10, 100, 205, 245. Thus, the image looks like the topmost figure on the right.

3. Then, we overexpose the photo a little, say, the luminance scale of each block is increased by 10. Thus, the luminance scale for each of the 4 blocks of new photo is 20, 110, 215, 255. Then, the image looks like the second figure on the right.

There is not much difference between both figures, all we can see is that the whole image becomes brighter (the contrast for each of the blocks remain the same).

4. Now, we overexpose the original photo again, this time the luminance scale of each block is increased by 50. Thus, the luminance scale for each of the 4 blocks of the new photo is 60, 150, 255, 255. The new image now looks like the third figure on the right.

Note that the scale for the last block is 255 instead of 295, for 255 is the top scale and thus the last block has clipped! When this happens, we lose the contrast of the last 2 blocks, and thus, we cannot recover the image no matter how we adjust it.

To conclude, when taking photos with a camera that displays histograms, always keep the brightest tone in the image below the largest scale 255 on the histogram in order to avoid losing details.

Drawbacks and other approaches

The main drawback of histograms for classification is that the representation is dependent on the color of the object being studied, ignoring its shape and texture. Color histograms can potentially be identical for two images with different object content which happens to share color information. Conversely, without spatial or shape information, similar objects of different color may be indistinguishable based solely on color histogram comparisons. There is no way to distinguish a red and white cup from a red and white plate. Put it another way: histogram-based algorithms have no concept of a generic 'cup', and a model of a red and white cup is no use when given an otherwise identical blue and white cup. Another problem is that color histograms have high sensitivity to noisy interference such as lighting intensity changes and quantization errors. High dimensionality (bins) color histograms are also another issue. Some color histogram feature spaces often occupy more than one hundred dimensions. [2]

Some of the proposed solutions have been color histogram intersection, color constant indexing, cumulative color histogram, quadratic distance, and color correlograms. Although there are drawbacks of using histograms for indexing and classification, using color in a real-time system has several advantages. One is that color information is faster to compute compared to other invariants. It has been shown in some cases that color can be an efficient method for identifying objects of known location and appearance.

Further research into the relationship between color histogram data to the physical properties of the objects in an image has shown they can represent not only object color and illumination but relate to surface roughness and image geometry and provide an improved estimate of illumination and object color. [3]

Usually, Euclidean distance, histogram intersection, or cosine or quadratic distances are used for the calculation of image similarity ratings. [4] Any of these values do not reflect the similarity rate of two images in itself; it is useful only when used in comparison to other similar values. This is the reason that all the practical implementations of content-based image retrieval must complete computation of all images from the database, and is the main disadvantage of these implementations.

Another approach to representative color image content is two-dimensional color histogram. A two-dimensional color histogram considers the relation between the pixel pair colors (not only the lighting component). [5] A two-dimensional color histogram is a two-dimensional array. The size of each dimension is the number of colors that were used in the phase of color quantization. These arrays are treated as matrices, each element of which stores a normalized count of pixel pairs, with each color corresponding to the index of an element in each pixel neighborhood. For comparison of two-dimensional color histograms it is suggested calculating their correlation, because constructed as described above, is a random vector (in other words, a multi-dimensional random value). While creating a set of final images, the images should be arranged in decreasing order of the correlation coefficient.

The correlation coefficient may also be used for color histogram comparison. Retrieval results with correlation coefficient are better than with other metrics. [6]

Intensity histogram of continuous data

The idea of an intensity histogram can be generalized to continuous data, say audio signals represented by real functions or images represented by functions with two-dimensional domain.

Let (see Lebesgue space), then the cumulative histogram operator can be defined by:

.

is the Lebesgue measure of sets. in turn is a real function. The (non-cumulative) histogram is defined as its derivative.

.

Related Research Articles

<span class="mw-page-title-main">JPEG</span> Lossy compression method for reducing the size of digital images

JPEG is a commonly used method of lossy compression for digital images, particularly for those images produced by digital photography. The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image quality. JPEG typically achieves 10:1 compression with little perceptible loss in image quality. Since its introduction in 1992, JPEG has been the most widely used image compression standard in the world, and the most widely used digital image format, with several billion JPEG images produced every day as of 2015.

<span class="mw-page-title-main">RGB color model</span> Color model based on red, green and blue

The RGB color model is an additive color model in which the red, green and blue primary colors of light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue.

Digital image processing is the use of a digital computer to process digital images through an algorithm. As a subcategory or field of digital signal processing, digital image processing has many advantages over analog image processing. It allows a much wider range of algorithms to be applied to the input data and can avoid problems such as the build-up of noise and distortion during processing. Since images are defined over two dimensions digital image processing may be modeled in the form of multidimensional systems. The generation and development of digital image processing are mainly affected by three factors: first, the development of computers; second, the development of mathematics ; third, the demand for a wide range of applications in environment, agriculture, military, industry and medical science has increased.

<span class="mw-page-title-main">HSL and HSV</span> Alternative representations of the RGB color model

HSL and HSV are alternative representations of the RGB color model, designed in the 1970s by computer graphics researchers. In these models, colors of each hue are arranged in a radial slice, around a central axis of neutral colors which ranges from black at the bottom to white at the top.

In digital photography, computer-generated imagery, and colorimetry, a grayscale image is one in which the value of each pixel is a single sample representing only an amount of light; that is, it carries only intensity information. Grayscale images, a kind of black-and-white or gray monochrome, are composed exclusively of shades of gray. The contrast ranges from black at the weakest intensity to white at the strongest.

The RGB chromaticity space, two dimensions of the normalized RGB space, is a chromaticity space, a two-dimensional color space in which there is no intensity information.

<span class="mw-page-title-main">Image segmentation</span> Partitioning a digital image into segments

In digital image processing and computer vision, image segmentation is the process of partitioning a digital image into multiple image segments, also known as image regions or image objects. The goal of segmentation is to simplify and/or change the representation of an image into something that is more meaningful and easier to analyze. Image segmentation is typically used to locate objects and boundaries in images. More precisely, image segmentation is the process of assigning a label to every pixel in an image such that pixels with the same label share certain characteristics.

<span class="mw-page-title-main">YCbCr</span> Family of digital colour spaces

YCbCr, Y′CbCr, or Y Pb/Cb Pr/Cr, also written as YCBCR or Y′CBCR, is a family of color spaces used as a part of the color image pipeline in video and digital photography systems. Y′ is the luma component and CB and CR are the blue-difference and red-difference chroma components. Y′ is distinguished from Y, which is luminance, meaning that light intensity is nonlinearly encoded based on gamma corrected RGB primaries.

<span class="mw-page-title-main">Octree</span> Tree data structure in which each internal node has exactly eight children, to partition a 3D space

An octree is a tree data structure in which each internal node has exactly eight children. Octrees are most often used to partition a three-dimensional space by recursively subdividing it into eight octants. Octrees are the three-dimensional analog of quadtrees. The word is derived from oct + tree. Octrees are often used in 3D graphics and 3D game engines.

The scale-invariant feature transform (SIFT) is a computer vision algorithm to detect, describe, and match local features in images, invented by David Lowe in 1999. Applications include object recognition, robotic mapping and navigation, image stitching, 3D modeling, gesture recognition, video tracking, individual identification of wildlife and match moving.

<span class="mw-page-title-main">Color balance</span> Adjustment of color intensities in photography

In photography and image processing, color balance is the global adjustment of the intensities of the colors. An important goal of this adjustment is to render specific colors – particularly neutral colors like white or grey – correctly. Hence, the general method is sometimes called gray balance, neutral balance, or white balance. Color balance changes the overall mixture of colors in an image and is used for color correction. Generalized versions of color balance are used to correct colors other than neutrals or to deliberately change them for effect. White balance is one of the most common kinds of balancing, and is when colors are adjusted to make a white object appear white and not a shade of any other colour.

The following are common definitions related to the machine vision field.

<span class="mw-page-title-main">Histogram equalization</span> Method in image processing of contrast adjustment using the images histogram

Histogram equalization is a method in image processing of contrast adjustment using the image's histogram.

<span class="mw-page-title-main">Color quantization</span>

In computer graphics, color quantization or color image quantization is quantization applied to color spaces; it is a process that reduces the number of distinct colors used in an image, usually with the intention that the new image should be as visually similar as possible to the original image. Computer algorithms to perform color quantization on bitmaps have been studied since the 1970s. Color quantization is critical for displaying images with many colors on devices that can only display a limited number of colors, usually due to memory limitations, and enables efficient compression of certain types of images.

In computer science, the earth mover's distance (EMD) is a distance-like measure of dissimilarity between two frequency distributions, densities, or measures over a region D. For probability distributions and normalized histograms, it reduces to the Wasserstein metric . Informally, if the distributions are interpreted as two different ways of piling up earth (dirt) over the region D, the EMD captures the minimum cost of building the smaller pile using dirt taken from the larger, where cost is defined as the amount of dirt moved multiplied by the ground distance over which it is moved.

The histogram of oriented gradients (HOG) is a feature descriptor used in computer vision and image processing for the purpose of object detection. The technique counts occurrences of gradient orientation in localized portions of an image. This method is similar to that of edge orientation histograms, scale-invariant feature transform descriptors, and shape contexts, but differs in that it is computed on a dense grid of uniformly spaced cells and uses overlapping local contrast normalization for improved accuracy.

<span class="mw-page-title-main">Ordered dithering</span> Image dithering algorithm

Ordered dithering is an image dithering algorithm. It is commonly used to display a continuous image on a display of smaller color depth. For example, Microsoft Windows uses it in 16-color graphics modes. The algorithm is characterized by noticeable crosshatch patterns in the result.

Local binary patterns (LBP) is a type of visual descriptor used for classification in computer vision. LBP is the particular case of the Texture Spectrum model proposed in 1990. LBP was first described in 1994. It has since been found to be a powerful feature for texture classification; it has further been determined that when LBP is combined with the Histogram of oriented gradients (HOG) descriptor, it improves the detection performance considerably on some datasets. A comparison of several improvements of the original LBP in the field of background subtraction was made in 2015 by Silva et al. A full survey of the different versions of LBP can be found in Bouwmans et al.

In digital image and video processing, a color layout descriptor (CLD) is designed to capture the spatial distribution of color in an image. The feature extraction process consists of two parts: grid based representative color selection and discrete cosine transform with quantization.

<span class="mw-page-title-main">Color Cell Compression</span> Lossy color image compression algorithm

Color Cell Compression is a lossy image compression algorithm developed by Campbell et al., in 1986, which can be considered an early forerunner of modern texture compression algorithms, such as S3 Texture Compression and Adaptive Scalable Texture Compression. It is closely related to Block Truncation Coding, another lossy image compression algorithm, which predates Color Cell Compression, in that it uses the dominant luminance of a block of pixels to partition said pixels into two representative colors. The primary difference between Block Truncation Coding and Color Cell Compression is that the former was designed to compress grayscale images and the latter was designed to compress color images. Also, Block Truncation Coding requires that the standard deviation of the colors of pixels in a block be computed in order to compress an image, whereas Color Cell Compression does not use the standard deviation. Both algorithms, though, can compress an image down to effectively 2 bits per pixel.

References

  1. Shapiro, Linda G. and Stockman, George C. "Computer Vision" Prentice Hall, 2003 ISBN   0-13-030796-3
  2. Xiang-Yang Wang, Jun-Feng Wu, and Hong-Ying Yang "Robust image retrieval based on color histogram of local feature regions" Springer Netherlands, 2009 ISSN 1573-7721
  3. Anatomy of a color histogram; Novak, C.L.; Shafer, S.A.; Computer Vision and Pattern Recognition, 1992. Proceedings CVPR '92., 1992 IEEE Computer Society Conference on 15–18 June 1992 Page(s):599 - 605 doi : 10.1109/CVPR.1992.223129
  4. Integrated Spatial and Feature Image Systems: Retrieval, Analysis and Compression; Smith, J.R.; Graduate School of Arts and Sciences, Columbia University, 1997
  5. Effectiveness estimation of image retrieval by 2D color histogram; Bashkov, E.A.; Kostyukova, N.S.; Journal of Automation and Information Sciences, 2006 (6) Page(s): 84-89
  6. Content-Based Image Retrieval Using Color Histogram Correlation; Bashkov, E.A.; Shozda, N.S.; Graphicon proceedings, 2002 Page(s): Archived 2012-07-07 at the Wayback Machine