# What algorithm does calcBackProject implement?

**URL:** <https://forum.opencv.org/t/what-algorithm-does-calcbackproject-implement/5407>\
**Category:** Uncategorized\
**Tags:** imgproc\
**Created:** [September 29, 2021, 2:16pm UTC](https://forum.opencv.org/t/what-algorithm-does-calcbackproject-implement/5407 "2021-09-29T14:16:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xin\_Wang](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/xin_wang/32/3318_2.png) [@Xin\_Wang](https://forum.opencv.org/u/Xin_Wang)\
**Post date:** [September 29, 2021, 2:16pm UTC](https://forum.opencv.org/t/what-algorithm-does-calcbackproject-implement/5407/1 "2021-09-29T14:16:28Z")

</div>

I was studying the source of _calcBackProject_ and couldn’t figure out whether the implementation follows the original histogram backprojection algorithm proposed by Michael J. Swain, Dana H. Ballard in their paper _Indexing via color histograms_.

A brief introduction of this algorithm is given by the official tutorial [Histogram Backprojection- Algorithm in Numpy](https://docs.opencv.org/4.5.3/dc/df6/tutorial_py_histogram_backprojection.html):

1. Calculate the histogram of the target image _I_ and that of the model image _M_.
2. Find their ratio histogram _R = M/I_.
3. Backproject _R_, i.e. for an intensity level L maps it to its corresponding height in _R_.

However in another OpenCV tutorial [Back Projection](https://docs.opencv.org/4.5.3/da/d7f/tutorial_back_projection.html) it seems to suggest that the backprojection uses only _M_:

1. Calculate the model image histogram _M_.
2. Backproject _M_.

I went through the source of calcBackProject `https://github.com/opencv/opencv/blob/master/modules/imgproc/src/histogram.cpp#L1609`(sorry I’m only allowed two links in my first post) but could find out where _R_ is calculated. Could anyone let me know which algorithm calcBackProject actually implements?

Many thanks.
