Histogram equalization(HE)은 histogram을 이용해서 이미지의 contrast을 조정하는 영상처리 기법이다. 히스토그램을 얻기 위해서 전체 이미지 픽셀을 사용하는 전역 HE와 각 픽셀을 중심으로 하는 국소 윈도의 픽셀만 가지고 만든 히스토그램을 이용한 국소 HE이 있다.

 

여기서는 각 픽셀에 대해서 정사각형의 국소 윈도(wsize x wsize)를 잡고, 이 윈도 영역의 국소 히스토그램 정보를 이용해서 HE를 수행한다. 각 윈도 안 픽셀의 히스토그램이 $\{h[i]\}$로 주어질 때, 윈도 중심에서의 픽셀 값 $j$는 

$$j \quad \longrightarrow \quad \frac{255}{\text{total pixels}}\sum_{k=0}^{j} h[k],$$

로 변환된다. 국소 히스토그램 $h[i]$은 running algorithm을 이용하면 빠르게 계산할 수 있다. 단, 국소 윈도가 이미지 영역 내에 있도록 선택했기 때문에 경계 부근의 픽셀은 윈도 중심이 아니다.

//

void localHistogramEqualization(BYTE *image, int width, int height, 
                                             int wsize, /*window size*/
                                             BYTE *out) {
    int hwsize = wsize >> 1;
    wsize = (hwsize << 1) + 1; //odd #;
    int topstop = height - wsize;
    int leftstop = width - wsize; 
    for (int y = 0, offset = 0; y < height; y++, offset += width) {
        int top = y - hwsize; 
        top = top < 0 ? 0 : top > topstop ? topstop : top; 
        BYTE *imgrow = &image[offset];
        BYTE *outrow = &out[offset];
        for (int x = 0; x < width; x++) {
            int left = x - hwsize;
            left = left < 0 ? 0 : left > leftstop ? leftstop : left;
            //make local histogram;
            int histo[256] = ; 
            for (int yy = 0, woffset = top * width + left; yy < wsize; yy++, woffset += width) {
                BYTE * winrow = &image[woffset];
                for (int xx = 0; xx < wsize; xx++) {
                    histo[winrow[xx]]++;
                }
            }
            int level = imgrow[x];
            int csum = 0;  // 0-th cumulative sum up to level;
            for (int k = 0; k <= level; k++) csum += histo[k];
            // apply local histogram eq.
            int a = int((255.0 * csum)/(wsize * wsize)) ;
            outrow[x] = (a & ~255) == 0 ? a: a < 0 ? 0: 255;
        }
    }
}

원본:

 

 

 

*global: 

 

 

 

 

*local: wsize=51;

 

 

** CLAHE 적용: tile size = 20x 20

 

 

 

728x90

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

Autofocus Algorithm  (0) 2012.06.03
Statistical Region Merging  (2) 2012.03.25
2차원 Savitzky-Golay Filters 응용  (0) 2012.02.28
webcam용 QR code detector  (0) 2012.02.19
Least Squares Estimation of Perspective Transformation  (4) 2012.02.15
Posted by helloktk
,