How to smooth a histogram?

I want to smooth the histogram.

So I tried to smooth out the inner matrix cvHistogram.

typedef struct CvHistogram
{
    int     type;
    CvArr*  bins;
    float   thresh[CV_MAX_DIM][2]; /* for uniform histograms */
    float** thresh2; /* for non-uniform histograms */
    CvMatND mat; /* embedded matrix header for array histograms */
}

I tried to smooth the matrix as follows:

cvCalcHist( planes, hist, 0, 0 ); // Compute histogram
(...)

// smooth histogram with Gaussian Filter
cvSmooth( hist->mat, hist_img, CV_GAUSSIAN, 3, 3, 0, 0 );

Unfortunately, this does not work, because for is cvSmoothneeded CvMatas input instead CvMatND. I could not convert CvMatNDto CvMat( CvMatNDin my case 2-dimensional).

Is there anyone who can help me? Thanks.

+3
source share
2 answers

You can use the same basic algorithm that is used for the average filter by simply calculating the average value.

for(int i = 1; i < NBins - 1; ++i)
{
    hist[i] = (hist[i - 1] + hist[i] + hist[i + 1]) / 3;
}

, .

int winSize = 5;
int winMidSize = winSize / 2;

for(int i = winMidSize; i < NBins - winMidSize; ++i)
{
    float mean = 0;
    for(int j = i - winMidSize; j <= (i + winMidSize); ++j)
    {
         mean += hist[j];
    }

    hist[i] = mean / winSize;
}

, .

, OpenCv, openCv: http://tech.groups.yahoo.com/group/OpenCV/join

+9

"" , . sqrt (n) , n . , .

0

Source: https://habr.com/ru/post/1723903/


All Articles