channel are 2, 1 and 0 to synchronise color with Viz axis color in objetc viz::WCoordinateSystem.
A slidebar is inserted in image window. Init slidebar value is 90, it means that only histogram cell greater than 9/100000.0 (23 pixels for an 512X512 pixels) will be display.
We are ready to open a viz window with a callback function to capture keyboard event in viz window. Using Viz::spinonce enable keyboard event to be capture in imshow window too.
The function DrawHistogram3D processes histogram Mat to display it in a Viz window. Number of plan, row and column in three dimensional Mat ca be found using this code :
To get histogram value at a specific location we use at method with three arguments k, i and j where k is plane number, i row number and j column number.
@code{.cpp}
for (int k = 0; k < plans; k++)
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
double x = h.histogram.at<float>(k, i, j);
if (x >= h.threshold)
{
double r=std::max(x/h.maxH,0.1);
viz::WCube s(Point3d(k - r / 2, i - r / 2, j - r / 2), Point3d(k + r / 2, i + r / 2, j + r / 2), false, viz::Color(j / double(plans) * 255, i / double(rows) * 255, k / double(cols) * 255));