Understanding of color histogram and reverse projection

Source: Internet
Author: User
Tags ranges

Recently, I have been studying the meanshift tracking algorithm and encountered some concepts, such as the color histogram and reverse projection, which I don't understand. I hope I can be impressed by Baidu's search and summary.

(1) color histogram

Color features are the most widely used visual features in image search. The main reason is that color is often related to objects or scenes contained in images. In addition, compared with other visual features, color features have less dependence on the size, direction, and Angle of View of the image, thus providing high robustness.

First, we need a suitable color space to describe color features. Secondly, we need to use a certain quantization method to express color features as vectors. Finally, A similarity (distance) standard is also defined to measure the color similarity between images.

Color histograms describe the proportions of different colors in the entire image. They do not care about the spatial location of each color, that is, they cannot describe objects or objects in the image. Color histograms are especially suitable for describing images that are difficult to automatically split. Color histograms are based on different color spaces and coordinate systems. The most common color space is the RGB color space, because most digital images are expressed in this color space. However, the RGB spatial structure does not conform to people's subjective judgment on color similarity. Therefore, some people propose color histograms based on HSV space, Luv space, and lab space, because they are closer to people's subjective understanding of color. The HSV space is the most commonly used color space of a histogram. The three components represent colors (Hue), saturation (s), and values (V ).

To calculate the color histogram, You need to divide the color space into several small color ranges, and each cell is a bin of the histogram. This process becomes Color quantization ). Then, the color histogram is obtained by calculating the number of pixels that the color falls into each cell. Color quantization involves many methods, such as vector quantization, clustering, or neural network.

Commonly used histogram operations in opencv

1) normalized Histogram

Cvnormalizehist (cvhistogram * Hist, double factor); factor is usually set to 1

2) threshold function

Cvthreshhist (cvhistogram * Hist, double factor); factor is a switching threshold

3) copy the Histogram

Void cvcopyhist (const cvhistogram * SRC, cvhistogram ** DST );

4) obtain the minimum maximum value of the histogram.

Void cvgetminmaxhistvalue (const cvhistogram * Hist, float * min_value, float * max_value, int * min_idx = NULL, int * max_idx = NULL );

5) Calculate the Histogram

Void cvcalchist (iplimage ** image, cvhistogram * Hist, int accumulate = 0, const cvarr * mask = NULL );

6) compare two histograms

Double cvcomparehist (const cvhistogram * hist1, const cvhistogram * hist2, int method );

7) create a Histogram

Cvhistogram * cvcreatehist (INT dims, int * size, int type, float ** ranges = NULL, int uniform = 1 );

Example: 

  Int h_bins = 30, s_bins = 32;
  Int hist_size [] = {h_bins, s_bins };
  Float h_ranges [] = {0,180 };
  Float s_ranges [] ={ 0,255 };
  Float * ranges [] = {h_ranges, s_ranges };
  Cvhistogram * hist;
  Hist = cvcreatehist (2, hist_size, cv_hist_array, ranges, 1 );

8) set a value for rangs before using the histogram.

Void cvsethistbinranges (cvhistogram * Hist, float ** ranges, int uniform = 1 );

Note:

   I) uniform indicates whether the histogram has a uniform bin. If it is set to a non-zero value, the histogram is even. You can also set it to null, which means rangs is unknown.

   Ii) The purpose of this range is to determine when to calculate the histogram or determine reverse ing.

9) release the Histogram

If you want to reuse the histogram, you can perform the zeroth operation (that is, set all bins to 0), or use the common release function to release the histogram.

Void cvclearhist (cvhistogram * hist );

Void cvreleasehist (cvhistogram ** hist );

10) create a histogram Based on the given data

Cvhistogram * cvmakehistheaderforarray(INT dims, int * sizes, cvhistogram * Hist, float * data, float ** ranges = NULL );

11) Access Histogram

Double cvqueryhistvalue_1d (cvhistogram * Hist, int idx0 );

Double cvqueryhistvalue_2d (cvhistogram * Hist, int idx0, int idx1 );

Double cvqueryhistvalue_3d (cvhistogram * Hist, int idx0, int idx1, int idx2 );

Double cvqueryhistvalue_nd (cvhistogram * Hist, int * idxn );

12) reverse projection

Http://blog.163.com/chenliangren@126/blog/static/168305659201072761518425/

Reverse projection is a way to record how pixels or pixel blocks adapt to the distribution in the histogram model.

Void cvcalcbackproject (iplimage ** image, cvarr * back_project, const cvhistogram * hist );

Void cvcalcbackprojectpatch (iplimage ** image, cvarr * DST, cvsize patch_size, cvhistogram * Hist, int method, float factor );

Application:

I) if we have a color histogram, we can use reverse projection to find this area in the image.

Ii) We can use the cvcalcbackproject () function to calculate whether a pixel is part of a known target.

Iii) You can also use the cvcalcbackprojectpatch () function to calculate whether a region contains known targets.

13) Draw a Histogram

Http://hi.baidu.com/devisdu/blog/item/2f73ff2d1f15403f349bf712.Html

 

(2) reverse projection

A reverse projection chart replaces the pixel value with the value corresponding to a bin in the histogram at a certain position of the input image (multidimensional or grayscale, therefore, the obtained reverse projection chart is single-pass. In statistical terms, the value of the output pixel point is the probability of the observed Array under a certain distribution (histogram. The reverse projection of an image is simply a probability density chart. The pixels in the reverse projection map represent a probability. If the point is brighter, it indicates that the point is more likely to belong to an object.

 

Example:

B (xi) indicates the number of bin B (xi) corresponding to the pixel on the position Xi, M bin in the histogram, and Qu indicates the value of the nth bin. For example, grayscale images are as follows:

Image =

 0  1  2  3

 4  5  6  7

 8  9 10 11

 8  9 14 15

 

The histogram of the grayscale image is (bin specified range ))

Histogram =

 4  4  6  2

(3) reverse projection

Back_projection =

 4  4  4  4

 4  4  4  4

 6  6  6  6

 6  6  2  2

For example, if the pixel value at the position () is 0 and the bin value is [), the bin value of the reverse histogram is 4.

 

Functions used:

Calcbackproject.

The input of the calcbackproject is the image and its histogram, and the output is the same as the size of the image to be tracked. Each pixel indicates the probability that the point is the target area. The brighter the point, the higher the probability that the point belongs to the object.

 

The test code is as follows: # include <iostream> using namespace STD; # include <iomanip> # include 

 

Reverse projection: reverse projection is used to search for a specific image (usually smaller or only 1 pixel, which is called a template image) in an input image (usually larger) the most matched point or area, that is, the position where the positioning template image appears in the input image.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.