히스토그램은 영상에서 각 그레이 값에 해당하는 픽셀의 수를 주는 일종의 이산적 함수로 생각할 수 있다. histogram에서 피크의 위치는 histogram을 연속적인 함수로 모델링하거나 또는 여러 개의 그룹으로 분리를 할 때 중요한 정보를 제공한다. 영상으로부터 얻은 histogram은 대부분 이웃하는 그레이 값 사이에서 smooth 하게 변하지 않기 때문에 피크를 찾는 작업을 하기 전에 미리 mean filter나 gaussian filter와 같은 smoothing 과정을 거친 후 사용한다. 여기서는 low-pass filter 대신에 histogram의 bin 인덱스와 bin 값을 컨트롤 포인트로 사용해서 만든 Bezier 곡선을 이용해서 histogram을 smooth 한 곡선으로 근사하는 방법을 알아본다. 이 경우 Bezier 곡선은 255-차수의 곡선이 된다. 높은 차원의 Bezier 곡선 계산에 Berstein 함수를 사용하는 경우 truncation 등의 수치 에러 때문에 값이 불안정해지므로 De Casteljau's algorithm을 이용하여서 iterative 하게 값을 계산을 하면 된다.

// linear interpolation between a and b;
double lerp(double t, double a, double b) {
    return (1 - t) * a + t * b;
}
// De Casteljau's algorithm
double Bezier(double t, int n, double Q[]){
    for (int k = 1; k < n; k++)
        for (int j = 0; j < (n - k); j++)
            Q[j] = lerp(t, Q[j], Q[j + 1]);
    return Q[0];
}
void SmoothenHistogram (int hist[], int numLevels/* =256 */) {
    std::vector<double> p(numLevels);
    std::vector<int> hist2(numLevels);
    // back-up;
    for (int j = 0; j < numLevels; j++) hist2[j] = hist[j];
    for (int j = 0; j < numLevels; j++) {
        double t = double(j) / (numLevels - 1);
        // control points {p}; calling of Bezier() modifies p's;
        for (int i = 0; i < numLevels; i++) p[i] = hist2[i];
        hist[j] = int(Bezier(t, numLevels, &p[0]) + 0.5);
    }
};

data=violet,  smoothed=green;


Bezief curve 위키피디아: http://en.wikipedia.org/wiki/B%C3%A9zier_curve

 

728x90

'Image Recognition > Fundamental' 카테고리의 다른 글

Object Orientation  (1) 2010.01.17
Bicubic Interpolation  (1) 2010.01.14
Running Median Filter  (0) 2010.01.07
Fant's Resampling  (0) 2008.12.17
Bright Preserving Histogram Equalization with Maximum Entropy  (0) 2008.07.31
Posted by helloktk
,