### Navigation

- index
- next |
- previous |
- OpenCV 3.0.0-dev documentation »
- OpenCV API Reference »
- legacy. Deprecated stuff »

# Histograms

## CalcPGH

Calculates a pair-wise geometrical histogram for a contour.

C:`` void `cvCalcPGH`(const CvSeq* contour, CvHistogram* hist)

  Parameters: | contour – Input contour. Currently, only integer point coordinates are allowed. hist – Calculated histogram. It must be two-dimensional.

The function calculates a 2D pair-wise geometrical histogram (PGH), described in [Iivarinen97] for the contour. The algorithm considers every pair of contour edges. The angle between the edges and the minimum/maximum distances are determined for every pair. To do this, each of the edges in turn is taken as the base, while the function loops through all the other edges. When the base edge and any other edge are considered, the minimum and maximum distances from the points on the non-base edge and line of the base edge are selected. The angle between the edges defines the row of the histogram in which all the bins that correspond to the distance between the calculated minimum and maximum distances are incremented (that is, the histogram is transposed relatively to the definition in the original paper). The histogram can be used for contour matching.

[Iivarinen97] | Jukka Iivarinen, Markus Peura, Jaakko Srel, and Ari Visa. Comparison of Combined Shape Descriptors for Irregular Objects, 8th British Machine Vision Conference, BMVC‘97. http://www.cis.hut.fi/research/IA/paper/publications/bmvc97/bmvc97.html

## QueryHistValue*D

Queries the value of the histogram bin.

C:`` float `cvQueryHistValue_1D`(CvHistogram hist, int idx0)

C:`` float `cvQueryHistValue_2D`(CvHistogram hist, int idx0, int idx1)

C:`` float `cvQueryHistValue_3D`(CvHistogram hist, int idx0, int idx1, int idx2)

C:`` float `cvQueryHistValue_nD`(CvHistogram hist, const int* idx)

  Parameters: | hist – Histogram. idx0 – 0-th index. idx1 – 1-st index. idx2 – 2-nd index. idx – Array of indices.

The macros return the value of the specified bin of the 1D, 2D, 3D, or N-D histogram. In case of a sparse histogram, the function returns 0. If the bin is not present in the histogram, no new bin is created.

## GetHistValue_?D

Returns a pointer to the histogram bin.

C:`` float `cvGetHistValue_1D`(CvHistogram hist, int idx0)

C:`` float `cvGetHistValue_2D`(CvHistogram hist, int idx0, int idx1)

C:`` float `cvGetHistValue_3D`(CvHistogram hist, int idx0, int idx1, int idx2)

C:`` float `cvGetHistValue_nD`(CvHistogram hist, int idx)

  Parameters: | hist – Histogram. idx0 – 0-th index. idx1 – 1-st index. idx2 – 2-nd index. idx – Array of indices.

    #define cvGetHistValue_1D( hist, idx0 )
        ((float*)(cvPtr1D( (hist)->bins, (idx0), 0 ))
    #define cvGetHistValue_2D( hist, idx0, idx1 )
        ((float*)(cvPtr2D( (hist)->bins, (idx0), (idx1), 0 )))
    #define cvGetHistValue_3D( hist, idx0, idx1, idx2 )
        ((float*)(cvPtr3D( (hist)->bins, (idx0), (idx1), (idx2), 0 )))
    #define cvGetHistValue_nD( hist, idx )
        ((float*)(cvPtrND( (hist)->bins, (idx), 0 )))

The macros `GetHistValue` return a pointer to the specified bin of the 1D, 2D, 3D, or N-D histogram. In case of a sparse histogram, the function creates a new bin and sets it to 0, unless it exists already.

## Help and Feedback

You did not find what you were looking for?

- Ask a question on the Q&A forum.
- If you think something is missing or wrong in the documentation, please file a bug report.

### Navigation

- index
- next |
- previous |
- OpenCV 3.0.0-dev documentation »
- OpenCV API Reference »
- legacy. Deprecated stuff »