Ask Your Question

Revision history [back]

No I can't. But I solve my problem : I don't use normalize

Mat m = imread("f:/lib/opencv/samples/data/baboon.jpg", CV_LOAD_IMAGE_ANYCOLOR);
Mat mask(m.size(),CV_8UC1,Scalar::all(0));
Rect rZone(Point(220, 330), Point(260, 360));
mask(rZone) = 255;

float hRange[] = { 0, 255 };
const float* etendu[] = { hRange, hRange,hRange };
int hBins = 30;
int tailleHist[] = { hBins, hBins, hBins };
int canaux[] = { 2, 1,0 };
double hMin, hMax;
cv::Mat histogramme;
cv::Mat resultMap;
cv::Mat backproj1d;
click to hide/show revision 2
No.2 Revision

updated 2016-11-29 04:50:53 -0600

berak gravatar image

No I can't. But I solve my problem : I don't use normalize

Mat m = imread("f:/lib/opencv/samples/data/baboon.jpg", CV_LOAD_IMAGE_ANYCOLOR);
Mat mask(m.size(),CV_8UC1,Scalar::all(0));
Rect rZone(Point(220, 330), Point(260, 360));
mask(rZone) = 255;

float hRange[] = { 0, 255 };
const float* etendu[] = { hRange, hRange,hRange };
int hBins = 30;
int tailleHist[] = { hBins, hBins, hBins };
int canaux[] = { 2, 1,0 };
double hMin, hMax;
cv::Mat histogramme;
cv::Mat resultMap;
cv::Mat backproj1d;

and then

for (int dim=1;dim<=3;dim++)
      {
        cv::calcHist(&m, 1, canaux, mask, histogramme, dim, tailleHist, etendu, true, false);
        minMaxIdx(histogramme, &hMin, &hMax);
        cout<<"Hist extremum = "<<hMin<<"\t"<<hMax<<"\n";
        if (dim<3)
            normalize(histogramme, histogramme, 0, 255, cv::NormTypes::NORM_MINMAX, -1, cv::Mat());
        else
            histogramme = 255 * histogramme / hMax;

        minMaxIdx(histogramme, &hMin, &hMax);
        cout << "after normalize Hist extremum = " << hMin << "\t" << hMax << "\n";
        cv::calcBackProject(&m, 1, canaux, histogramme, backproj1d, etendu, 1, true);
        applyColorMap(backproj1d, resultMap, cv::COLORMAP_JET);
click to hide/show revision 3
No.3 Revision

updated 2016-11-29 04:51:54 -0600

berak gravatar image

No I can't. But I solve my problem : I don't use normalize

Mat m = imread("f:/lib/opencv/samples/data/baboon.jpg", CV_LOAD_IMAGE_ANYCOLOR);
Mat mask(m.size(),CV_8UC1,Scalar::all(0));
Rect rZone(Point(220, 330), Point(260, 360));
mask(rZone) = 255;

float hRange[] = { 0, 255 };
const float* etendu[] = { hRange, hRange,hRange };
int hBins = 30;
int tailleHist[] = { hBins, hBins, hBins };
int canaux[] = { 2, 1,0 };
double hMin, hMax;
cv::Mat histogramme;
cv::Mat resultMap;
cv::Mat backproj1d;

and then

for (int dim=1;dim<=3;dim++)
      {
        cv::calcHist(&m, 1, canaux, mask, histogramme, dim, tailleHist, etendu, true, false);
        minMaxIdx(histogramme, &hMin, &hMax);
        cout<<"Hist extremum = "<<hMin<<"\t"<<hMax<<"\n";
        if (dim<3)
            normalize(histogramme, histogramme, 0, 255, cv::NormTypes::NORM_MINMAX, -1, cv::Mat());
        else
            histogramme = 255 * histogramme / hMax;

        minMaxIdx(histogramme, &hMin, &hMax);
        cout << "after normalize Hist extremum = " << hMin << "\t" << hMax << "\n";
        cv::calcBackProject(&m, 1, canaux, histogramme, backproj1d, etendu, 1, true);
        applyColorMap(backproj1d, resultMap, cv::COLORMAP_JET);

the end

    imshow(format("backproject %dD",dim), resultMap);
    waitKey();
}
rectangle(m, rZone, Scalar(255, 255, 255));
imshow("original", m);
waitKey();



}